except equal parameters from the uniqueness check

This commit is contained in:
Ali MJ Al-Nasrawy 2023-10-21 16:28:51 +00:00
parent 4e1999d387
commit 4ecdf5ff00
6 changed files with 246 additions and 5 deletions

View file

@ -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`
}
}

View file

@ -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(())
| ^^^^^^^^^^^^
For more information about this error, try `rustc --explain E0657`.
error: aborting due to 4 previous errors
Some errors have detailed explanations: E0657, E0792.
For more information about an error, try `rustc --explain E0657`.

View file

@ -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() {}

View file

@ -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

View file

@ -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() {}