Ensure we error in case of non-higher-kinded lifetimes

This commit is contained in:
Oli Scherer 2022-02-01 16:41:32 +00:00
parent 7a1ccf9a03
commit bae04fb3de
4 changed files with 49 additions and 2 deletions

View file

@ -0,0 +1,23 @@
// this used to cause stack overflows
trait Hrtb<'a> {
type Assoc;
}
impl<'a> Hrtb<'a> for () {
type Assoc = ();
}
impl<'a> Hrtb<'a> for &'a () {
type Assoc = ();
}
fn make_impl() -> impl for<'a> Hrtb<'a, Assoc = impl Send + 'a> {}
fn make_weird_impl<'b>(x: &'b ()) -> impl for<'a> Hrtb<'a, Assoc = impl Send + 'a> {
&() //~ ERROR implementation of `Hrtb` is not general enough
}
fn make_bad_impl<'b>(x: &'b ()) -> impl for<'a> Hrtb<'a, Assoc = impl Send + 'a> {
x //~ ERROR implementation of `Hrtb` is not general enough
}
fn main() {}

View file

@ -0,0 +1,20 @@
error: implementation of `Hrtb` is not general enough
--> $DIR/issue-88236-2.rs:17:5
|
LL | &()
| ^^^ implementation of `Hrtb` is not general enough
|
= note: `Hrtb<'0>` would have to be implemented for the type `&()`, for any lifetime `'0`...
= note: ...but `Hrtb<'1>` is actually implemented for the type `&'1 ()`, for some specific lifetime `'1`
error: implementation of `Hrtb` is not general enough
--> $DIR/issue-88236-2.rs:20:5
|
LL | x
| ^ implementation of `Hrtb` is not general enough
|
= note: `&()` must implement `Hrtb<'0>`, for any lifetime `'0`...
= note: ...but `Hrtb<'_>` is actually implemented for the type `&()`
error: aborting due to 2 previous errors

View file

@ -10,6 +10,10 @@ impl<'a> Hrtb<'a> for () {
type Assoc = ();
}
impl<'a> Hrtb<'a> for &'a () {
type Assoc = ();
}
fn make_impl() -> impl for<'a> Hrtb<'a, Assoc = impl Send + 'a> {}
fn main() {}
fn main() {}

View file

@ -16,4 +16,4 @@ fn main() {
type BlahFut<'a> = impl Future<Output = ()> + Send + 'a;
fn blah<'a>(_value: &'a u8) -> BlahFut<'a> {
async {}
}
}