]> git.lizzy.rs Git - rust.git/blob - src/test/compile-fail/issue-30438-c.rs
2b4d0dc339bf0da0b4ada1f5a5dcdadb084bc40e
[rust.git] / src / test / compile-fail / issue-30438-c.rs
1 // Copyright 2016 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 // Simplified regression test for #30438, inspired by arielb1.
12
13 trait Trait { type Out; }
14
15 struct Test<'a> { s: &'a str }
16
17 fn silly<'y, 'z>(_s: &'y Test<'z>) -> &'y <Test<'z> as Trait>::Out where 'z: 'static {
18     let x = Test { s: "this cannot last" };
19     &x
20     //~^ ERROR: `x` does not live long enough
21 }
22
23 impl<'b> Trait for Test<'b> { type Out = Test<'b>; }
24
25 fn main() {
26     let orig = Test { s: "Hello World" };
27     let r = silly(&orig);
28     println!("{}", orig.s); // OK since `orig` is valid
29     println!("{}", r.s); // Segfault (method does not return a sane value)
30 }