diff options
| author | Eduard-Mihai Burtescu <edy.burt@gmail.com> | 2016-08-06 15:01:23 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2016-08-06 15:01:23 +0300 |
| commit | 56cadb6a9878adefe25006122c290f7f9984fbbe (patch) | |
| tree | c10249cb4d6efc0e6355970a0ceccaaed55ab5b3 | |
| parent | 77c342e03c51461b07bd4ffd535319a14838c29b (diff) | |
| parent | 7eca647e5ae5bef69999c41216e7a8508758d67a (diff) | |
| download | rust-56cadb6a9878adefe25006122c290f7f9984fbbe.tar.gz rust-56cadb6a9878adefe25006122c290f7f9984fbbe.zip | |
Rollup merge of #35376 - trixnz:update-error-373, r=jonathandturner
Update error format for E0373 Fixes #35337 as part of #35233 r? @jonathandturner
6 files changed, 56 insertions, 3 deletions
diff --git a/src/librustc_borrowck/borrowck/mod.rs b/src/librustc_borrowck/borrowck/mod.rs index 1fe47cd4853..9115fd42be8 100644 --- a/src/librustc_borrowck/borrowck/mod.rs +++ b/src/librustc_borrowck/borrowck/mod.rs @@ -942,9 +942,12 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> { but it borrows {}, \ which is owned by the current function", cmt_path_or_string) - .span_note(capture_span, + .span_label(capture_span, &format!("{} is borrowed here", cmt_path_or_string)) + .span_label(err.span, + &format!("may outlive borrowed value {}", + cmt_path_or_string)) .span_suggestion(err.span, &format!("to force the closure to take ownership of {} \ (and any other referenced variables), \ diff --git a/src/test/compile-fail/borrowck/borrowck-escaping-closure-error-1.rs b/src/test/compile-fail/borrowck/borrowck-escaping-closure-error-1.rs index 87e40df7663..ec330247f23 100644 --- a/src/test/compile-fail/borrowck/borrowck-escaping-closure-error-1.rs +++ b/src/test/compile-fail/borrowck/borrowck-escaping-closure-error-1.rs @@ -22,4 +22,6 @@ fn main() { let mut books = vec![1,2,3]; spawn(|| books.push(4)); //~^ ERROR E0373 + //~| NOTE `books` is borrowed here + //~| NOTE may outlive borrowed value `books` } diff --git a/src/test/compile-fail/borrowck/borrowck-escaping-closure-error-2.rs b/src/test/compile-fail/borrowck/borrowck-escaping-closure-error-2.rs index 67700be890b..81685c32f2f 100644 --- a/src/test/compile-fail/borrowck/borrowck-escaping-closure-error-2.rs +++ b/src/test/compile-fail/borrowck/borrowck-escaping-closure-error-2.rs @@ -20,6 +20,8 @@ fn foo<'a>(x: &'a i32) -> Box<FnMut()+'a> { let mut books = vec![1,2,3]; Box::new(|| books.push(4)) //~^ ERROR E0373 + //~| NOTE `books` is borrowed here + //~| NOTE may outlive borrowed value `books` } fn main() { } diff --git a/src/test/compile-fail/issue-4335.rs b/src/test/compile-fail/issue-4335.rs index 9a1b5d9b83d..09371fbafcb 100644 --- a/src/test/compile-fail/issue-4335.rs +++ b/src/test/compile-fail/issue-4335.rs @@ -14,7 +14,10 @@ fn f<'r, T>(v: &'r T) -> Box<FnMut() -> T + 'r> { // FIXME (#22405): Replace `Box::new` with `box` here when/if possible. id(Box::new(|| *v)) //~^ ERROR E0373 - //~| ERROR cannot move out of borrowed content + //~| NOTE `v` is borrowed here + //~| NOTE may outlive borrowed value `v` + //~| ERROR E0507 + //~| NOTE cannot move out of borrowed content } fn main() { diff --git a/src/test/compile-fail/region-borrow-params-issue-29793-small.rs b/src/test/compile-fail/region-borrow-params-issue-29793-small.rs index 4fda8ec3f38..6be2adbe2a0 100644 --- a/src/test/compile-fail/region-borrow-params-issue-29793-small.rs +++ b/src/test/compile-fail/region-borrow-params-issue-29793-small.rs @@ -16,6 +16,10 @@ fn escaping_borrow_of_closure_params_1() { let g = |x: usize, y:usize| { + //~^ NOTE reference must be valid for the scope of call-site for function + //~| NOTE ...but borrowed value is only valid for the scope of function body + //~| NOTE reference must be valid for the scope of call-site for function + //~| NOTE ...but borrowed value is only valid for the scope of function body let f = |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`) //~^ ERROR `x` does not live long enough //~| ERROR `y` does not live long enough @@ -31,6 +35,10 @@ fn escaping_borrow_of_closure_params_1() { fn escaping_borrow_of_closure_params_2() { let g = |x: usize, y:usize| { + //~^ NOTE reference must be valid for the scope of call-site for function + //~| NOTE ...but borrowed value is only valid for the scope of function body + //~| NOTE reference must be valid for the scope of call-site for function + //~| NOTE ...but borrowed value is only valid for the scope of function body let f = |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`) //~^ ERROR `x` does not live long enough //~| ERROR `y` does not live long enough @@ -64,7 +72,11 @@ fn escaping_borrow_of_fn_params_1() { fn g<'a>(x: usize, y:usize) -> Box<Fn(bool) -> usize + 'a> { let f = |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`) //~^ ERROR E0373 + //~| NOTE `x` is borrowed here + //~| NOTE may outlive borrowed value `x` //~| ERROR E0373 + //~| NOTE `y` is borrowed here + //~| NOTE may outlive borrowed value `y` return Box::new(f); }; @@ -75,7 +87,11 @@ fn escaping_borrow_of_fn_params_2() { fn g<'a>(x: usize, y:usize) -> Box<Fn(bool) -> usize + 'a> { let f = |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`) //~^ ERROR E0373 + //~| NOTE `x` is borrowed here + //~| NOTE may outlive borrowed value `x` //~| ERROR E0373 + //~| NOTE `y` is borrowed here + //~| NOTE may outlive borrowed value `y` Box::new(f) }; @@ -99,7 +115,11 @@ fn escaping_borrow_of_method_params_1() { fn g<'a>(&self, x: usize, y:usize) -> Box<Fn(bool) -> usize + 'a> { let f = |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`) //~^ ERROR E0373 + //~| NOTE `x` is borrowed here + //~| NOTE may outlive borrowed value `x` //~| ERROR E0373 + //~| NOTE `y` is borrowed here + //~| NOTE may outlive borrowed value `y` return Box::new(f); } } @@ -113,7 +133,11 @@ fn escaping_borrow_of_method_params_2() { fn g<'a>(&self, x: usize, y:usize) -> Box<Fn(bool) -> usize + 'a> { let f = |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`) //~^ ERROR E0373 + //~| NOTE `x` is borrowed here + //~| NOTE may outlive borrowed value `x` //~| ERROR E0373 + //~| NOTE `y` is borrowed here + //~| NOTE may outlive borrowed value `y` Box::new(f) } } @@ -141,7 +165,11 @@ fn escaping_borrow_of_trait_impl_params_1() { fn g<'a>(&self, x: usize, y:usize) -> Box<Fn(bool) -> usize + 'a> { let f = |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`) //~^ ERROR E0373 + //~| NOTE `x` is borrowed here + //~| NOTE may outlive borrowed value `x` //~| ERROR E0373 + //~| NOTE `y` is borrowed here + //~| NOTE may outlive borrowed value `y` return Box::new(f); } } @@ -156,7 +184,11 @@ fn escaping_borrow_of_trait_impl_params_2() { fn g<'a>(&self, x: usize, y:usize) -> Box<Fn(bool) -> usize + 'a> { let f = |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`) //~^ ERROR E0373 + //~| NOTE `x` is borrowed here + //~| NOTE may outlive borrowed value `x` //~| ERROR E0373 + //~| NOTE `y` is borrowed here + //~| NOTE may outlive borrowed value `y` Box::new(f) } } @@ -184,7 +216,11 @@ fn escaping_borrow_of_trait_default_params_1() { fn g<'a>(&self, x: usize, y:usize) -> Box<Fn(bool) -> usize + 'a> { let f = |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`) //~^ ERROR E0373 + //~| NOTE `x` is borrowed here + //~| NOTE may outlive borrowed value `x` //~| ERROR E0373 + //~| NOTE `y` is borrowed here + //~| NOTE may outlive borrowed value `y` return Box::new(f); } } @@ -198,7 +234,11 @@ fn escaping_borrow_of_trait_default_params_2() { fn g<'a>(&self, x: usize, y:usize) -> Box<Fn(bool) -> usize + 'a> { let f = |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`) //~^ ERROR E0373 + //~| NOTE `x` is borrowed here + //~| NOTE may outlive borrowed value `x` //~| ERROR E0373 + //~| NOTE `y` is borrowed here + //~| NOTE may outlive borrowed value `y` Box::new(f) } } diff --git a/src/test/compile-fail/regions-nested-fns-2.rs b/src/test/compile-fail/regions-nested-fns-2.rs index 948dc8cd219..40ba34b26ed 100644 --- a/src/test/compile-fail/regions-nested-fns-2.rs +++ b/src/test/compile-fail/regions-nested-fns-2.rs @@ -13,8 +13,11 @@ fn ignore<F>(_f: F) where F: for<'z> FnOnce(&'z isize) -> &'z isize {} fn nested() { let y = 3; ignore( - |z| { //~ ERROR E0373 + |z| { + //~^ ERROR E0373 + //~| NOTE may outlive borrowed value `y` if false { &y } else { z } + //~^ NOTE `y` is borrowed here }); } |
