Skip to content

Commit 2f23e17

Browse files
committed
use the correct subtyping order in a test
also, ensure that callers are checked.
1 parent ce70207 commit 2f23e17

File tree

1 file changed

+35
-8
lines changed

1 file changed

+35
-8
lines changed

src/test/compile-fail/wf-static-method.rs

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,30 +8,57 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

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.
1216

13-
trait Foo<'a, 'b>: Sized {
17+
trait Foo<'a, 'b, T>: Sized {
1418
fn make_me() -> Self { loop {} }
15-
fn static_evil(u: &'a u32) -> &'b u32;
19+
fn static_evil(u: &'b u32) -> &'a u32;
1620
}
1721

1822
struct Evil<'a, 'b: 'a>(Option<&'a &'b ()>);
1923

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 {
2327
u //~ ERROR cannot infer an appropriate lifetime
2428
}
2529
}
2630

2731
struct IndirectEvil<'a, 'b: 'a>(Option<&'a &'b ()>);
2832

29-
impl<'a, 'b> Foo<'a, 'b> for IndirectEvil<'a, 'b> {
33+
impl<'a, 'b> Foo<'a, 'b, ()> for IndirectEvil<'a, 'b> {
3034
fn make_me() -> Self { IndirectEvil(None) }
31-
fn static_evil(u: &'a u32) -> &'b u32 {
35+
fn static_evil(u: &'b u32) -> &'a u32 {
3236
let me = Self::make_me(); //~ ERROR lifetime bound not satisfied
3337
loop {} // (`me` could be used for the lifetime transmute).
3438
}
3539
}
3640

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+
3764
fn main() {}

0 commit comments

Comments
 (0)