]> git.lizzy.rs Git - rust.git/blob - src/test/ui/suggestions/impl-on-dyn-trait-with-implicit-static-bound-nll.rs
Merge commit 'e8dca3e87d164d2806098c462c6ce41301341f68' into sync_from_cg_gcc
[rust.git] / src / test / ui / suggestions / impl-on-dyn-trait-with-implicit-static-bound-nll.rs
1 // FIXME(nll): On NLL stabilization, this should replace
2 // `impl-on-dyn-trait-with-implicit-static-bound.rs`. Compiletest has
3 // problems with rustfix and revisions.
4 // ignore-compare-mode-nll
5 // compile-flags: -Zborrowck=mir
6
7 #![allow(dead_code)]
8
9 mod foo {
10     trait OtherTrait<'a> {}
11     impl<'a> OtherTrait<'a> for &'a () {}
12
13     trait ObjectTrait<T> {}
14     trait MyTrait<T> {
15         fn use_self<K>(&self) -> &();
16     }
17     trait Irrelevant {}
18
19     impl<T> MyTrait<T> for dyn ObjectTrait<T> {
20         fn use_self<K>(&self) -> &() { panic!() }
21     }
22     impl<T> Irrelevant for dyn ObjectTrait<T> {}
23
24     fn use_it<'a, T>(val: &'a dyn ObjectTrait<T>) -> impl OtherTrait<'a> + 'a {
25         val.use_self::<T>() //~ ERROR borrowed data escapes
26     }
27 }
28
29 mod bar {
30     trait ObjectTrait {}
31     trait MyTrait {
32         fn use_self(&self) -> &();
33     }
34     trait Irrelevant {}
35
36     impl MyTrait for dyn ObjectTrait {
37         fn use_self(&self) -> &() { panic!() }
38     }
39     impl Irrelevant for dyn ObjectTrait {}
40
41     fn use_it<'a>(val: &'a dyn ObjectTrait) -> &'a () {
42         val.use_self()
43     }
44 }
45
46 mod baz {
47     trait ObjectTrait {}
48     trait MyTrait {
49         fn use_self(&self) -> &();
50     }
51     trait Irrelevant {}
52
53     impl MyTrait for Box<dyn ObjectTrait> {
54         fn use_self(&self) -> &() { panic!() }
55     }
56     impl Irrelevant for Box<dyn ObjectTrait> {}
57
58     fn use_it<'a>(val: &'a Box<dyn ObjectTrait + 'a>) -> &'a () {
59         val.use_self()
60     }
61 }
62
63 mod bat {
64     trait OtherTrait<'a> {}
65     impl<'a> OtherTrait<'a> for &'a () {}
66
67     trait ObjectTrait {}
68
69     impl dyn ObjectTrait {
70         fn use_self(&self) -> &() { panic!() }
71     }
72
73     fn use_it<'a>(val: &'a dyn ObjectTrait) -> impl OtherTrait<'a> + 'a {
74         val.use_self()
75         //~^ ERROR borrowed data escapes
76     }
77 }
78
79 mod ban {
80     trait OtherTrait<'a> {}
81     impl<'a> OtherTrait<'a> for &'a () {}
82
83     trait ObjectTrait {}
84     trait MyTrait {
85         fn use_self(&self) -> &() { panic!() }
86     }
87     trait Irrelevant {
88         fn use_self(&self) -> &() { panic!() }
89     }
90
91     impl MyTrait for dyn ObjectTrait {}
92
93     fn use_it<'a>(val: &'a dyn ObjectTrait) -> impl OtherTrait<'a> {
94         val.use_self() //~ ERROR borrowed data escapes
95     }
96 }
97
98 mod bal {
99     trait OtherTrait<'a> {}
100     impl<'a> OtherTrait<'a> for &'a () {}
101
102     trait ObjectTrait {}
103     trait MyTrait {
104         fn use_self(&self) -> &() { panic!() }
105     }
106     trait Irrelevant {
107         fn use_self(&self) -> &() { panic!() }
108     }
109
110     impl MyTrait for dyn ObjectTrait {}
111     impl Irrelevant for dyn ObjectTrait {}
112
113     fn use_it<'a>(val: &'a dyn ObjectTrait) -> impl OtherTrait<'a> + 'a {
114         MyTrait::use_self(val) //~ ERROR borrowed data escapes
115     }
116 }
117
118 fn main() {}