Skip to content

Commit 00fbfcc

Browse files
committed
Auto merge of #46719 - estebank:issue-39268, r=pnkfelix
Point at var in short lived borrows instead of drop location For RLS' sake, point at the borrow location as primary span for short lived borrows, instead of the borrow drop location. Fix #39268.
2 parents b3392f8 + b562565 commit 00fbfcc

File tree

103 files changed

+585
-538
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

103 files changed

+585
-538
lines changed

Diff for: src/librustc_borrowck/borrowck/mod.rs

+7-11
Original file line numberDiff line numberDiff line change
@@ -919,11 +919,9 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
919919
}
920920

921921
let mut db = self.path_does_not_live_long_enough(error_span, &msg, Origin::Ast);
922-
let (value_kind, value_msg) = match err.cmt.cat {
923-
mc::Categorization::Rvalue(..) =>
924-
("temporary value", "temporary value created here"),
925-
_ =>
926-
("borrowed value", "borrow occurs here")
922+
let value_kind = match err.cmt.cat {
923+
mc::Categorization::Rvalue(..) => "temporary value",
924+
_ => "borrowed value",
927925
};
928926

929927
let is_closure = match cause {
@@ -936,14 +934,16 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
936934
Some(primary) => {
937935
db.span = MultiSpan::from_span(s);
938936
db.span_label(primary, "capture occurs here");
939-
db.span_label(s, "does not live long enough");
937+
db.span_label(s, format!("{} does not live long enough",
938+
value_kind));
940939
true
941940
}
942941
None => false
943942
}
944943
}
945944
_ => {
946-
db.span_label(error_span, "does not live long enough");
945+
db.span_label(error_span, format!("{} does not live long enough",
946+
value_kind));
947947
false
948948
}
949949
};
@@ -954,8 +954,6 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
954954
match (sub_span, super_span) {
955955
(Some(s1), Some(s2)) if s1 == s2 => {
956956
if !is_closure {
957-
db.span = MultiSpan::from_span(s1);
958-
db.span_label(error_span, value_msg);
959957
let msg = match opt_loan_path(&err.cmt) {
960958
None => value_kind.to_string(),
961959
Some(lp) => {
@@ -971,8 +969,6 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
971969
they are created");
972970
}
973971
(Some(s1), Some(s2)) if !is_closure => {
974-
db.span = MultiSpan::from_span(s2);
975-
db.span_label(error_span, value_msg);
976972
let msg = match opt_loan_path(&err.cmt) {
977973
None => value_kind.to_string(),
978974
Some(lp) => {

Diff for: src/librustc_mir/borrow_check/error_reporting.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -391,10 +391,10 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
391391
&mut self, name: &String, _scope_tree: &Rc<ScopeTree>, _borrow: &BorrowData<'tcx>,
392392
drop_span: Span, borrow_span: Span, _proper_span: Span, end_span: Option<Span>
393393
) {
394-
let mut err = self.tcx.path_does_not_live_long_enough(drop_span,
394+
let mut err = self.tcx.path_does_not_live_long_enough(borrow_span,
395395
&format!("`{}`", name),
396396
Origin::Mir);
397-
err.span_label(borrow_span, "borrow occurs here");
397+
err.span_label(borrow_span, "borrowed value does not live long enough");
398398
err.span_label(drop_span, format!("`{}` dropped here while still borrowed", name));
399399
if let Some(end) = end_span {
400400
err.span_label(end, "borrowed value needs to live until here");
@@ -404,12 +404,12 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
404404

405405
fn report_scoped_temporary_value_does_not_live_long_enough(
406406
&mut self, _scope_tree: &Rc<ScopeTree>, _borrow: &BorrowData<'tcx>,
407-
drop_span: Span, borrow_span: Span, proper_span: Span, end_span: Option<Span>
407+
drop_span: Span, _borrow_span: Span, proper_span: Span, end_span: Option<Span>
408408
) {
409-
let mut err = self.tcx.path_does_not_live_long_enough(borrow_span,
409+
let mut err = self.tcx.path_does_not_live_long_enough(proper_span,
410410
"borrowed value",
411411
Origin::Mir);
412-
err.span_label(proper_span, "temporary value created here");
412+
err.span_label(proper_span, "temporary value does not live long enough");
413413
err.span_label(drop_span, "temporary value dropped here while still borrowed");
414414
err.note("consider using a `let` binding to increase its lifetime");
415415
if let Some(end) = end_span {
@@ -425,7 +425,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
425425
let mut err = self.tcx.path_does_not_live_long_enough(borrow_span,
426426
&format!("`{}`", name),
427427
Origin::Mir);
428-
err.span_label(borrow_span, "does not live long enough");
428+
err.span_label(borrow_span, "borrowed value does not live long enough");
429429
err.span_label(drop_span, "borrowed value only lives until here");
430430
self.tcx.note_and_explain_region(scope_tree, &mut err,
431431
"borrowed value must be valid for ",
@@ -440,7 +440,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
440440
let mut err = self.tcx.path_does_not_live_long_enough(proper_span,
441441
"borrowed value",
442442
Origin::Mir);
443-
err.span_label(proper_span, "does not live long enough");
443+
err.span_label(proper_span, "temporary value does not live long enough");
444444
err.span_label(drop_span, "temporary value only lives until here");
445445
self.tcx.note_and_explain_region(scope_tree, &mut err,
446446
"borrowed value must be valid for ",

Diff for: src/test/compile-fail-fulldeps/dropck_tarena_cycle_checked.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,4 +124,4 @@ fn f<'a>(arena: &'a TypedArena<C<'a>>) {
124124
fn main() {
125125
let arena = TypedArena::new();
126126
f(&arena);
127-
} //~ ERROR `arena` does not live long enough
127+
} //~^ ERROR `arena` does not live long enough

Diff for: src/test/compile-fail-fulldeps/dropck_tarena_unsound_drop.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,5 @@ fn f<'a>(_arena: &'a TypedArena<C<'a>>) {}
4949
fn main() {
5050
let arena: TypedArena<C> = TypedArena::new();
5151
f(&arena);
52-
} //~ ERROR `arena` does not live long enough
52+
} //~^ ERROR `arena` does not live long enough
5353

Diff for: src/test/compile-fail/E0597.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@ fn main() {
1616
let mut x = Foo { x: None };
1717
let y = 0;
1818
x.x = Some(&y);
19-
} //~ `y` does not live long enough [E0597]
19+
//~^ `y` does not live long enough [E0597]
20+
}

Diff for: src/test/compile-fail/catch-bad-lifetime.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@ pub fn main() {
1818
let _result: Result<(), &str> = do catch {
1919
let my_string = String::from("");
2020
let my_str: & str = & my_string;
21+
//~^ ERROR `my_string` does not live long enough
2122
Err(my_str) ?;
2223
Err("") ?;
2324
Ok(())
24-
}; //~ ERROR `my_string` does not live long enough
25+
};
2526
}
2627

2728
{

Diff for: src/test/compile-fail/issue-36082.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ fn main() {
2121
let val: &_ = x.borrow().0;
2222
//[ast]~^ ERROR borrowed value does not live long enough [E0597]
2323
//[ast]~| NOTE temporary value dropped here while still borrowed
24-
//[ast]~| NOTE temporary value created here
24+
//[ast]~| NOTE temporary value does not live long enough
2525
//[ast]~| NOTE consider using a `let` binding to increase its lifetime
2626
//[mir]~^^^^^ ERROR borrowed value does not live long enough [E0597]
2727
//[mir]~| NOTE temporary value dropped here while still borrowed
28-
//[mir]~| NOTE temporary value created here
28+
//[mir]~| NOTE temporary value does not live long enough
2929
//[mir]~| NOTE consider using a `let` binding to increase its lifetime
3030
println!("{}", val);
3131
}

Diff for: src/test/compile-fail/region-borrow-params-issue-29793-big.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,9 @@ fn main() {
8181
WrapB::new().set(|t: bool| if t { x } else { y }) // (separate errors for `x` vs `y`)
8282
//[ast]~^ ERROR `x` does not live long enough
8383
//[ast]~| ERROR `y` does not live long enough
84+
//[mir]~^^^ ERROR `x` does not live long enough
85+
//[mir]~| ERROR `y` does not live long enough
8486
});
85-
//[mir]~^ ERROR `x` does not live long enough
86-
//[mir]~| ERROR `y` does not live long enough
8787

8888
w.handle(); // This works
8989
// w.handle_ref(); // This doesn't

Diff for: src/test/ui/dropck/dropck-eyepatch-extern-crate.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -37,22 +37,23 @@ fn main() {
3737
dr = Dr("dr", &c_long);
3838
// Error: destructor order imprecisely modelled
3939
dt = Dt("dt", &c);
40+
//~^ ERROR `c` does not live long enough
4041
dr = Dr("dr", &c);
42+
//~^ ERROR `c` does not live long enough
4143

4244
// No error: Drop impl asserts .1 (A and &'a _) are not accessed
4345
pt = Pt("pt", &c, &c_long);
4446
pr = Pr("pr", &c, &c_long);
4547

4648
// Error: Drop impl's assertion does not apply to `B` nor `&'b _`
4749
pt = Pt("pt", &c_long, &c);
50+
//~^ ERROR `c` does not live long enough
4851
pr = Pr("pr", &c_long, &c);
52+
//~^ ERROR `c` does not live long enough
4953

5054
// No error: St and Sr have no destructor.
5155
st = St("st", &c);
5256
sr = Sr("sr", &c);
5357

5458
println!("{:?}", (dt.0, dr.0, pt.0, pr.0, st.0, sr.0));
55-
}//~ ERROR `c` does not live long enough
56-
//~^ ERROR `c` does not live long enough
57-
//~| ERROR `c` does not live long enough
58-
//~| ERROR `c` does not live long enough
59+
}

Diff for: src/test/ui/dropck/dropck-eyepatch-extern-crate.stderr

+19-19
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,44 @@
11
error[E0597]: `c` does not live long enough
2-
--> $DIR/dropck-eyepatch-extern-crate.rs:55:1
2+
--> $DIR/dropck-eyepatch-extern-crate.rs:39:20
33
|
44
39 | dt = Dt("dt", &c);
5-
| - borrow occurs here
5+
| ^ borrowed value does not live long enough
66
...
7-
55 | }//~ ERROR `c` does not live long enough
8-
| ^ `c` dropped here while still borrowed
7+
59 | }
8+
| - `c` dropped here while still borrowed
99
|
1010
= note: values in a scope are dropped in the opposite order they are created
1111

1212
error[E0597]: `c` does not live long enough
13-
--> $DIR/dropck-eyepatch-extern-crate.rs:55:1
13+
--> $DIR/dropck-eyepatch-extern-crate.rs:41:20
1414
|
15-
40 | dr = Dr("dr", &c);
16-
| - borrow occurs here
15+
41 | dr = Dr("dr", &c);
16+
| ^ borrowed value does not live long enough
1717
...
18-
55 | }//~ ERROR `c` does not live long enough
19-
| ^ `c` dropped here while still borrowed
18+
59 | }
19+
| - `c` dropped here while still borrowed
2020
|
2121
= note: values in a scope are dropped in the opposite order they are created
2222

2323
error[E0597]: `c` does not live long enough
24-
--> $DIR/dropck-eyepatch-extern-crate.rs:55:1
24+
--> $DIR/dropck-eyepatch-extern-crate.rs:49:29
2525
|
26-
47 | pt = Pt("pt", &c_long, &c);
27-
| - borrow occurs here
26+
49 | pt = Pt("pt", &c_long, &c);
27+
| ^ borrowed value does not live long enough
2828
...
29-
55 | }//~ ERROR `c` does not live long enough
30-
| ^ `c` dropped here while still borrowed
29+
59 | }
30+
| - `c` dropped here while still borrowed
3131
|
3232
= note: values in a scope are dropped in the opposite order they are created
3333

3434
error[E0597]: `c` does not live long enough
35-
--> $DIR/dropck-eyepatch-extern-crate.rs:55:1
35+
--> $DIR/dropck-eyepatch-extern-crate.rs:51:29
3636
|
37-
48 | pr = Pr("pr", &c_long, &c);
38-
| - borrow occurs here
37+
51 | pr = Pr("pr", &c_long, &c);
38+
| ^ borrowed value does not live long enough
3939
...
40-
55 | }//~ ERROR `c` does not live long enough
41-
| ^ `c` dropped here while still borrowed
40+
59 | }
41+
| - `c` dropped here while still borrowed
4242
|
4343
= note: values in a scope are dropped in the opposite order they are created
4444

Diff for: src/test/ui/dropck/dropck-eyepatch-reorder.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -55,23 +55,23 @@ fn main() {
5555
dr = Dr("dr", &c_long);
5656
// Error: destructor order imprecisely modelled
5757
dt = Dt("dt", &c);
58+
//~^ ERROR `c` does not live long enough
5859
dr = Dr("dr", &c);
60+
//~^ ERROR `c` does not live long enough
5961

6062
// No error: Drop impl asserts .1 (A and &'a _) are not accessed
6163
pt = Pt("pt", &c, &c_long);
6264
pr = Pr("pr", &c, &c_long);
6365

6466
// Error: Drop impl's assertion does not apply to `B` nor `&'b _`
6567
pt = Pt("pt", &c_long, &c);
68+
//~^ ERROR `c` does not live long enough
6669
pr = Pr("pr", &c_long, &c);
70+
//~^ ERROR `c` does not live long enough
6771

6872
// No error: St and Sr have no destructor.
6973
st = St("st", &c);
7074
sr = Sr("sr", &c);
7175

7276
println!("{:?}", (dt.0, dr.0, pt.0, pr.0, st.0, sr.0));
7377
}
74-
//~^ ERROR `c` does not live long enough
75-
//~| ERROR `c` does not live long enough
76-
//~| ERROR `c` does not live long enough
77-
//~| ERROR `c` does not live long enough

Diff for: src/test/ui/dropck/dropck-eyepatch-reorder.stderr

+19-19
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,44 @@
11
error[E0597]: `c` does not live long enough
2-
--> $DIR/dropck-eyepatch-reorder.rs:73:1
2+
--> $DIR/dropck-eyepatch-reorder.rs:57:20
33
|
44
57 | dt = Dt("dt", &c);
5-
| - borrow occurs here
5+
| ^ borrowed value does not live long enough
66
...
7-
73 | }
8-
| ^ `c` dropped here while still borrowed
7+
77 | }
8+
| - `c` dropped here while still borrowed
99
|
1010
= note: values in a scope are dropped in the opposite order they are created
1111

1212
error[E0597]: `c` does not live long enough
13-
--> $DIR/dropck-eyepatch-reorder.rs:73:1
13+
--> $DIR/dropck-eyepatch-reorder.rs:59:20
1414
|
15-
58 | dr = Dr("dr", &c);
16-
| - borrow occurs here
15+
59 | dr = Dr("dr", &c);
16+
| ^ borrowed value does not live long enough
1717
...
18-
73 | }
19-
| ^ `c` dropped here while still borrowed
18+
77 | }
19+
| - `c` dropped here while still borrowed
2020
|
2121
= note: values in a scope are dropped in the opposite order they are created
2222

2323
error[E0597]: `c` does not live long enough
24-
--> $DIR/dropck-eyepatch-reorder.rs:73:1
24+
--> $DIR/dropck-eyepatch-reorder.rs:67:29
2525
|
26-
65 | pt = Pt("pt", &c_long, &c);
27-
| - borrow occurs here
26+
67 | pt = Pt("pt", &c_long, &c);
27+
| ^ borrowed value does not live long enough
2828
...
29-
73 | }
30-
| ^ `c` dropped here while still borrowed
29+
77 | }
30+
| - `c` dropped here while still borrowed
3131
|
3232
= note: values in a scope are dropped in the opposite order they are created
3333

3434
error[E0597]: `c` does not live long enough
35-
--> $DIR/dropck-eyepatch-reorder.rs:73:1
35+
--> $DIR/dropck-eyepatch-reorder.rs:69:29
3636
|
37-
66 | pr = Pr("pr", &c_long, &c);
38-
| - borrow occurs here
37+
69 | pr = Pr("pr", &c_long, &c);
38+
| ^ borrowed value does not live long enough
3939
...
40-
73 | }
41-
| ^ `c` dropped here while still borrowed
40+
77 | }
41+
| - `c` dropped here while still borrowed
4242
|
4343
= note: values in a scope are dropped in the opposite order they are created
4444

Diff for: src/test/ui/dropck/dropck-eyepatch.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -78,23 +78,23 @@ fn main() {
7878
dr = Dr("dr", &c_long);
7979
// Error: destructor order imprecisely modelled
8080
dt = Dt("dt", &c);
81+
//~^ ERROR `c` does not live long enough
8182
dr = Dr("dr", &c);
83+
//~^ ERROR `c` does not live long enough
8284

8385
// No error: Drop impl asserts .1 (A and &'a _) are not accessed
8486
pt = Pt("pt", &c, &c_long);
8587
pr = Pr("pr", &c, &c_long);
8688

8789
// Error: Drop impl's assertion does not apply to `B` nor `&'b _`
8890
pt = Pt("pt", &c_long, &c);
91+
//~^ ERROR `c` does not live long enough
8992
pr = Pr("pr", &c_long, &c);
93+
//~^ ERROR `c` does not live long enough
9094

9195
// No error: St and Sr have no destructor.
9296
st = St("st", &c);
9397
sr = Sr("sr", &c);
9498

9599
println!("{:?}", (dt.0, dr.0, pt.0, pr.0, st.0, sr.0));
96100
}
97-
//~^ ERROR `c` does not live long enough
98-
//~| ERROR `c` does not live long enough
99-
//~| ERROR `c` does not live long enough
100-
//~| ERROR `c` does not live long enough

0 commit comments

Comments
 (0)