From e6e93e021e7be6c9ae400145a2aa235f16f9eb45 Mon Sep 17 00:00:00 2001 From: lcnr Date: Tue, 24 Jan 2023 12:41:18 +0100 Subject: [PATCH] add test where we ignore hr implied bounds --- tests/ui/regions/higher-ranked-implied.rs | 14 +++++++++++++ tests/ui/regions/higher-ranked-implied.stderr | 21 +++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 tests/ui/regions/higher-ranked-implied.rs create mode 100644 tests/ui/regions/higher-ranked-implied.stderr diff --git a/tests/ui/regions/higher-ranked-implied.rs b/tests/ui/regions/higher-ranked-implied.rs new file mode 100644 index 0000000000000..103884c50313f --- /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(*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 0000000000000..9d80eacd7c320 --- /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`.