]> git.lizzy.rs Git - rust.git/blob - src/test/ui/issues/issue-30438-c.rs
Auto merge of #96436 - petrochenkov:nowhole2, r=wesleywiser
[rust.git] / src / test / ui / issues / issue-30438-c.rs
1 // Simplified regression test for #30438, inspired by arielb1.
2
3 trait Trait { type Out; }
4
5 struct Test<'a> { s: &'a str }
6
7 fn silly<'y, 'z>(_s: &'y Test<'z>) -> &'y <Test<'z> as Trait>::Out where 'z: 'static {
8     //~^ WARN unnecessary lifetime parameter `'z`
9     let x = Test { s: "this cannot last" };
10     &x
11     //~^ ERROR: cannot return reference to local variable `x`
12 }
13
14 impl<'b> Trait for Test<'b> { type Out = Test<'b>; }
15
16 fn main() {
17     let orig = Test { s: "Hello World" };
18     let r = silly(&orig);
19     println!("{}", orig.s); // OK since `orig` is valid
20     println!("{}", r.s); // Segfault (method does not return a sane value)
21 }