1
Fork 0

Same change to point at borrow for mir errors

This commit is contained in:
Esteban Küber 2017-12-14 09:57:34 -08:00
parent 02079e44dd
commit b562565b09
25 changed files with 71 additions and 68 deletions

View file

@ -394,10 +394,10 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
&mut self, name: &String, _scope_tree: &Rc<ScopeTree>, _borrow: &BorrowData<'tcx>, &mut self, name: &String, _scope_tree: &Rc<ScopeTree>, _borrow: &BorrowData<'tcx>,
drop_span: Span, borrow_span: Span, _proper_span: Span, end_span: Option<Span> drop_span: Span, borrow_span: Span, _proper_span: Span, end_span: Option<Span>
) { ) {
let mut err = self.tcx.path_does_not_live_long_enough(drop_span, let mut err = self.tcx.path_does_not_live_long_enough(borrow_span,
&format!("`{}`", name), &format!("`{}`", name),
Origin::Mir); Origin::Mir);
err.span_label(borrow_span, "borrow occurs here"); err.span_label(borrow_span, "borrowed value does not live long enough");
err.span_label(drop_span, format!("`{}` dropped here while still borrowed", name)); err.span_label(drop_span, format!("`{}` dropped here while still borrowed", name));
if let Some(end) = end_span { if let Some(end) = end_span {
err.span_label(end, "borrowed value needs to live until here"); err.span_label(end, "borrowed value needs to live until here");
@ -407,12 +407,12 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
fn report_scoped_temporary_value_does_not_live_long_enough( fn report_scoped_temporary_value_does_not_live_long_enough(
&mut self, _scope_tree: &Rc<ScopeTree>, _borrow: &BorrowData<'tcx>, &mut self, _scope_tree: &Rc<ScopeTree>, _borrow: &BorrowData<'tcx>,
drop_span: Span, borrow_span: Span, proper_span: Span, end_span: Option<Span> drop_span: Span, _borrow_span: Span, proper_span: Span, end_span: Option<Span>
) { ) {
let mut err = self.tcx.path_does_not_live_long_enough(borrow_span, let mut err = self.tcx.path_does_not_live_long_enough(proper_span,
"borrowed value", "borrowed value",
Origin::Mir); Origin::Mir);
err.span_label(proper_span, "temporary value created here"); err.span_label(proper_span, "temporary value does not live long enough");
err.span_label(drop_span, "temporary value dropped here while still borrowed"); err.span_label(drop_span, "temporary value dropped here while still borrowed");
err.note("consider using a `let` binding to increase its lifetime"); err.note("consider using a `let` binding to increase its lifetime");
if let Some(end) = end_span { if let Some(end) = end_span {
@ -428,7 +428,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
let mut err = self.tcx.path_does_not_live_long_enough(borrow_span, let mut err = self.tcx.path_does_not_live_long_enough(borrow_span,
&format!("`{}`", name), &format!("`{}`", name),
Origin::Mir); Origin::Mir);
err.span_label(borrow_span, "does not live long enough"); err.span_label(borrow_span, "borrowed value does not live long enough");
err.span_label(drop_span, "borrowed value only lives until here"); err.span_label(drop_span, "borrowed value only lives until here");
self.tcx.note_and_explain_region(scope_tree, &mut err, self.tcx.note_and_explain_region(scope_tree, &mut err,
"borrowed value must be valid for ", "borrowed value must be valid for ",
@ -443,7 +443,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
let mut err = self.tcx.path_does_not_live_long_enough(proper_span, let mut err = self.tcx.path_does_not_live_long_enough(proper_span,
"borrowed value", "borrowed value",
Origin::Mir); Origin::Mir);
err.span_label(proper_span, "does not live long enough"); err.span_label(proper_span, "temporary value does not live long enough");
err.span_label(drop_span, "temporary value only lives until here"); err.span_label(drop_span, "temporary value only lives until here");
self.tcx.note_and_explain_region(scope_tree, &mut err, self.tcx.note_and_explain_region(scope_tree, &mut err,
"borrowed value must be valid for ", "borrowed value must be valid for ",

View file

@ -124,4 +124,4 @@ fn f<'a>(arena: &'a TypedArena<C<'a>>) {
fn main() { fn main() {
let arena = TypedArena::new(); let arena = TypedArena::new();
f(&arena); f(&arena);
} //~ ERROR `arena` does not live long enough } //~^ ERROR `arena` does not live long enough

View file

@ -49,5 +49,5 @@ fn f<'a>(_arena: &'a TypedArena<C<'a>>) {}
fn main() { fn main() {
let arena: TypedArena<C> = TypedArena::new(); let arena: TypedArena<C> = TypedArena::new();
f(&arena); f(&arena);
} //~ ERROR `arena` does not live long enough } //~^ ERROR `arena` does not live long enough

View file

@ -16,4 +16,5 @@ fn main() {
let mut x = Foo { x: None }; let mut x = Foo { x: None };
let y = 0; let y = 0;
x.x = Some(&y); x.x = Some(&y);
} //~ `y` does not live long enough [E0597] //~^ `y` does not live long enough [E0597]
}

View file

@ -18,10 +18,11 @@ pub fn main() {
let _result: Result<(), &str> = do catch { let _result: Result<(), &str> = do catch {
let my_string = String::from(""); let my_string = String::from("");
let my_str: & str = & my_string; let my_str: & str = & my_string;
//~^ ERROR `my_string` does not live long enough
Err(my_str) ?; Err(my_str) ?;
Err("") ?; Err("") ?;
Ok(()) Ok(())
}; //~ ERROR `my_string` does not live long enough };
} }
{ {

View file

@ -21,11 +21,11 @@ fn main() {
let val: &_ = x.borrow().0; let val: &_ = x.borrow().0;
//[ast]~^ ERROR borrowed value does not live long enough [E0597] //[ast]~^ ERROR borrowed value does not live long enough [E0597]
//[ast]~| NOTE temporary value dropped here while still borrowed //[ast]~| NOTE temporary value dropped here while still borrowed
//[ast]~| NOTE temporary value created here //[ast]~| NOTE temporary value does not live long enough
//[ast]~| NOTE consider using a `let` binding to increase its lifetime //[ast]~| NOTE consider using a `let` binding to increase its lifetime
//[mir]~^^^^^ ERROR borrowed value does not live long enough [E0597] //[mir]~^^^^^ ERROR borrowed value does not live long enough [E0597]
//[mir]~| NOTE temporary value dropped here while still borrowed //[mir]~| NOTE temporary value dropped here while still borrowed
//[mir]~| NOTE temporary value created here //[mir]~| NOTE temporary value does not live long enough
//[mir]~| NOTE consider using a `let` binding to increase its lifetime //[mir]~| NOTE consider using a `let` binding to increase its lifetime
println!("{}", val); println!("{}", val);
} }

View file

@ -81,9 +81,9 @@ fn main() {
WrapB::new().set(|t: bool| if t { x } else { y }) // (separate errors for `x` vs `y`) WrapB::new().set(|t: bool| if t { x } else { y }) // (separate errors for `x` vs `y`)
//[ast]~^ ERROR `x` does not live long enough //[ast]~^ ERROR `x` does not live long enough
//[ast]~| ERROR `y` does not live long enough //[ast]~| ERROR `y` does not live long enough
}); //[mir]~^^^ ERROR `x` does not live long enough
//[mir]~^ ERROR `x` does not live long enough
//[mir]~| ERROR `y` does not live long enough //[mir]~| ERROR `y` does not live long enough
});
w.handle(); // This works w.handle(); // This works
// w.handle_ref(); // This doesn't // w.handle_ref(); // This doesn't

View file

@ -15,7 +15,7 @@ fn main() {
let mut z = 0; let mut z = 0;
&mut z &mut z
}; };
//~^ ERROR `z` does not live long enough (Ast) [E0597] //~^^ ERROR `z` does not live long enough (Ast) [E0597]
//~| ERROR `z` does not live long enough (Mir) [E0597] //~| ERROR `z` does not live long enough (Mir) [E0597]
println!("{}", y); println!("{}", y);
} }

View file

@ -10,12 +10,12 @@ error[E0597]: `z` does not live long enough (Ast)
| - borrowed value needs to live until here | - borrowed value needs to live until here
error[E0597]: `z` does not live long enough (Mir) error[E0597]: `z` does not live long enough (Mir)
--> $DIR/issue-46471-1.rs:17:6 --> $DIR/issue-46471-1.rs:16:9
| |
16 | &mut z 16 | &mut z
| ------ borrow occurs here | ^^^^^^ borrowed value does not live long enough
17 | }; 17 | };
| ^ `z` dropped here while still borrowed | - `z` dropped here while still borrowed
... ...
21 | } 21 | }
| - borrowed value needs to live until here | - borrowed value needs to live until here

View file

@ -13,7 +13,7 @@ error[E0597]: `x` does not live long enough (Mir)
--> $DIR/issue-46471.rs:15:5 --> $DIR/issue-46471.rs:15:5
| |
15 | &x 15 | &x
| ^^ does not live long enough | ^^ borrowed value does not live long enough
... ...
18 | } 18 | }
| - borrowed value only lives until here | - borrowed value only lives until here

View file

@ -21,7 +21,7 @@ error[E0597]: borrowed value does not live long enough (Mir)
--> $DIR/issue-46472.rs:14:10 --> $DIR/issue-46472.rs:14:10
| |
14 | &mut 4 14 | &mut 4
| ^ does not live long enough | ^ temporary value does not live long enough
... ...
17 | } 17 | }
| - temporary value only lives until here | - temporary value only lives until here

View file

@ -2,7 +2,7 @@ error[E0597]: `y` does not live long enough
--> $DIR/capture-ref-in-struct.rs:32:16 --> $DIR/capture-ref-in-struct.rs:32:16
| |
32 | y: &y, 32 | y: &y,
| ^^ does not live long enough | ^^ borrowed value does not live long enough
... ...
37 | } 37 | }
| - borrowed value only lives until here | - borrowed value only lives until here

View file

@ -28,7 +28,7 @@ error[E0597]: `y` does not live long enough
--> $DIR/escape-argument.rs:37:25 --> $DIR/escape-argument.rs:37:25
| |
37 | closure(&mut p, &y); 37 | closure(&mut p, &y);
| ^^ does not live long enough | ^^ borrowed value does not live long enough
38 | //~^ ERROR `y` does not live long enough [E0597] 38 | //~^ ERROR `y` does not live long enough [E0597]
39 | } 39 | }
| - borrowed value only lives until here | - borrowed value only lives until here

View file

@ -54,7 +54,7 @@ error[E0597]: `y` does not live long enough
31 | | let mut closure1 = || p = &y; 31 | | let mut closure1 = || p = &y;
32 | | closure1(); 32 | | closure1();
33 | | }; 33 | | };
| |_________^ does not live long enough | |_________^ borrowed value does not live long enough
... ...
36 | } 36 | }
| - borrowed value only lives until here | - borrowed value only lives until here

View file

@ -31,7 +31,7 @@ error[E0597]: `y` does not live long enough
--> $DIR/escape-upvar-ref.rs:33:27 --> $DIR/escape-upvar-ref.rs:33:27
| |
33 | let mut closure = || p = &y; 33 | let mut closure = || p = &y;
| ^^^^^^^^^ does not live long enough | ^^^^^^^^^ borrowed value does not live long enough
... ...
36 | } 36 | }
| - borrowed value only lives until here | - borrowed value only lives until here

View file

@ -75,7 +75,7 @@ error[E0597]: `a` does not live long enough
--> $DIR/propagate-approximated-shorter-to-static-comparing-against-free.rs:41:26 --> $DIR/propagate-approximated-shorter-to-static-comparing-against-free.rs:41:26
| |
41 | let cell = Cell::new(&a); 41 | let cell = Cell::new(&a);
| ^^ does not live long enough | ^^ borrowed value does not live long enough
... ...
49 | } 49 | }
| - borrowed value only lives until here | - borrowed value only lives until here

View file

@ -2,7 +2,7 @@ error[E0597]: `x` does not live long enough
--> $DIR/region-borrow-params-issue-29793-small.rs:19:34 --> $DIR/region-borrow-params-issue-29793-small.rs:19:34
| |
19 | let f = |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`) 19 | let f = |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`)
| --------- ^ does not live long enough | --------- ^ borrowed value does not live long enough
| | | |
| capture occurs here | capture occurs here
... ...
@ -15,7 +15,7 @@ error[E0597]: `y` does not live long enough
--> $DIR/region-borrow-params-issue-29793-small.rs:19:45 --> $DIR/region-borrow-params-issue-29793-small.rs:19:45
| |
19 | let f = |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`) 19 | let f = |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`)
| --------- ^ does not live long enough | --------- ^ borrowed value does not live long enough
| | | |
| capture occurs here | capture occurs here
... ...
@ -28,7 +28,7 @@ error[E0597]: `x` does not live long enough
--> $DIR/region-borrow-params-issue-29793-small.rs:34:34 --> $DIR/region-borrow-params-issue-29793-small.rs:34:34
| |
34 | let f = |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`) 34 | let f = |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`)
| --------- ^ does not live long enough | --------- ^ borrowed value does not live long enough
| | | |
| capture occurs here | capture occurs here
... ...
@ -41,7 +41,7 @@ error[E0597]: `y` does not live long enough
--> $DIR/region-borrow-params-issue-29793-small.rs:34:45 --> $DIR/region-borrow-params-issue-29793-small.rs:34:45
| |
34 | let f = |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`) 34 | let f = |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`)
| --------- ^ does not live long enough | --------- ^ borrowed value does not live long enough
| | | |
| capture occurs here | capture occurs here
... ...

View file

@ -42,6 +42,7 @@ fn f() {
//~| NOTE consider using a `let` binding to increase its lifetime //~| NOTE consider using a `let` binding to increase its lifetime
} // (statement 7) } // (statement 7)
//~^ NOTE temporary value needs to live until here
let mut v5 = Vec::new(); // statement 8 let mut v5 = Vec::new(); // statement 8

View file

@ -1,49 +1,49 @@
error[E0597]: `young[..]` does not live long enough error[E0597]: `young[..]` does not live long enough
--> $DIR/borrowck-let-suggestion-suffixes.rs:43:1 --> $DIR/borrowck-let-suggestion-suffixes.rs:21:14
| |
21 | v2.push(&young[0]); // statement 4 21 | v2.push(&young[0]); // statement 4
| -------- borrow occurs here | ^^^^^^^^ borrowed value does not live long enough
... ...
43 | } 56 | }
| ^ `young[..]` dropped here while still borrowed | - `young[..]` dropped here while still borrowed
| |
= note: values in a scope are dropped in the opposite order they are created = note: values in a scope are dropped in the opposite order they are created
error[E0597]: borrowed value does not live long enough error[E0597]: borrowed value does not live long enough
--> $DIR/borrowck-let-suggestion-suffixes.rs:25:22 --> $DIR/borrowck-let-suggestion-suffixes.rs:28:14
| |
25 | v3.push(&id('x')); // statement 6 28 | v3.push(&id('x')); // statement 6
| ------- ^ temporary value dropped here while still borrowed | ^^^^^^^ - temporary value dropped here while still borrowed
| | | |
| temporary value created here | temporary value does not live long enough
... ...
43 | } 56 | }
| - temporary value needs to live until here | - temporary value needs to live until here
| |
= note: consider using a `let` binding to increase its lifetime = note: consider using a `let` binding to increase its lifetime
error[E0597]: borrowed value does not live long enough error[E0597]: borrowed value does not live long enough
--> $DIR/borrowck-let-suggestion-suffixes.rs:32:26 --> $DIR/borrowck-let-suggestion-suffixes.rs:38:18
| |
32 | v4.push(&id('y')); 38 | v4.push(&id('y'));
| ------- ^ temporary value dropped here while still borrowed | ^^^^^^^ - temporary value dropped here while still borrowed
| | | |
| temporary value created here | temporary value does not live long enough
... ...
35 | } // (statement 7) 44 | } // (statement 7)
| - temporary value needs to live until here | - temporary value needs to live until here
| |
= note: consider using a `let` binding to increase its lifetime = note: consider using a `let` binding to increase its lifetime
error[E0597]: borrowed value does not live long enough error[E0597]: borrowed value does not live long enough
--> $DIR/borrowck-let-suggestion-suffixes.rs:39:22 --> $DIR/borrowck-let-suggestion-suffixes.rs:49:14
| |
39 | v5.push(&id('z')); 49 | v5.push(&id('z'));
| ------- ^ temporary value dropped here while still borrowed | ^^^^^^^ - temporary value dropped here while still borrowed
| | | |
| temporary value created here | temporary value does not live long enough
... ...
43 | } 56 | }
| - temporary value needs to live until here | - temporary value needs to live until here
| |
= note: consider using a `let` binding to increase its lifetime = note: consider using a `let` binding to increase its lifetime

View file

@ -35,6 +35,7 @@ impl<'t> MakerTrait for Box<Trait<'t>+'static> {
pub fn main() { pub fn main() {
let m : Box<Trait+'static> = make_val(); let m : Box<Trait+'static> = make_val();
assert_eq!(object_invoke1(&*m), (4,5)); assert_eq!(object_invoke1(&*m), (4,5));
//~^ ERROR `*m` does not live long enough
// the problem here is that the full type of `m` is // the problem here is that the full type of `m` is
// //
@ -54,5 +55,4 @@ pub fn main() {
// the type of `m` *strictly outlives* `'m`. Hence we get an // the type of `m` *strictly outlives* `'m`. Hence we get an
// error. // error.
} }
//~^ ERROR `*m` does not live long enough

View file

@ -1,11 +1,11 @@
error[E0597]: `*m` does not live long enough error[E0597]: `*m` does not live long enough
--> $DIR/dropck-object-cycle.rs:56:1 --> $DIR/dropck-object-cycle.rs:37:32
| |
37 | assert_eq!(object_invoke1(&*m), (4,5)); 37 | assert_eq!(object_invoke1(&*m), (4,5));
| -- borrow occurs here | ^^ borrowed value does not live long enough
... ...
56 | } 57 | }
| ^ `*m` dropped here while still borrowed | - `*m` dropped here while still borrowed
| |
= note: values in a scope are dropped in the opposite order they are created = note: values in a scope are dropped in the opposite order they are created

View file

@ -12,5 +12,5 @@ fn main() {
let p; let p;
let a = 42; let a = 42;
p = &a; p = &a;
//~^ ERROR `a` does not live long enough
} }
//~^ ERROR `a` does not live long enough

View file

@ -1,10 +1,11 @@
error[E0597]: `a` does not live long enough error[E0597]: `a` does not live long enough
--> $DIR/issue-36537.rs:15:1 --> $DIR/issue-36537.rs:14:10
| |
14 | p = &a; 14 | p = &a;
| - borrow occurs here | ^ borrowed value does not live long enough
15 | } 15 | //~^ ERROR `a` does not live long enough
| ^ `a` dropped here while still borrowed 16 | }
| - `a` dropped here while still borrowed
| |
= note: values in a scope are dropped in the opposite order they are created = note: values in a scope are dropped in the opposite order they are created

View file

@ -15,9 +15,9 @@ fn broken() {
while x < 10 { //~ ERROR cannot use `x` because it was mutably borrowed while x < 10 { //~ ERROR cannot use `x` because it was mutably borrowed
let mut z = x; //~ ERROR cannot use `x` because it was mutably borrowed let mut z = x; //~ ERROR cannot use `x` because it was mutably borrowed
_y.push(&mut z); _y.push(&mut z);
//~^ ERROR `z` does not live long enough
x += 1; //~ ERROR cannot assign x += 1; //~ ERROR cannot assign
} }
//~^ ERROR `z` does not live long enough
} }
fn main() { } fn main() { }

View file

@ -1,12 +1,11 @@
error[E0597]: `z` does not live long enough error[E0597]: `z` does not live long enough
--> $DIR/regions-escape-loop-via-vec.rs:19:5 --> $DIR/regions-escape-loop-via-vec.rs:17:22
| |
17 | _y.push(&mut z); 17 | _y.push(&mut z);
| - borrow occurs here | ^ borrowed value does not live long enough
18 | x += 1; //~ ERROR cannot assign ...
19 | } 20 | }
| ^ `z` dropped here while still borrowed | - `z` dropped here while still borrowed
20 | //~^ ERROR `z` does not live long enough
21 | } 21 | }
| - borrowed value needs to live until here | - borrowed value needs to live until here
@ -28,12 +27,12 @@ error[E0503]: cannot use `x` because it was mutably borrowed
| ^^^^^ use of borrowed `x` | ^^^^^ use of borrowed `x`
error[E0506]: cannot assign to `x` because it is borrowed error[E0506]: cannot assign to `x` because it is borrowed
--> $DIR/regions-escape-loop-via-vec.rs:18:9 --> $DIR/regions-escape-loop-via-vec.rs:19:9
| |
14 | let mut _y = vec![&mut x]; 14 | let mut _y = vec![&mut x];
| - borrow of `x` occurs here | - borrow of `x` occurs here
... ...
18 | x += 1; //~ ERROR cannot assign 19 | x += 1; //~ ERROR cannot assign
| ^^^^^^ assignment to borrowed `x` occurs here | ^^^^^^ assignment to borrowed `x` occurs here
error: aborting due to 4 previous errors error: aborting due to 4 previous errors