From 7eca647e5ae5bef69999c41216e7a8508758d67a Mon Sep 17 00:00:00 2001 From: trixnz Date: Fri, 5 Aug 2016 19:53:14 +0200 Subject: [PATCH] Update error format for E0373 --- src/librustc_borrowck/borrowck/mod.rs | 5 ++- .../borrowck-escaping-closure-error-1.rs | 2 + .../borrowck-escaping-closure-error-2.rs | 2 + src/test/compile-fail/issue-4335.rs | 5 ++- .../region-borrow-params-issue-29793-small.rs | 40 +++++++++++++++++++ src/test/compile-fail/regions-nested-fns-2.rs | 5 ++- 6 files changed, 56 insertions(+), 3 deletions(-) diff --git a/src/librustc_borrowck/borrowck/mod.rs b/src/librustc_borrowck/borrowck/mod.rs index 1fe47cd485387..9115fd42be870 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 87e40df7663ba..ec330247f238b 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 67700be890b1f..81685c32f2f29 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 { 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 9a1b5d9b83d2c..09371fbafcb56 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 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 4fda8ec3f384e..6be2adbe2a0d1 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 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 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 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 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 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 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 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 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 948dc8cd21968..40ba34b26ede6 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) 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 }); }