Skip to content

Commit be68c69

Browse files
committed
add known-bug test for unsound issue 84591
1 parent cac62ab commit be68c69

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// check-pass
2+
// known-bug: #84591
3+
4+
// Should fail. Subtrait can incorrectly extend supertrait lifetimes even when
5+
// supertrait has weaker implied bounds than subtrait. Strongly related to
6+
// issue #25860.
7+
8+
trait Subtrait<T>: Supertrait {}
9+
trait Supertrait {
10+
fn action(self);
11+
}
12+
13+
fn subs_to_soup<T, U>(x: T)
14+
where
15+
T: Subtrait<U>,
16+
{
17+
soup(x)
18+
}
19+
20+
fn soup<T: Supertrait>(x: T) {
21+
x.action();
22+
}
23+
24+
impl<'a, 'b: 'a> Supertrait for (&'b str, &mut &'a str) {
25+
fn action(self) {
26+
*self.1 = self.0;
27+
}
28+
}
29+
30+
impl<'a, 'b> Subtrait<&'a &'b str> for (&'b str, &mut &'a str) {}
31+
32+
fn main() {
33+
let mut d = "hi";
34+
{
35+
let x = "Hello World".to_string();
36+
subs_to_soup((x.as_str(), &mut d));
37+
}
38+
println!("{}", d);
39+
}

0 commit comments

Comments
 (0)