Update error format for E0373

This commit is contained in:
trixnz 2016-08-05 19:53:14 +02:00
parent 4c02363852
commit 7eca647e5a
6 changed files with 56 additions and 3 deletions

View file

@ -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), \

View file

@ -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`
}

View file

@ -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() { }

View file

@ -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() {

View file

@ -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)
}
}

View file

@ -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
});
}