about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2023-01-25 22:19:54 +0100
committerGitHub <noreply@github.com>2023-01-25 22:19:54 +0100
commitc20e0daf32b355e2a0ab9972cf19b2aa64c4d64f (patch)
treedb6d79fb5ad6f82182eb31ce376a440410e9dac6
parent2ed3639f83f3648854879404ac192092a582d133 (diff)
parente6e93e021e7be6c9ae400145a2aa235f16f9eb45 (diff)
downloadrust-c20e0daf32b355e2a0ab9972cf19b2aa64c4d64f.tar.gz
rust-c20e0daf32b355e2a0ab9972cf19b2aa64c4d64f.zip
Rollup merge of #107255 - lcnr:implied-b-hr, r=oli-obk
add test where we ignore hr implied bounds

r? types
-rw-r--r--tests/ui/regions/higher-ranked-implied.rs14
-rw-r--r--tests/ui/regions/higher-ranked-implied.stderr21
2 files changed, 35 insertions, 0 deletions
diff --git a/tests/ui/regions/higher-ranked-implied.rs b/tests/ui/regions/higher-ranked-implied.rs
new file mode 100644
index 00000000000..103884c5031
--- /dev/null
+++ b/tests/ui/regions/higher-ranked-implied.rs
@@ -0,0 +1,14 @@
+// FIXME: This test should pass as the first two fields add implied bounds that
+// `'a` is equal to `'b` while the last one should simply use that fact. With
+// the current implementation this errors. We have to be careful as implied bounds
+// are only sound if they're also correctly checked.
+
+struct Inv<T>(*mut T); // `T` is invariant.
+type A = for<'a, 'b> fn(Inv<&'a &'b ()>, Inv<&'b &'a ()>, Inv<&'a ()>);
+type B = for<'a, 'b> fn(Inv<&'a &'b ()>, Inv<&'b &'a ()>, Inv<&'b ()>);
+
+fn main() {
+    let x: A = |_, _, _| ();
+    let y: B = x; //~ ERROR mismatched types
+    let _: A = y; //~ ERROR mismatched types
+}
diff --git a/tests/ui/regions/higher-ranked-implied.stderr b/tests/ui/regions/higher-ranked-implied.stderr
new file mode 100644
index 00000000000..9d80eacd7c3
--- /dev/null
+++ b/tests/ui/regions/higher-ranked-implied.stderr
@@ -0,0 +1,21 @@
+error[E0308]: mismatched types
+  --> $DIR/higher-ranked-implied.rs:12:16
+   |
+LL |     let y: B = x;
+   |                ^ one type is more general than the other
+   |
+   = note: expected fn pointer `for<'a, 'b> fn(Inv<&'a &'b ()>, Inv<&'b &'a ()>, Inv<&'b ()>)`
+              found fn pointer `for<'a, 'b> fn(Inv<&'a &'b ()>, Inv<&'b &'a ()>, Inv<&'a ()>)`
+
+error[E0308]: mismatched types
+  --> $DIR/higher-ranked-implied.rs:13:16
+   |
+LL |     let _: A = y;
+   |                ^ one type is more general than the other
+   |
+   = note: expected fn pointer `for<'a, 'b> fn(Inv<&'a &'b ()>, Inv<&'b &'a ()>, Inv<&'a ()>)`
+              found fn pointer `for<'a, 'b> fn(Inv<&'a &'b ()>, Inv<&'b &'a ()>, Inv<&'b ()>)`
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0308`.