]> git.lizzy.rs Git - rust.git/blob - src/test/ui/generic-associated-types/issue-78113-lifetime-mismatch-dyn-trait-box.rs
Rollup merge of #102854 - semarie:openbsd-immutablestack, r=m-ou-se
[rust.git] / src / test / ui / generic-associated-types / issue-78113-lifetime-mismatch-dyn-trait-box.rs
1 // Test for diagnostics when we have mismatched lifetime due to implicit 'static lifetime in GATs
2
3 // check-fail
4
5 pub trait A {}
6 impl A for &dyn A {}
7 impl A for Box<dyn A> {}
8
9 pub trait B {
10     type T<'a>: A;
11 }
12
13 impl B for () {
14     // `'a` doesn't match implicit `'static`: suggest `'_`
15     type T<'a> = Box<dyn A + 'a>; //~ incompatible lifetime on type
16 }
17
18 trait C {}
19 impl C for Box<dyn A + 'static> {}
20 pub trait D {
21     type T<'a>: C;
22 }
23 impl D for () {
24     // `'a` doesn't match explicit `'static`: we *should* suggest removing `'static`
25     type T<'a> = Box<dyn A + 'a>; //~ incompatible lifetime on type
26 }
27
28 trait E {}
29 impl E for (Box<dyn A>, Box<dyn A>) {}
30 pub trait F {
31     type T<'a>: E;
32 }
33 impl F for () {
34     // `'a` doesn't match explicit `'static`: suggest `'_`
35     type T<'a> = (Box<dyn A + 'a>, Box<dyn A + 'a>); //~ incompatible lifetime on type
36 }
37
38 fn main() {}