]> git.proxmox.com Git - rustc.git/blame - src/test/compile-fail/wf-static-method.rs
Imported Upstream version 1.9.0+dfsg1
[rustc.git] / src / test / compile-fail / wf-static-method.rs
CommitLineData
b039eaaf
SL
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.
4//
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.
10
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.
16
17trait Foo<'a, 'b, T>: Sized {
18 fn make_me() -> Self { loop {} }
19 fn static_evil(u: &'b u32) -> &'a u32;
20}
21
22struct Evil<'a, 'b: 'a>(Option<&'a &'b ()>);
23
24impl<'a, 'b> Foo<'a, 'b, Evil<'a, 'b>> for () {
25 fn make_me() -> Self { }
26 fn static_evil(u: &'b u32) -> &'a u32 {
54a0048b 27 u //~ ERROR E0312
b039eaaf
SL
28 }
29}
30
31struct IndirectEvil<'a, 'b: 'a>(Option<&'a &'b ()>);
32
33impl<'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).
38 }
39}
40
41impl<'a, 'b> Evil<'a, 'b> {
42 fn inherent_evil(u: &'b u32) -> &'a u32 {
54a0048b 43 u //~ ERROR E0312
b039eaaf
SL
44 }
45}
46
47// while static methods don't get to *assume* this, we still
48// *check* that they hold.
49
50fn evil<'a, 'b>(b: &'b u32) -> &'a u32 {
51 <()>::static_evil(b) //~ ERROR cannot infer an appropriate lifetime
52}
53
54fn indirect_evil<'a, 'b>(b: &'b u32) -> &'a u32 {
55 <IndirectEvil>::static_evil(b)
56 //~^ ERROR cannot infer an appropriate lifetime
57}
58
59fn inherent_evil<'a, 'b>(b: &'b u32) -> &'a u32 {
60 <Evil>::inherent_evil(b) // bug? shouldn't this be an error
61}
62
63
64fn main() {}