about summary refs log tree commit diff
path: root/src/test/ui/static
diff options
context:
space:
mode:
authorMatthew Jasper <mjjasper1@gmail.com>2018-10-14 15:12:02 +0100
committerMatthew Jasper <mjjasper1@gmail.com>2018-10-21 12:35:00 +0100
commit2a3969a3f70779790fd8de1f1602441b5078566b (patch)
tree475915e8d6062700fcced479edfa9aa4b9475d13 /src/test/ui/static
parent275432c1151d1c77afbaebaefa2379a76d1af051 (diff)
downloadrust-2a3969a3f70779790fd8de1f1602441b5078566b.tar.gz
rust-2a3969a3f70779790fd8de1f1602441b5078566b.zip
Use new region infer errors for explaining borrows
This gives at least some explanation for why a borrow is expected to
last for a certain free region. Also:

* Reports E0373: "closure may outlive the current function" with NLL.
* Special cases the case of returning a reference to (or value
  referencing) a local variable or temporary (E0515).
* Special case assigning a reference to a local variable in a closure
  to a captured variable.
Diffstat (limited to 'src/test/ui/static')
-rw-r--r--src/test/ui/static/static-drop-scope.nll.stderr20
-rw-r--r--src/test/ui/static/static-lifetime-bound.nll.stderr7
-rw-r--r--src/test/ui/static/static-reference-to-fn-2.nll.stderr79
-rw-r--r--src/test/ui/static/static-region-bound.nll.stderr3
4 files changed, 44 insertions, 65 deletions
diff --git a/src/test/ui/static/static-drop-scope.nll.stderr b/src/test/ui/static/static-drop-scope.nll.stderr
index a498d80b67b..745f390a4f3 100644
--- a/src/test/ui/static/static-drop-scope.nll.stderr
+++ b/src/test/ui/static/static-drop-scope.nll.stderr
@@ -8,11 +8,11 @@ error[E0716]: temporary value dropped while borrowed
   --> $DIR/static-drop-scope.rs:19:60
    |
 LL | static PROMOTION_FAIL_S: Option<&'static WithDtor> = Some(&WithDtor);
-   |                                                            ^^^^^^^^- temporary value is freed at the end of this statement
-   |                                                            |
-   |                                                            creates a temporary which is freed while still in use
-   |
-   = note: borrowed value must be valid for the static lifetime...
+   |                                                      ------^^^^^^^^-
+   |                                                      |     |       |
+   |                                                      |     |       temporary value is freed at the end of this statement
+   |                                                      |     creates a temporary which is freed while still in use
+   |                                                      using this value as a static requires that borrow lasts for `'static`
 
 error[E0493]: destructors cannot be evaluated at compile-time
   --> $DIR/static-drop-scope.rs:23:59
@@ -24,11 +24,11 @@ error[E0716]: temporary value dropped while borrowed
   --> $DIR/static-drop-scope.rs:23:59
    |
 LL | const PROMOTION_FAIL_C: Option<&'static WithDtor> = Some(&WithDtor);
-   |                                                           ^^^^^^^^- temporary value is freed at the end of this statement
-   |                                                           |
-   |                                                           creates a temporary which is freed while still in use
-   |
-   = note: borrowed value must be valid for the static lifetime...
+   |                                                     ------^^^^^^^^-
+   |                                                     |     |       |
+   |                                                     |     |       temporary value is freed at the end of this statement
+   |                                                     |     creates a temporary which is freed while still in use
+   |                                                     using this value as a constant requires that borrow lasts for `'static`
 
 error[E0493]: destructors cannot be evaluated at compile-time
   --> $DIR/static-drop-scope.rs:27:28
diff --git a/src/test/ui/static/static-lifetime-bound.nll.stderr b/src/test/ui/static/static-lifetime-bound.nll.stderr
index ad4d04343fe..d195b4ce39a 100644
--- a/src/test/ui/static/static-lifetime-bound.nll.stderr
+++ b/src/test/ui/static/static-lifetime-bound.nll.stderr
@@ -10,11 +10,12 @@ error[E0597]: `x` does not live long enough
   --> $DIR/static-lifetime-bound.rs:15:7
    |
 LL |     f(&x); //~ERROR does not live long enough
-   |       ^^ borrowed value does not live long enough
+   |     --^^-
+   |     | |
+   |     | borrowed value does not live long enough
+   |     argument requires that `x` is borrowed for `'static`
 LL | }
    | - `x` dropped here while still borrowed
-   |
-   = note: borrowed value must be valid for the static lifetime...
 
 error: aborting due to previous error
 
diff --git a/src/test/ui/static/static-reference-to-fn-2.nll.stderr b/src/test/ui/static/static-reference-to-fn-2.nll.stderr
index a9ecc14403a..eec1a4d9f12 100644
--- a/src/test/ui/static/static-reference-to-fn-2.nll.stderr
+++ b/src/test/ui/static/static-reference-to-fn-2.nll.stderr
@@ -1,68 +1,47 @@
 error[E0716]: temporary value dropped while borrowed
   --> $DIR/static-reference-to-fn-2.rs:28:22
    |
+LL | fn state1(self_: &mut StateMachineIter) -> Option<&'static str> {
+   |           ----- has type `&mut StateMachineIter<'1>`
 LL |     self_.statefn = &id(state2 as StateMachineFunc);
-   |                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- temporary value is freed at the end of this statement
-   |                      |
-   |                      creates a temporary which is freed while still in use
-   |
-note: borrowed value must be valid for the anonymous lifetime #2 defined on the function body at 27:1...
-  --> $DIR/static-reference-to-fn-2.rs:27:1
-   |
-LL | / fn state1(self_: &mut StateMachineIter) -> Option<&'static str> {
-LL | |     self_.statefn = &id(state2 as StateMachineFunc);
-LL | |     //~^ ERROR borrowed value does not live long enough
-LL | |     return Some("state1");
-LL | | }
-   | |_^
+   |     -----------------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- temporary value is freed at the end of this statement
+   |     |                |
+   |     |                creates a temporary which is freed while still in use
+   |     assignment requires that borrow lasts for `'1`
 
 error[E0716]: temporary value dropped while borrowed
   --> $DIR/static-reference-to-fn-2.rs:34:22
    |
+LL | fn state2(self_: &mut StateMachineIter) -> Option<(&'static str)> {
+   |           ----- has type `&mut StateMachineIter<'1>`
 LL |     self_.statefn = &id(state3 as StateMachineFunc);
-   |                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- temporary value is freed at the end of this statement
-   |                      |
-   |                      creates a temporary which is freed while still in use
-   |
-note: borrowed value must be valid for the anonymous lifetime #2 defined on the function body at 33:1...
-  --> $DIR/static-reference-to-fn-2.rs:33:1
-   |
-LL | / fn state2(self_: &mut StateMachineIter) -> Option<(&'static str)> {
-LL | |     self_.statefn = &id(state3 as StateMachineFunc);
-LL | |     //~^ ERROR borrowed value does not live long enough
-LL | |     return Some("state2");
-LL | | }
-   | |_^
+   |     -----------------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- temporary value is freed at the end of this statement
+   |     |                |
+   |     |                creates a temporary which is freed while still in use
+   |     assignment requires that borrow lasts for `'1`
 
 error[E0716]: temporary value dropped while borrowed
   --> $DIR/static-reference-to-fn-2.rs:40:22
    |
+LL | fn state3(self_: &mut StateMachineIter) -> Option<(&'static str)> {
+   |           ----- has type `&mut StateMachineIter<'1>`
 LL |     self_.statefn = &id(finished as StateMachineFunc);
-   |                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- temporary value is freed at the end of this statement
-   |                      |
-   |                      creates a temporary which is freed while still in use
-   |
-note: borrowed value must be valid for the anonymous lifetime #2 defined on the function body at 39:1...
-  --> $DIR/static-reference-to-fn-2.rs:39:1
-   |
-LL | / fn state3(self_: &mut StateMachineIter) -> Option<(&'static str)> {
-LL | |     self_.statefn = &id(finished as StateMachineFunc);
-LL | |     //~^ ERROR borrowed value does not live long enough
-LL | |     return Some("state3");
-LL | | }
-   | |_^
+   |     -----------------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- temporary value is freed at the end of this statement
+   |     |                |
+   |     |                creates a temporary which is freed while still in use
+   |     assignment requires that borrow lasts for `'1`
 
-error[E0716]: temporary value dropped while borrowed
-  --> $DIR/static-reference-to-fn-2.rs:51:19
-   |
-LL |         statefn: &id(state1 as StateMachineFunc)
-   |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ creates a temporary which is freed while still in use
-...
-LL | }
-   | - temporary value is freed at the end of this statement
-   |
-   = note: borrowed value must be valid for the static lifetime...
+error[E0515]: cannot return value referencing temporary value
+  --> $DIR/static-reference-to-fn-2.rs:50:5
+   |
+LL | /     StateMachineIter {
+LL | |         statefn: &id(state1 as StateMachineFunc)
+   | |                   ------------------------------ temporary value created here
+LL | |         //~^ ERROR borrowed value does not live long enough
+LL | |     }
+   | |_____^ returns a value referencing data owned by the current function
 
 error: aborting due to 4 previous errors
 
-For more information about this error, try `rustc --explain E0716`.
+Some errors occurred: E0515, E0716.
+For more information about an error, try `rustc --explain E0515`.
diff --git a/src/test/ui/static/static-region-bound.nll.stderr b/src/test/ui/static/static-region-bound.nll.stderr
index 45af062c824..c33c1a45547 100644
--- a/src/test/ui/static/static-region-bound.nll.stderr
+++ b/src/test/ui/static/static-region-bound.nll.stderr
@@ -4,10 +4,9 @@ error[E0716]: temporary value dropped while borrowed
 LL |     let x = &id(3); //~ ERROR borrowed value does not live long enough
    |              ^^^^^ creates a temporary which is freed while still in use
 LL |     f(x);
+   |     ---- argument requires that borrow lasts for `'static`
 LL | }
    | - temporary value is freed at the end of this statement
-   |
-   = note: borrowed value must be valid for the static lifetime...
 
 error: aborting due to previous error