]>
git.proxmox.com Git - rustc.git/blob - src/test/ui/wf/wf-static-method.rs
1 // check that static methods don't get to assume their trait-ref
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.
8 // ignore-compare-mode-nll
9 //[nll] compile-flags: -Z borrowck=mir
11 trait Foo
<'a
, 'b
, T
>: Sized
{
12 fn make_me() -> Self { loop {}
}
13 fn static_evil(u
: &'b
u32) -> &'a
u32;
16 struct Evil
<'a
, 'b
: 'a
>(Option
<&'a
&'
b ()>);
18 impl<'a
, 'b
> Foo
<'a
, 'b
, Evil
<'a
, 'b
>> for () {
19 fn make_me() -> Self { }
20 fn static_evil(u
: &'b
u32) -> &'a
u32 {
22 //[base]~^ ERROR E0312
23 //[nll]~^^ ERROR lifetime may not live long enough
27 struct IndirectEvil
<'a
, 'b
: 'a
>(Option
<&'a
&'
b ()>);
29 impl<'a
, 'b
> Foo
<'a
, 'b
, ()> for IndirectEvil
<'a
, 'b
> {
30 fn make_me() -> Self { IndirectEvil(None) }
31 fn static_evil(u
: &'b
u32) -> &'a
u32 {
32 let me
= Self::make_me();
33 //[base]~^ ERROR lifetime bound not satisfied
34 //[nll]~^^ ERROR lifetime may not live long enough
35 loop {}
// (`me` could be used for the lifetime transmute).
39 impl<'a
, 'b
> Evil
<'a
, 'b
> {
40 fn inherent_evil(u
: &'b
u32) -> &'a
u32 {
42 //[base]~^ ERROR E0312
43 //[nll]~^^ ERROR lifetime may not live long enough
47 // while static methods don't get to *assume* this, we still
48 // *check* that they hold.
50 fn evil
<'a
, 'b
>(b
: &'b
u32) -> &'a
u32 {
52 //[base]~^ ERROR cannot infer an appropriate lifetime
53 //[nll]~^^ ERROR lifetime may not live long enough
56 fn indirect_evil
<'a
, 'b
>(b
: &'b
u32) -> &'a
u32 {
57 <IndirectEvil
>::static_evil(b
)
58 //[base]~^ ERROR cannot infer an appropriate lifetime
59 //[nll]~^^ ERROR lifetime may not live long enough
62 fn inherent_evil
<'a
, 'b
>(b
: &'b
u32) -> &'a
u32 {
63 <Evil
>::inherent_evil(b
)
64 //[base]~^ ERROR cannot infer an appropriate lifetime
65 //[nll]~^^ ERROR lifetime may not live long enough