Skip to content

Commit bae04fb

Browse files
committed
Ensure we error in case of non-higher-kinded lifetimes
1 parent 7a1ccf9 commit bae04fb

File tree

4 files changed

+49
-2
lines changed

4 files changed

+49
-2
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// this used to cause stack overflows
2+
3+
trait Hrtb<'a> {
4+
type Assoc;
5+
}
6+
7+
impl<'a> Hrtb<'a> for () {
8+
type Assoc = ();
9+
}
10+
11+
impl<'a> Hrtb<'a> for &'a () {
12+
type Assoc = ();
13+
}
14+
15+
fn make_impl() -> impl for<'a> Hrtb<'a, Assoc = impl Send + 'a> {}
16+
fn make_weird_impl<'b>(x: &'b ()) -> impl for<'a> Hrtb<'a, Assoc = impl Send + 'a> {
17+
&() //~ ERROR implementation of `Hrtb` is not general enough
18+
}
19+
fn make_bad_impl<'b>(x: &'b ()) -> impl for<'a> Hrtb<'a, Assoc = impl Send + 'a> {
20+
x //~ ERROR implementation of `Hrtb` is not general enough
21+
}
22+
23+
fn main() {}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
error: implementation of `Hrtb` is not general enough
2+
--> $DIR/issue-88236-2.rs:17:5
3+
|
4+
LL | &()
5+
| ^^^ implementation of `Hrtb` is not general enough
6+
|
7+
= note: `Hrtb<'0>` would have to be implemented for the type `&()`, for any lifetime `'0`...
8+
= note: ...but `Hrtb<'1>` is actually implemented for the type `&'1 ()`, for some specific lifetime `'1`
9+
10+
error: implementation of `Hrtb` is not general enough
11+
--> $DIR/issue-88236-2.rs:20:5
12+
|
13+
LL | x
14+
| ^ implementation of `Hrtb` is not general enough
15+
|
16+
= note: `&()` must implement `Hrtb<'0>`, for any lifetime `'0`...
17+
= note: ...but `Hrtb<'_>` is actually implemented for the type `&()`
18+
19+
error: aborting due to 2 previous errors
20+

src/test/ui/impl-trait/issues/issue-88236.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ impl<'a> Hrtb<'a> for () {
1010
type Assoc = ();
1111
}
1212

13+
impl<'a> Hrtb<'a> for &'a () {
14+
type Assoc = ();
15+
}
16+
1317
fn make_impl() -> impl for<'a> Hrtb<'a, Assoc = impl Send + 'a> {}
1418

15-
fn main() {}
19+
fn main() {}

src/test/ui/type-alias-impl-trait/issue-93411.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ fn main() {
1616
type BlahFut<'a> = impl Future<Output = ()> + Send + 'a;
1717
fn blah<'a>(_value: &'a u8) -> BlahFut<'a> {
1818
async {}
19-
}
19+
}

0 commit comments

Comments
 (0)