Skip to content

Commit a105aa2

Browse files
authored
Rollup merge of #113163 - JohnTitor:issue-112895, r=compiler-errors
Add a regression test for #112895 Closes #112895 if the second option is enough to close the issue r? `@compiler-errors`
2 parents baba904 + 40f2fbf commit a105aa2

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// This test checks that we correctly reject the following unsound code.
2+
3+
trait Lengthen<T> {
4+
fn lengthen(self) -> T;
5+
}
6+
7+
impl<'a> Lengthen<&'a str> for &'a str {
8+
fn lengthen(self) -> &'a str { self }
9+
}
10+
11+
trait Gat {
12+
type Gat<'a>: for<'b> Lengthen<Self::Gat<'b>>;
13+
14+
fn lengthen(s: Self::Gat<'_>) -> Self::Gat<'static> {
15+
s.lengthen()
16+
}
17+
}
18+
19+
impl Gat for () {
20+
type Gat<'a> = &'a str; //~ ERROR: implementation of `Lengthen` is not general enough
21+
}
22+
23+
fn main() {
24+
let s = "hello, garbage".to_string();
25+
let borrow: &'static str = <() as Gat>::lengthen(&s);
26+
drop(s);
27+
28+
println!("{borrow}");
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error: implementation of `Lengthen` is not general enough
2+
--> $DIR/gat-bounds-not-checked-with-right-substitutions.rs:20:20
3+
|
4+
LL | type Gat<'a> = &'a str;
5+
| ^^^^^^^ implementation of `Lengthen` is not general enough
6+
|
7+
= note: `Lengthen<&'0 str>` would have to be implemented for the type `&'a str`, for any lifetime `'0`...
8+
= note: ...but `Lengthen<&'1 str>` is actually implemented for the type `&'1 str`, for some specific lifetime `'1`
9+
10+
error: aborting due to previous error
11+

0 commit comments

Comments
 (0)