Same change to point at borrow for mir errors
This commit is contained in:
parent
02079e44dd
commit
b562565b09
@ -394,10 +394,10 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, '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>
|
||||
) {
|
||||
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),
|
||||
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));
|
||||
if let Some(end) = end_span {
|
||||
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(
|
||||
&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",
|
||||
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.note("consider using a `let` binding to increase its lifetime");
|
||||
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,
|
||||
&format!("`{}`", name),
|
||||
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");
|
||||
self.tcx.note_and_explain_region(scope_tree, &mut err,
|
||||
"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,
|
||||
"borrowed value",
|
||||
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");
|
||||
self.tcx.note_and_explain_region(scope_tree, &mut err,
|
||||
"borrowed value must be valid for ",
|
||||
|
@ -124,4 +124,4 @@ fn f<'a>(arena: &'a TypedArena<C<'a>>) {
|
||||
fn main() {
|
||||
let arena = TypedArena::new();
|
||||
f(&arena);
|
||||
} //~ ERROR `arena` does not live long enough
|
||||
} //~^ ERROR `arena` does not live long enough
|
||||
|
@ -49,5 +49,5 @@ fn f<'a>(_arena: &'a TypedArena<C<'a>>) {}
|
||||
fn main() {
|
||||
let arena: TypedArena<C> = TypedArena::new();
|
||||
f(&arena);
|
||||
} //~ ERROR `arena` does not live long enough
|
||||
} //~^ ERROR `arena` does not live long enough
|
||||
|
||||
|
@ -16,4 +16,5 @@ fn main() {
|
||||
let mut x = Foo { x: None };
|
||||
let y = 0;
|
||||
x.x = Some(&y);
|
||||
} //~ `y` does not live long enough [E0597]
|
||||
//~^ `y` does not live long enough [E0597]
|
||||
}
|
||||
|
@ -18,10 +18,11 @@ pub fn main() {
|
||||
let _result: Result<(), &str> = do catch {
|
||||
let my_string = String::from("");
|
||||
let my_str: & str = & my_string;
|
||||
//~^ ERROR `my_string` does not live long enough
|
||||
Err(my_str) ?;
|
||||
Err("") ?;
|
||||
Ok(())
|
||||
}; //~ ERROR `my_string` does not live long enough
|
||||
};
|
||||
}
|
||||
|
||||
{
|
||||
|
@ -21,11 +21,11 @@ fn main() {
|
||||
let val: &_ = x.borrow().0;
|
||||
//[ast]~^ ERROR borrowed value does not live long enough [E0597]
|
||||
//[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
|
||||
//[mir]~^^^^^ ERROR borrowed value does not live long enough [E0597]
|
||||
//[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
|
||||
println!("{}", val);
|
||||
}
|
||||
|
@ -81,9 +81,9 @@ fn main() {
|
||||
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 `y` does not live long enough
|
||||
//[mir]~^^^ ERROR `x` does not live long enough
|
||||
//[mir]~| ERROR `y` does not live long enough
|
||||
});
|
||||
//[mir]~^ ERROR `x` does not live long enough
|
||||
//[mir]~| ERROR `y` does not live long enough
|
||||
|
||||
w.handle(); // This works
|
||||
// w.handle_ref(); // This doesn't
|
||||
|
@ -15,7 +15,7 @@ fn main() {
|
||||
let mut z = 0;
|
||||
&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]
|
||||
println!("{}", y);
|
||||
}
|
||||
|
@ -10,12 +10,12 @@ error[E0597]: `z` does not live long enough (Ast)
|
||||
| - borrowed value needs to live until here
|
||||
|
||||
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
|
||||
| ------ borrow occurs here
|
||||
| ^^^^^^ borrowed value does not live long enough
|
||||
17 | };
|
||||
| ^ `z` dropped here while still borrowed
|
||||
| - `z` dropped here while still borrowed
|
||||
...
|
||||
21 | }
|
||||
| - borrowed value needs to live until here
|
||||
|
@ -13,7 +13,7 @@ error[E0597]: `x` does not live long enough (Mir)
|
||||
--> $DIR/issue-46471.rs:15:5
|
||||
|
|
||||
15 | &x
|
||||
| ^^ does not live long enough
|
||||
| ^^ borrowed value does not live long enough
|
||||
...
|
||||
18 | }
|
||||
| - borrowed value only lives until here
|
||||
|
@ -21,7 +21,7 @@ error[E0597]: borrowed value does not live long enough (Mir)
|
||||
--> $DIR/issue-46472.rs:14:10
|
||||
|
|
||||
14 | &mut 4
|
||||
| ^ does not live long enough
|
||||
| ^ temporary value does not live long enough
|
||||
...
|
||||
17 | }
|
||||
| - temporary value only lives until here
|
||||
|
@ -2,7 +2,7 @@ error[E0597]: `y` does not live long enough
|
||||
--> $DIR/capture-ref-in-struct.rs:32:16
|
||||
|
|
||||
32 | y: &y,
|
||||
| ^^ does not live long enough
|
||||
| ^^ borrowed value does not live long enough
|
||||
...
|
||||
37 | }
|
||||
| - borrowed value only lives until here
|
||||
|
@ -28,7 +28,7 @@ error[E0597]: `y` does not live long enough
|
||||
--> $DIR/escape-argument.rs:37:25
|
||||
|
|
||||
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]
|
||||
39 | }
|
||||
| - borrowed value only lives until here
|
||||
|
@ -54,7 +54,7 @@ error[E0597]: `y` does not live long enough
|
||||
31 | | let mut closure1 = || p = &y;
|
||||
32 | | closure1();
|
||||
33 | | };
|
||||
| |_________^ does not live long enough
|
||||
| |_________^ borrowed value does not live long enough
|
||||
...
|
||||
36 | }
|
||||
| - borrowed value only lives until here
|
||||
|
@ -31,7 +31,7 @@ error[E0597]: `y` does not live long enough
|
||||
--> $DIR/escape-upvar-ref.rs:33:27
|
||||
|
|
||||
33 | let mut closure = || p = &y;
|
||||
| ^^^^^^^^^ does not live long enough
|
||||
| ^^^^^^^^^ borrowed value does not live long enough
|
||||
...
|
||||
36 | }
|
||||
| - borrowed value only lives until here
|
||||
|
@ -75,7 +75,7 @@ error[E0597]: `a` does not live long enough
|
||||
--> $DIR/propagate-approximated-shorter-to-static-comparing-against-free.rs:41:26
|
||||
|
|
||||
41 | let cell = Cell::new(&a);
|
||||
| ^^ does not live long enough
|
||||
| ^^ borrowed value does not live long enough
|
||||
...
|
||||
49 | }
|
||||
| - borrowed value only lives until here
|
||||
|
@ -2,7 +2,7 @@ error[E0597]: `x` does not live long enough
|
||||
--> $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`)
|
||||
| --------- ^ does not live long enough
|
||||
| --------- ^ borrowed value does not live long enough
|
||||
| |
|
||||
| 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
|
||||
|
|
||||
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
|
||||
...
|
||||
@ -28,7 +28,7 @@ error[E0597]: `x` does not live long enough
|
||||
--> $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`)
|
||||
| --------- ^ does not live long enough
|
||||
| --------- ^ borrowed value does not live long enough
|
||||
| |
|
||||
| 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
|
||||
|
|
||||
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
|
||||
...
|
||||
|
@ -42,6 +42,7 @@ fn f() {
|
||||
//~| NOTE consider using a `let` binding to increase its lifetime
|
||||
|
||||
} // (statement 7)
|
||||
//~^ NOTE temporary value needs to live until here
|
||||
|
||||
let mut v5 = Vec::new(); // statement 8
|
||||
|
||||
|
@ -1,49 +1,49 @@
|
||||
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
|
||||
| -------- borrow occurs here
|
||||
| ^^^^^^^^ borrowed value does not live long enough
|
||||
...
|
||||
43 | }
|
||||
| ^ `young[..]` dropped here while still borrowed
|
||||
56 | }
|
||||
| - `young[..]` dropped here while still borrowed
|
||||
|
|
||||
= note: values in a scope are dropped in the opposite order they are created
|
||||
|
||||
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
|
||||
| ------- ^ temporary value dropped here while still borrowed
|
||||
28 | v3.push(&id('x')); // statement 6
|
||||
| ^^^^^^^ - 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
|
||||
|
|
||||
= note: consider using a `let` binding to increase its lifetime
|
||||
|
||||
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'));
|
||||
| ------- ^ temporary value dropped here while still borrowed
|
||||
38 | v4.push(&id('y'));
|
||||
| ^^^^^^^ - 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
|
||||
|
|
||||
= note: consider using a `let` binding to increase its lifetime
|
||||
|
||||
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'));
|
||||
| ------- ^ temporary value dropped here while still borrowed
|
||||
49 | v5.push(&id('z'));
|
||||
| ^^^^^^^ - 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
|
||||
|
|
||||
= note: consider using a `let` binding to increase its lifetime
|
||||
|
@ -35,6 +35,7 @@ impl<'t> MakerTrait for Box<Trait<'t>+'static> {
|
||||
pub fn main() {
|
||||
let m : Box<Trait+'static> = make_val();
|
||||
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
|
||||
//
|
||||
@ -54,5 +55,4 @@ pub fn main() {
|
||||
// the type of `m` *strictly outlives* `'m`. Hence we get an
|
||||
// error.
|
||||
}
|
||||
//~^ ERROR `*m` does not live long enough
|
||||
|
||||
|
@ -1,11 +1,11 @@
|
||||
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));
|
||||
| -- borrow occurs here
|
||||
| ^^ borrowed value does not live long enough
|
||||
...
|
||||
56 | }
|
||||
| ^ `*m` dropped here while still borrowed
|
||||
57 | }
|
||||
| - `*m` dropped here while still borrowed
|
||||
|
|
||||
= note: values in a scope are dropped in the opposite order they are created
|
||||
|
||||
|
@ -12,5 +12,5 @@ fn main() {
|
||||
let p;
|
||||
let a = 42;
|
||||
p = &a;
|
||||
//~^ ERROR `a` does not live long enough
|
||||
}
|
||||
//~^ ERROR `a` does not live long enough
|
||||
|
@ -1,10 +1,11 @@
|
||||
error[E0597]: `a` does not live long enough
|
||||
--> $DIR/issue-36537.rs:15:1
|
||||
--> $DIR/issue-36537.rs:14:10
|
||||
|
|
||||
14 | p = &a;
|
||||
| - borrow occurs here
|
||||
15 | }
|
||||
| ^ `a` dropped here while still borrowed
|
||||
| ^ borrowed value does not live long enough
|
||||
15 | //~^ ERROR `a` does not live long enough
|
||||
16 | }
|
||||
| - `a` dropped here while still borrowed
|
||||
|
|
||||
= note: values in a scope are dropped in the opposite order they are created
|
||||
|
||||
|
@ -15,9 +15,9 @@ fn broken() {
|
||||
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
|
||||
_y.push(&mut z);
|
||||
//~^ ERROR `z` does not live long enough
|
||||
x += 1; //~ ERROR cannot assign
|
||||
}
|
||||
//~^ ERROR `z` does not live long enough
|
||||
}
|
||||
|
||||
fn main() { }
|
||||
|
@ -1,12 +1,11 @@
|
||||
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);
|
||||
| - borrow occurs here
|
||||
18 | x += 1; //~ ERROR cannot assign
|
||||
19 | }
|
||||
| ^ `z` dropped here while still borrowed
|
||||
20 | //~^ ERROR `z` does not live long enough
|
||||
| ^ borrowed value does not live long enough
|
||||
...
|
||||
20 | }
|
||||
| - `z` dropped here while still borrowed
|
||||
21 | }
|
||||
| - 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`
|
||||
|
||||
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];
|
||||
| - borrow of `x` occurs here
|
||||
...
|
||||
18 | x += 1; //~ ERROR cannot assign
|
||||
19 | x += 1; //~ ERROR cannot assign
|
||||
| ^^^^^^ assignment to borrowed `x` occurs here
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
|
Loading…
Reference in New Issue
Block a user