]> git.proxmox.com Git - rustc.git/blob - src/test/ui/issues/issue-30438-b.rs
New upstream version 1.48.0~beta.8+dfsg1
[rustc.git] / src / test / ui / issues / issue-30438-b.rs
1 // Modified regression test for Issue #30438 that exposed an
2 // independent issue (see discussion on ticket).
3
4 use std::ops::Index;
5
6 struct Test<'a> {
7 s: &'a String
8 }
9
10 impl <'a> Index<usize> for Test<'a> {
11 type Output = Test<'a>;
12 fn index(&self, _: usize) -> &Self::Output {
13 &Test { s: &self.s}
14 //~^ ERROR: cannot return reference to temporary value
15 }
16 }
17
18 fn main() {
19 let s = "Hello World".to_string();
20 let test = Test{s: &s};
21 let r = &test[0];
22 println!("{}", test.s); // OK since test is valid
23 println!("{}", r.s); // Segfault since value pointed by r has already been dropped
24 }