|
8 | 8 | // option. This file may not be copied, modified, or distributed
|
9 | 9 | // except according to those terms.
|
10 | 10 |
|
11 |
| -// check that static methods don't get to assume `Self` is well-formed |
| 11 | +// check that static methods don't get to assume their trait-ref |
| 12 | +// is well-formed. |
| 13 | +// FIXME(#27579): this is just a bug. However, our checking with |
| 14 | +// static inherent methods isn't quite working - need to |
| 15 | +// fix that before removing the check. |
12 | 16 |
|
13 |
| -trait Foo<'a, 'b>: Sized { |
| 17 | +trait Foo<'a, 'b, T>: Sized { |
14 | 18 | fn make_me() -> Self { loop {} }
|
15 |
| - fn static_evil(u: &'a u32) -> &'b u32; |
| 19 | + fn static_evil(u: &'b u32) -> &'a u32; |
16 | 20 | }
|
17 | 21 |
|
18 | 22 | struct Evil<'a, 'b: 'a>(Option<&'a &'b ()>);
|
19 | 23 |
|
20 |
| -impl<'a, 'b> Foo<'a, 'b> for Evil<'a, 'b> { |
21 |
| - fn make_me() -> Self { Evil(None) } |
22 |
| - fn static_evil(u: &'a u32) -> &'b u32 { |
| 24 | +impl<'a, 'b> Foo<'a, 'b, Evil<'a, 'b>> for () { |
| 25 | + fn make_me() -> Self { } |
| 26 | + fn static_evil(u: &'b u32) -> &'a u32 { |
23 | 27 | u //~ ERROR cannot infer an appropriate lifetime
|
24 | 28 | }
|
25 | 29 | }
|
26 | 30 |
|
27 | 31 | struct IndirectEvil<'a, 'b: 'a>(Option<&'a &'b ()>);
|
28 | 32 |
|
29 |
| -impl<'a, 'b> Foo<'a, 'b> for IndirectEvil<'a, 'b> { |
| 33 | +impl<'a, 'b> Foo<'a, 'b, ()> for IndirectEvil<'a, 'b> { |
30 | 34 | fn make_me() -> Self { IndirectEvil(None) }
|
31 |
| - fn static_evil(u: &'a u32) -> &'b u32 { |
| 35 | + fn static_evil(u: &'b u32) -> &'a u32 { |
32 | 36 | let me = Self::make_me(); //~ ERROR lifetime bound not satisfied
|
33 | 37 | loop {} // (`me` could be used for the lifetime transmute).
|
34 | 38 | }
|
35 | 39 | }
|
36 | 40 |
|
| 41 | +impl<'a, 'b> Evil<'a, 'b> { |
| 42 | + fn inherent_evil(u: &'b u32) -> &'a u32 { |
| 43 | + u //~ ERROR cannot infer an appropriate lifetime |
| 44 | + } |
| 45 | +} |
| 46 | + |
| 47 | +// while static methods don't get to *assume* this, we still |
| 48 | +// *check* that they hold. |
| 49 | + |
| 50 | +fn evil<'a, 'b>(b: &'b u32) -> &'a u32 { |
| 51 | + <()>::static_evil(b) //~ ERROR cannot infer an appropriate lifetime |
| 52 | +} |
| 53 | + |
| 54 | +fn indirect_evil<'a, 'b>(b: &'b u32) -> &'a u32 { |
| 55 | + <IndirectEvil>::static_evil(b) |
| 56 | + //~^ ERROR cannot infer an appropriate lifetime |
| 57 | +} |
| 58 | + |
| 59 | +fn inherent_evil<'a, 'b>(b: &'b u32) -> &'a u32 { |
| 60 | + <Evil>::inherent_evil(b) // bug? shouldn't this be an error |
| 61 | +} |
| 62 | + |
| 63 | + |
37 | 64 | fn main() {}
|
0 commit comments