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 | |
| parent | 4e1999d3870c7be9a4addcfcf4fd5db9d29b7d1c (diff) | |
| download | rust-4ecdf5ff00a9af18160bc7214cbcb8a6a1e01d10.tar.gz rust-4ecdf5ff00a9af18160bc7214cbcb8a6a1e01d10.zip | |
except equal parameters from the uniqueness check
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/ui/error-codes/E0657.rs | 2 | ||||
| -rw-r--r-- | tests/ui/error-codes/E0657.stderr | 27 | ||||
| -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 | ||||
| -rw-r--r-- | tests/ui/type-alias-impl-trait/equal-lifetime-params-ok.rs | 50 |
5 files changed, 149 insertions, 4 deletions
diff --git a/tests/ui/error-codes/E0657.rs b/tests/ui/error-codes/E0657.rs index 212c1d9e581..d70c0b334fa 100644 --- a/tests/ui/error-codes/E0657.rs +++ b/tests/ui/error-codes/E0657.rs @@ -11,6 +11,7 @@ fn free_fn_capture_hrtb_in_impl_trait() //~^ ERROR `impl Trait` cannot capture higher-ranked lifetime from `dyn` type { Box::new(()) + //~^ ERROR expected generic lifetime parameter, found `'static` } struct Foo; @@ -20,6 +21,7 @@ impl Foo { //~^ ERROR `impl Trait` cannot capture higher-ranked lifetime from `dyn` type { Box::new(()) + //~^ ERROR expected generic lifetime parameter, found `'static` } } diff --git a/tests/ui/error-codes/E0657.stderr b/tests/ui/error-codes/E0657.stderr index c539007cdcf..28b989aa429 100644 --- a/tests/ui/error-codes/E0657.stderr +++ b/tests/ui/error-codes/E0657.stderr @@ -10,18 +10,37 @@ note: lifetime declared here LL | -> Box<for<'a> Id<impl Lt<'a>>> | ^^ +error[E0792]: expected generic lifetime parameter, found `'static` + --> $DIR/E0657.rs:13:5 + | +LL | -> Box<for<'a> Id<impl Lt<'a>>> + | -- cannot use static lifetime; use a bound lifetime instead or remove the lifetime parameter from the opaque type +... +LL | Box::new(()) + | ^^^^^^^^^^^^ + error[E0657]: `impl Trait` cannot capture higher-ranked lifetime from `dyn` type - --> $DIR/E0657.rs:19:35 + --> $DIR/E0657.rs:20:35 | LL | -> Box<for<'a> Id<impl Lt<'a>>> | ^^ | note: lifetime declared here - --> $DIR/E0657.rs:19:20 + --> $DIR/E0657.rs:20:20 | LL | -> Box<for<'a> Id<impl Lt<'a>>> | ^^ -error: aborting due to 2 previous errors +error[E0792]: expected generic lifetime parameter, found `'static` + --> $DIR/E0657.rs:23:9 + | +LL | -> Box<for<'a> Id<impl Lt<'a>>> + | -- cannot use static lifetime; use a bound lifetime instead or remove the lifetime parameter from the opaque type +... +LL | Box::new(()) + | ^^^^^^^^^^^^ + +error: aborting due to 4 previous errors -For more information about this error, try `rustc --explain E0657`. +Some errors have detailed explanations: E0657, E0792. +For more information about an error, try `rustc --explain E0657`. 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 + diff --git a/tests/ui/type-alias-impl-trait/equal-lifetime-params-ok.rs b/tests/ui/type-alias-impl-trait/equal-lifetime-params-ok.rs new file mode 100644 index 00000000000..6e3f72a1ebe --- /dev/null +++ b/tests/ui/type-alias-impl-trait/equal-lifetime-params-ok.rs @@ -0,0 +1,50 @@ +// FIXME: description +// issue: #113916 +//@ check-pass + +#![feature(type_alias_impl_trait)] +#![feature(impl_trait_in_assoc_type)] + +trait Trait<'a, 'b> {} +impl<T> Trait<'_, '_> for T {} + +mod equal_params { + type Opaque<'a: 'b, 'b: 'a> = impl super::Trait<'a, 'b>; + fn test<'a: 'b, 'b: 'a>() -> Opaque<'a, 'b> { + let _ = None::<&'a &'b &'a ()>; + 0u8 + } +} + +mod equal_static { + type Opaque<'a: 'static> = impl Sized + 'a; + fn test<'a: 'static>() -> Opaque<'a> { + let _ = None::<&'static &'a ()>; + 0u8 + } +} + +mod implied_bounds { + trait Traitor { + type Assoc; + fn define(self) -> Self::Assoc; + } + + impl<'a> Traitor for &'static &'a () { + type Assoc = impl Sized + 'a; + fn define(self) -> Self::Assoc { + let _ = None::<&'static &'a ()>; + 0u8 + } + } + + impl<'a, 'b> Traitor for (&'a &'b (), &'b &'a ()) { + type Assoc = impl Sized + 'a + 'b; + fn define(self) -> Self::Assoc { + let _ = None::<(&'a &'b (), &'b &'a ())>; + 0u8 + } + } +} + +fn main() {} |
