]> git.lizzy.rs Git - rust.git/blob - tests/ui/suggestions/impl-on-dyn-trait-with-implicit-static-bound.rs
Rollup merge of #106144 - tgross35:patch-1, r=Mark-Simulacrum
[rust.git] / tests / ui / suggestions / impl-on-dyn-trait-with-implicit-static-bound.rs
1 // FIXME(#96332): We should be able to suggest a fix and automatically fix.
2
3 #![allow(dead_code)]
4
5 mod foo {
6     trait OtherTrait<'a> {}
7     impl<'a> OtherTrait<'a> for &'a () {}
8
9     trait ObjectTrait<T> {}
10     trait MyTrait<T> {
11         fn use_self<K>(&self) -> &();
12     }
13     trait Irrelevant {}
14
15     impl<T> MyTrait<T> for dyn ObjectTrait<T> {
16         fn use_self<K>(&self) -> &() { panic!() }
17     }
18     impl<T> Irrelevant for dyn ObjectTrait<T> {}
19
20     fn use_it<'a, T>(val: &'a dyn ObjectTrait<T>) -> impl OtherTrait<'a> + 'a {
21         val.use_self::<T>() //~ ERROR borrowed data escapes
22     }
23 }
24
25 mod bar {
26     trait ObjectTrait {}
27     trait MyTrait {
28         fn use_self(&self) -> &();
29     }
30     trait Irrelevant {}
31
32     impl MyTrait for dyn ObjectTrait {
33         fn use_self(&self) -> &() { panic!() }
34     }
35     impl Irrelevant for dyn ObjectTrait {}
36
37     fn use_it<'a>(val: &'a dyn ObjectTrait) -> &'a () {
38         val.use_self()
39     }
40 }
41
42 mod baz {
43     trait ObjectTrait {}
44     trait MyTrait {
45         fn use_self(&self) -> &();
46     }
47     trait Irrelevant {}
48
49     impl MyTrait for Box<dyn ObjectTrait> {
50         fn use_self(&self) -> &() { panic!() }
51     }
52     impl Irrelevant for Box<dyn ObjectTrait> {}
53
54     fn use_it<'a>(val: &'a Box<dyn ObjectTrait + 'a>) -> &'a () {
55         val.use_self()
56     }
57 }
58
59 mod bat {
60     trait OtherTrait<'a> {}
61     impl<'a> OtherTrait<'a> for &'a () {}
62
63     trait ObjectTrait {}
64
65     impl dyn ObjectTrait {
66         fn use_self(&self) -> &() { panic!() }
67     }
68
69     fn use_it<'a>(val: &'a dyn ObjectTrait) -> impl OtherTrait<'a> + 'a {
70         val.use_self()
71         //~^ ERROR borrowed data escapes
72     }
73 }
74
75 mod ban {
76     trait OtherTrait<'a> {}
77     impl<'a> OtherTrait<'a> for &'a () {}
78
79     trait ObjectTrait {}
80     trait MyTrait {
81         fn use_self(&self) -> &() { panic!() }
82     }
83     trait Irrelevant {
84         fn use_self(&self) -> &() { panic!() }
85     }
86
87     impl MyTrait for dyn ObjectTrait {}
88
89     fn use_it<'a>(val: &'a dyn ObjectTrait) -> impl OtherTrait<'a> {
90         val.use_self() //~ ERROR borrowed data escapes
91     }
92 }
93
94 mod bal {
95     trait OtherTrait<'a> {}
96     impl<'a> OtherTrait<'a> for &'a () {}
97
98     trait ObjectTrait {}
99     trait MyTrait {
100         fn use_self(&self) -> &() { panic!() }
101     }
102     trait Irrelevant {
103         fn use_self(&self) -> &() { panic!() }
104     }
105
106     impl MyTrait for dyn ObjectTrait {}
107     impl Irrelevant for dyn ObjectTrait {}
108
109     fn use_it<'a>(val: &'a dyn ObjectTrait) -> impl OtherTrait<'a> + 'a {
110         MyTrait::use_self(val) //~ ERROR borrowed data escapes
111     }
112 }
113
114 fn main() {}