summaryrefslogtreecommitdiffstats
path: root/src/test/ui/issues/issue-30438-b.rs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/test/ui/issues/issue-30438-b.rs24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/test/ui/issues/issue-30438-b.rs b/src/test/ui/issues/issue-30438-b.rs
new file mode 100644
index 000000000..79510cdb6
--- /dev/null
+++ b/src/test/ui/issues/issue-30438-b.rs
@@ -0,0 +1,24 @@
+// Modified regression test for Issue #30438 that exposed an
+// independent issue (see discussion on ticket).
+
+use std::ops::Index;
+
+struct Test<'a> {
+ s: &'a String
+}
+
+impl <'a> Index<usize> for Test<'a> {
+ type Output = Test<'a>;
+ fn index(&self, _: usize) -> &Self::Output {
+ &Test { s: &self.s}
+ //~^ ERROR: cannot return reference to temporary value
+ }
+}
+
+fn main() {
+ let s = "Hello World".to_string();
+ let test = Test{s: &s};
+ let r = &test[0];
+ println!("{}", test.s); // OK since test is valid
+ println!("{}", r.s); // Segfault since value pointed by r has already been dropped
+}