summaryrefslogtreecommitdiff
path: root/tests/ui/nll/issue-30438-a.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/ui/nll/issue-30438-a.rs')
-rw-r--r--tests/ui/nll/issue-30438-a.rs23
1 files changed, 23 insertions, 0 deletions
diff --git a/tests/ui/nll/issue-30438-a.rs b/tests/ui/nll/issue-30438-a.rs
new file mode 100644
index 00000000000..0d4eb796ad9
--- /dev/null
+++ b/tests/ui/nll/issue-30438-a.rs
@@ -0,0 +1,23 @@
+// Original regression test for Issue #30438.
+
+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 {
+ return &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
+}