diff options
| author | Ali MJ Al-Nasrawy <alimjalnasrawy@gmail.com> | 2023-10-21 16:28:51 +0000 |
|---|---|---|
| committer | Ali MJ Al-Nasrawy <alimjalnasrawy@gmail.com> | 2024-03-28 06:00:25 +0000 |
| commit | 4ecdf5ff00a9af18160bc7214cbcb8a6a1e01d10 (patch) | |
| tree | bb704518bd69db1c27d67df0e5f307151a079074 /tests/ui/impl-trait | |
| parent | 4e1999d3870c7be9a4addcfcf4fd5db9d29b7d1c (diff) | |
| download | rust-4ecdf5ff00a9af18160bc7214cbcb8a6a1e01d10.tar.gz rust-4ecdf5ff00a9af18160bc7214cbcb8a6a1e01d10.zip | |
except equal parameters from the uniqueness check
Diffstat (limited to 'tests/ui/impl-trait')
| -rw-r--r-- | tests/ui/impl-trait/rpit/non-defining-use-lifetimes.rs | 38 | ||||
| -rw-r--r-- | tests/ui/impl-trait/rpit/non-defining-use-lifetimes.stderr | 36 |
2 files changed, 74 insertions, 0 deletions
diff --git a/tests/ui/impl-trait/rpit/non-defining-use-lifetimes.rs b/tests/ui/impl-trait/rpit/non-defining-use-lifetimes.rs new file mode 100644 index 00000000000..aa60ec27e00 --- /dev/null +++ b/tests/ui/impl-trait/rpit/non-defining-use-lifetimes.rs @@ -0,0 +1,38 @@ +// issue: #111935 +// FIXME(aliemjay): outdated due to "once modulo regions" restriction. +// FIXME(aliemjay): mod `infer` should fail. + +#![allow(unconditional_recursion)] + +// Lt indirection is necessary to make the lifetime of the function late-bound, +// in order to bypass some other bugs. +type Lt<'lt> = Option<*mut &'lt ()>; + +mod statik { + use super::*; + // invalid defining use: Opaque<'static> := () + fn foo<'a>(_: Lt<'a>) -> impl Sized + 'a { + let _: () = foo(Lt::<'static>::None); + //~^ ERROR opaque type used twice with different lifetimes + } +} + +mod infer { + use super::*; + // invalid defining use: Opaque<'_> := () + fn foo<'a>(_: Lt<'a>) -> impl Sized + 'a { + let _: () = foo(Lt::<'_>::None); + } +} + +mod equal { + use super::*; + // invalid defining use: Opaque<'a, 'a> := () + // because of the use of equal lifetimes in args + fn foo<'a, 'b>(_: Lt<'a>, _: Lt<'b>) -> impl Sized + 'a + 'b { + let _: () = foo(Lt::<'a>::None, Lt::<'a>::None); + //~^ ERROR opaque type used twice with different lifetimes + } +} + +fn main() {} diff --git a/tests/ui/impl-trait/rpit/non-defining-use-lifetimes.stderr b/tests/ui/impl-trait/rpit/non-defining-use-lifetimes.stderr new file mode 100644 index 00000000000..fe6bf71abdb --- /dev/null +++ b/tests/ui/impl-trait/rpit/non-defining-use-lifetimes.stderr @@ -0,0 +1,36 @@ +error: opaque type used twice with different lifetimes + --> $DIR/non-defining-use-lifetimes.rs:15:16 + | +LL | fn foo<'a>(_: Lt<'a>) -> impl Sized + 'a { + | ______________________________________________- +LL | | let _: () = foo(Lt::<'static>::None); + | | ^^ lifetime `'static` used here +LL | | +LL | | } + | |_____- lifetime `'a` previously used here + | +note: if all non-lifetime generic parameters are the same, but the lifetime parameters differ, it is not possible to differentiate the opaque types + --> $DIR/non-defining-use-lifetimes.rs:15:16 + | +LL | let _: () = foo(Lt::<'static>::None); + | ^^ + +error: opaque type used twice with different lifetimes + --> $DIR/non-defining-use-lifetimes.rs:33:16 + | +LL | fn foo<'a, 'b>(_: Lt<'a>, _: Lt<'b>) -> impl Sized + 'a + 'b { + | __________________________________________________________________- +LL | | let _: () = foo(Lt::<'a>::None, Lt::<'a>::None); + | | ^^ lifetime `'a` used here +LL | | +LL | | } + | |_____- lifetime `'b` previously used here + | +note: if all non-lifetime generic parameters are the same, but the lifetime parameters differ, it is not possible to differentiate the opaque types + --> $DIR/non-defining-use-lifetimes.rs:33:16 + | +LL | let _: () = foo(Lt::<'a>::None, Lt::<'a>::None); + | ^^ + +error: aborting due to 2 previous errors + |
