Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update error format for E0373 #35376

Merged
merged 1 commit into from
Aug 6, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/librustc_borrowck/borrowck/mod.rs
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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`
}
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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