]> git.lizzy.rs Git - rust.git/blob - src/test/ui/issues/issue-30438-c.rs
Merge commit 'f2cdd4a78d89c009342197cf5844a21f8aa813df' into sync_cg_clif-2022-04-22
[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     let x = Test { s: "this cannot last" };
9     &x
10     //~^ ERROR: cannot return reference to local variable `x`
11 }
12
13 impl<'b> Trait for Test<'b> { type Out = Test<'b>; }
14
15 fn main() {
16     let orig = Test { s: "Hello World" };
17     let r = silly(&orig);
18     println!("{}", orig.s); // OK since `orig` is valid
19     println!("{}", r.s); // Segfault (method does not return a sane value)
20 }