]>
git.proxmox.com Git - rustc.git/blob - src/test/compile-fail/wf-static-method.rs
1 // Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 // check that static methods don't get to assume their trait-ref
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.
17 trait Foo
<'a
, 'b
, T
>: Sized
{
18 fn make_me() -> Self { loop {}
}
19 fn static_evil(u
: &'b
u32) -> &'a
u32;
22 struct Evil
<'a
, 'b
: 'a
>(Option
<&'a
&'
b ()>);
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 {
31 struct IndirectEvil
<'a
, 'b
: 'a
>(Option
<&'a
&'
b ()>);
33 impl<'a
, 'b
> Foo
<'a
, 'b
, ()> for IndirectEvil
<'a
, 'b
> {
34 fn make_me() -> Self { IndirectEvil(None) }
35 fn static_evil(u
: &'b
u32) -> &'a
u32 {
36 let me
= Self::make_me(); //~ ERROR lifetime bound not satisfied
37 loop {}
// (`me` could be used for the lifetime transmute).
41 impl<'a
, 'b
> Evil
<'a
, 'b
> {
42 fn inherent_evil(u
: &'b
u32) -> &'a
u32 {
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 {
51 <()>::static_evil(b
) //~ ERROR cannot infer an appropriate lifetime
54 fn indirect_evil
<'a
, 'b
>(b
: &'b
u32) -> &'a
u32 {
55 <IndirectEvil
>::static_evil(b
)
56 //~^ ERROR cannot infer an appropriate lifetime
59 fn inherent_evil
<'a
, 'b
>(b
: &'b
u32) -> &'a
u32 {
60 <Evil
>::inherent_evil(b
) // bug? shouldn't this be an error