Skip to content

Commit

Permalink
Update error format for E0373
Browse files Browse the repository at this point in the history
  • Loading branch information
trixnz committed Aug 5, 2016
1 parent 4c02363 commit 7eca647
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/librustc_borrowck/borrowck/mod.rs
Expand Up @@ -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), \
Expand Down
Expand Up @@ -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`
}
Expand Up @@ -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() { }
5 changes: 4 additions & 1 deletion src/test/compile-fail/issue-4335.rs
Expand Up @@ -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() {
Expand Down
40 changes: 40 additions & 0 deletions src/test/compile-fail/region-borrow-params-issue-29793-small.rs
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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);
};

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

Expand All @@ -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);
}
}
Expand All @@ -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)
}
}
Expand Down Expand Up @@ -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);
}
}
Expand All @@ -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)
}
}
Expand Down Expand Up @@ -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);
}
}
Expand All @@ -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)
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/test/compile-fail/regions-nested-fns-2.rs
Expand Up @@ -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
});
}

Expand Down

0 comments on commit 7eca647

Please sign in to comment.