]> git.lizzy.rs Git - rust.git/blob - src/test/ui/suggestions/impl-on-dyn-trait-with-implicit-static-bound.rs
Increase accuracy of lifetime bound on trait object impl suggestion
[rust.git] / src / test / ui / suggestions / impl-on-dyn-trait-with-implicit-static-bound.rs
1 // run-rustfix
2 #![allow(dead_code)]
3
4 mod foo {
5     trait OtherTrait<'a> {}
6     impl<'a> OtherTrait<'a> for &'a () {}
7
8     trait ObjectTrait {}
9     trait MyTrait {
10         fn use_self(&self) -> &();
11     }
12     trait Irrelevant {}
13
14     impl MyTrait for dyn ObjectTrait {
15         fn use_self(&self) -> &() { panic!() }
16     }
17     impl Irrelevant for dyn ObjectTrait {}
18
19     fn use_it<'a>(val: &'a dyn ObjectTrait) -> impl OtherTrait<'a> + 'a {
20         val.use_self() //~ ERROR cannot infer an appropriate lifetime
21     }
22 }
23
24 mod bar {
25     trait ObjectTrait {}
26     trait MyTrait {
27         fn use_self(&self) -> &();
28     }
29     trait Irrelevant {}
30
31     impl MyTrait for dyn ObjectTrait {
32         fn use_self(&self) -> &() { panic!() }
33     }
34     impl Irrelevant for dyn ObjectTrait {}
35
36     fn use_it<'a>(val: &'a dyn ObjectTrait) -> &'a () {
37         val.use_self() //~ ERROR cannot infer an appropriate lifetime
38     }
39 }
40
41 mod baz {
42     trait ObjectTrait {}
43     trait MyTrait {
44         fn use_self(&self) -> &();
45     }
46     trait Irrelevant {}
47
48     impl MyTrait for Box<dyn ObjectTrait> {
49         fn use_self(&self) -> &() { panic!() }
50     }
51     impl Irrelevant for Box<dyn ObjectTrait> {}
52
53     fn use_it<'a>(val: &'a Box<dyn ObjectTrait + 'a>) -> &'a () {
54         val.use_self() //~ ERROR cannot infer an appropriate lifetime
55     }
56 }
57
58 mod bat {
59     trait OtherTrait<'a> {}
60     impl<'a> OtherTrait<'a> for &'a () {}
61
62     trait ObjectTrait {}
63
64     impl dyn ObjectTrait {
65         fn use_self(&self) -> &() { panic!() }
66     }
67
68     fn use_it<'a>(val: &'a dyn ObjectTrait) -> impl OtherTrait<'a> + 'a {
69         val.use_self() //~ ERROR cannot infer an appropriate lifetime
70     }
71 }
72
73 fn main() {}