]> git.lizzy.rs Git - rust.git/blob - tests/ui/wf/wf-static-method.rs
Rollup merge of #106570 - Xaeroxe:div-duration-tests, r=JohnTitor
[rust.git] / tests / ui / wf / wf-static-method.rs
1 // check that static methods don't get to assume their trait-ref
2 // is well-formed.
3 // FIXME(#27579): this is just a bug. However, our checking with
4 // static inherent methods isn't quite working - need to
5 // fix that before removing the check.
6
7 trait Foo<'a, 'b, T>: Sized {
8     fn make_me() -> Self { loop {} }
9     fn static_evil(u: &'b u32) -> &'a u32;
10 }
11
12 struct Evil<'a, 'b: 'a>(Option<&'a &'b ()>);
13
14 impl<'a, 'b> Foo<'a, 'b, Evil<'a, 'b>> for () {
15     fn make_me() -> Self { }
16     fn static_evil(u: &'b u32) -> &'a u32 {
17         u
18         //~^ ERROR lifetime may not live long enough
19     }
20 }
21
22 struct IndirectEvil<'a, 'b: 'a>(Option<&'a &'b ()>);
23
24 impl<'a, 'b> Foo<'a, 'b, ()> for IndirectEvil<'a, 'b> {
25     fn make_me() -> Self { IndirectEvil(None) }
26     fn static_evil(u: &'b u32) -> &'a u32 {
27         let me = Self::make_me();
28         //~^ ERROR lifetime may not live long enough
29         loop {} // (`me` could be used for the lifetime transmute).
30     }
31 }
32
33 impl<'a, 'b> Evil<'a, 'b> {
34     fn inherent_evil(u: &'b u32) -> &'a u32 {
35         u
36         //~^ ERROR lifetime may not live long enough
37     }
38 }
39
40 // while static methods don't get to *assume* this, we still
41 // *check* that they hold.
42
43 fn evil<'a, 'b>(b: &'b u32) -> &'a u32 {
44     <()>::static_evil(b)
45     //~^ ERROR lifetime may not live long enough
46 }
47
48 fn indirect_evil<'a, 'b>(b: &'b u32) -> &'a u32 {
49     <IndirectEvil>::static_evil(b)
50     //~^ ERROR lifetime may not live long enough
51 }
52
53 fn inherent_evil<'a, 'b>(b: &'b u32) -> &'a u32 {
54     <Evil>::inherent_evil(b)
55     //~^ ERROR lifetime may not live long enough
56 }
57
58
59 fn main() {}