about summary refs log tree commit diff
path: root/src/test/ui
diff options
context:
space:
mode:
authorMikhail Modin <mikhailm1@gmail.com>2016-11-03 09:58:01 +0300
committerMikhail Modin <mikhailm1@gmail.com>2016-11-09 00:28:50 +0300
commitcfdf7633f08ee77e303f1bf88b613a35f9946e75 (patch)
treebc145012daf7b215be45761b4866cc9ff2b6f320 /src/test/ui
parenta0e7e357a796f93527d0a0e850fa71c48594b91d (diff)
Improve "Doesn't live long enough" error
case with temporary variable
Diffstat (limited to 'src/test/ui')
-rw-r--r--src/test/ui/lifetimes/borrowck-let-suggestion.stderr4
-rw-r--r--src/test/ui/span/borrowck-let-suggestion-suffixes.stderr12
-rw-r--r--src/test/ui/span/issue-15480.rs19
-rw-r--r--src/test/ui/span/issue-15480.stderr15
-rw-r--r--src/test/ui/span/regions-close-over-borrowed-ref-in-obj.rs23
-rw-r--r--src/test/ui/span/regions-close-over-borrowed-ref-in-obj.stderr13
-rw-r--r--src/test/ui/span/slice-borrow.rs19
-rw-r--r--src/test/ui/span/slice-borrow.stderr13
8 files changed, 110 insertions, 8 deletions
diff --git a/src/test/ui/lifetimes/borrowck-let-suggestion.stderr b/src/test/ui/lifetimes/borrowck-let-suggestion.stderr
index 91600340019..d85483f43c9 100644
--- a/src/test/ui/lifetimes/borrowck-let-suggestion.stderr
+++ b/src/test/ui/lifetimes/borrowck-let-suggestion.stderr
@@ -1,8 +1,8 @@
 error: borrowed value does not live long enough
-  --> $DIR/borrowck-let-suggestion.rs:12:13
+  --> $DIR/borrowck-let-suggestion.rs:12:23
    |
 12 |     let x = [1].iter();
-   |             ^^^       - temporary value only lives until here
+   |             ---       ^ temporary value dropped here while still borrowed
    |             |
    |             temporary value created here
 13 | }
diff --git a/src/test/ui/span/borrowck-let-suggestion-suffixes.stderr b/src/test/ui/span/borrowck-let-suggestion-suffixes.stderr
index 0bba986e437..5bb656878b3 100644
--- a/src/test/ui/span/borrowck-let-suggestion-suffixes.stderr
+++ b/src/test/ui/span/borrowck-let-suggestion-suffixes.stderr
@@ -10,10 +10,10 @@ error: `young[..]` does not live long enough
    = note: values in a scope are dropped in the opposite order they are created
 
 error: borrowed value does not live long enough
-  --> $DIR/borrowck-let-suggestion-suffixes.rs:24:14
+  --> $DIR/borrowck-let-suggestion-suffixes.rs:24:18
    |
 24 |     v3.push(&'x');           // statement 6
-   |              ^^^ - temporary value only lives until here
+   |              --- ^ temporary value dropped here while still borrowed
    |              |
    |              temporary value created here
 ...
@@ -23,10 +23,10 @@ error: borrowed value does not live long enough
    = note: consider using a `let` binding to increase its lifetime
 
 error: borrowed value does not live long enough
-  --> $DIR/borrowck-let-suggestion-suffixes.rs:34:18
+  --> $DIR/borrowck-let-suggestion-suffixes.rs:34:22
    |
 34 |         v4.push(&'y');
-   |                  ^^^ - temporary value only lives until here
+   |                  --- ^ temporary value dropped here while still borrowed
    |                  |
    |                  temporary value created here
 ...
@@ -36,10 +36,10 @@ error: borrowed value does not live long enough
    = note: consider using a `let` binding to increase its lifetime
 
 error: borrowed value does not live long enough
-  --> $DIR/borrowck-let-suggestion-suffixes.rs:45:14
+  --> $DIR/borrowck-let-suggestion-suffixes.rs:45:18
    |
 45 |     v5.push(&'z');
-   |              ^^^ - temporary value only lives until here
+   |              --- ^ temporary value dropped here while still borrowed
    |              |
    |              temporary value created here
 ...
diff --git a/src/test/ui/span/issue-15480.rs b/src/test/ui/span/issue-15480.rs
new file mode 100644
index 00000000000..ea5f4d3fe60
--- /dev/null
+++ b/src/test/ui/span/issue-15480.rs
@@ -0,0 +1,19 @@
+// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+fn main() {
+    let v = vec![
+        &3
+    ];
+
+    for &&x in &v {
+        println!("{}", x + 3);
+    }
+}
diff --git a/src/test/ui/span/issue-15480.stderr b/src/test/ui/span/issue-15480.stderr
new file mode 100644
index 00000000000..85f6c41c366
--- /dev/null
+++ b/src/test/ui/span/issue-15480.stderr
@@ -0,0 +1,15 @@
+error: borrowed value does not live long enough
+  --> $DIR/issue-15480.rs:14:6
+   |
+13 |         &3
+   |          - temporary value created here
+14 |     ];
+   |      ^ temporary value dropped here while still borrowed
+...
+19 | }
+   | - temporary value needs to live until here
+   |
+   = note: consider using a `let` binding to increase its lifetime
+
+error: aborting due to previous error
+
diff --git a/src/test/ui/span/regions-close-over-borrowed-ref-in-obj.rs b/src/test/ui/span/regions-close-over-borrowed-ref-in-obj.rs
new file mode 100644
index 00000000000..a524562f2d9
--- /dev/null
+++ b/src/test/ui/span/regions-close-over-borrowed-ref-in-obj.rs
@@ -0,0 +1,23 @@
+// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![feature(box_syntax)]
+
+trait Foo { }
+
+impl<'a> Foo for &'a isize { }
+
+fn main() {
+    let blah;
+    {
+        let ss: &isize = &1;
+        blah = box ss as Box<Foo>;
+    }
+}
diff --git a/src/test/ui/span/regions-close-over-borrowed-ref-in-obj.stderr b/src/test/ui/span/regions-close-over-borrowed-ref-in-obj.stderr
new file mode 100644
index 00000000000..205734c25e0
--- /dev/null
+++ b/src/test/ui/span/regions-close-over-borrowed-ref-in-obj.stderr
@@ -0,0 +1,13 @@
+error: borrowed value does not live long enough
+  --> $DIR/regions-close-over-borrowed-ref-in-obj.rs:22:5
+   |
+20 |         let ss: &isize = &1;
+   |                           - temporary value created here
+21 |         blah = box ss as Box<Foo>;
+22 |     }
+   |     ^ temporary value dropped here while still borrowed
+23 | }
+   | - temporary value needs to live until here
+
+error: aborting due to previous error
+
diff --git a/src/test/ui/span/slice-borrow.rs b/src/test/ui/span/slice-borrow.rs
new file mode 100644
index 00000000000..4ca0ccaa731
--- /dev/null
+++ b/src/test/ui/span/slice-borrow.rs
@@ -0,0 +1,19 @@
+// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// Test slicing expressions doesn't defeat the borrow checker.
+
+fn main() {
+    let y;
+    {
+        let x: &[isize] = &[1, 2, 3, 4, 5];
+        y = &x[1..];
+    }
+}
diff --git a/src/test/ui/span/slice-borrow.stderr b/src/test/ui/span/slice-borrow.stderr
new file mode 100644
index 00000000000..efe81fd00bf
--- /dev/null
+++ b/src/test/ui/span/slice-borrow.stderr
@@ -0,0 +1,13 @@
+error: borrowed value does not live long enough
+  --> $DIR/slice-borrow.rs:18:5
+   |
+16 |         let x: &[isize] = &[1, 2, 3, 4, 5];
+   |                            --------------- temporary value created here
+17 |         y = &x[1..];
+18 |     }
+   |     ^ temporary value dropped here while still borrowed
+19 | }
+   | - temporary value needs to live until here
+
+error: aborting due to previous error
+