Skip to content

Commit 02079e4

Browse files
committed
Point at var in short lived borrows
1 parent 9331031 commit 02079e4

File tree

82 files changed

+514
-470
lines changed

Some content is hidden

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

82 files changed

+514
-470
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/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

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

+32-32
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,46 @@
11
error[E0597]: `c` does not live long enough
2-
--> $DIR/dropck-eyepatch.rs:96:1
3-
|
4-
80 | dt = Dt("dt", &c);
5-
| - borrow occurs here
2+
--> $DIR/dropck-eyepatch.rs:80:20
3+
|
4+
80 | dt = Dt("dt", &c);
5+
| ^ borrowed value does not live long enough
66
...
7-
96 | }
8-
| ^ `c` dropped here while still borrowed
9-
|
10-
= note: values in a scope are dropped in the opposite order they are created
7+
100 | }
8+
| - `c` dropped here while still borrowed
9+
|
10+
= 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.rs:96:1
14-
|
15-
81 | dr = Dr("dr", &c);
16-
| - borrow occurs here
13+
--> $DIR/dropck-eyepatch.rs:82:20
14+
|
15+
82 | dr = Dr("dr", &c);
16+
| ^ borrowed value does not live long enough
1717
...
18-
96 | }
19-
| ^ `c` dropped here while still borrowed
20-
|
21-
= note: values in a scope are dropped in the opposite order they are created
18+
100 | }
19+
| - `c` dropped here while still borrowed
20+
|
21+
= 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.rs:96:1
25-
|
26-
88 | pt = Pt("pt", &c_long, &c);
27-
| - borrow occurs here
24+
--> $DIR/dropck-eyepatch.rs:90:29
25+
|
26+
90 | pt = Pt("pt", &c_long, &c);
27+
| ^ borrowed value does not live long enough
2828
...
29-
96 | }
30-
| ^ `c` dropped here while still borrowed
31-
|
32-
= note: values in a scope are dropped in the opposite order they are created
29+
100 | }
30+
| - `c` dropped here while still borrowed
31+
|
32+
= 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.rs:96:1
36-
|
37-
89 | pr = Pr("pr", &c_long, &c);
38-
| - borrow occurs here
35+
--> $DIR/dropck-eyepatch.rs:92:29
36+
|
37+
92 | pr = Pr("pr", &c_long, &c);
38+
| ^ borrowed value does not live long enough
3939
...
40-
96 | }
41-
| ^ `c` dropped here while still borrowed
42-
|
43-
= note: values in a scope are dropped in the opposite order they are created
40+
100 | }
41+
| - `c` dropped here while still borrowed
42+
|
43+
= note: values in a scope are dropped in the opposite order they are created
4444

4545
error: aborting due to 4 previous errors
4646

Diff for: src/test/ui/generator/borrowing.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0597]: `a` does not live long enough
22
--> $DIR/borrowing.rs:18:20
33
|
44
18 | (|| yield &a).resume()
5-
| -- ^ does not live long enough
5+
| -- ^ borrowed value does not live long enough
66
| |
77
| capture occurs here
88
19 | //~^ ERROR: `a` does not live long enough
@@ -18,7 +18,7 @@ error[E0597]: `a` does not live long enough
1818
24 | || {
1919
| -- capture occurs here
2020
25 | yield &a
21-
| ^ does not live long enough
21+
| ^ borrowed value does not live long enough
2222
...
2323
28 | };
2424
| - borrowed value only lives until here

Diff for: src/test/ui/generator/ref-escapes-but-not-over-yield.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ fn foo(x: &i32) {
2222
yield();
2323
let b = 5;
2424
a = &b;
25-
}; //~ ERROR
25+
//~^ ERROR `b` does not live long enough
26+
};
2627
}
2728

2829
fn main() { }

Diff for: src/test/ui/generator/ref-escapes-but-not-over-yield.stderr

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
error[E0597]: `b` does not live long enough
2-
--> $DIR/ref-escapes-but-not-over-yield.rs:25:5
2+
--> $DIR/ref-escapes-but-not-over-yield.rs:24:14
33
|
44
24 | a = &b;
5-
| - borrow occurs here
6-
25 | }; //~ ERROR
7-
| ^ `b` dropped here while still borrowed
8-
26 | }
5+
| ^ borrowed value does not live long enough
6+
25 | //~^ ERROR `b` does not live long enough
7+
26 | };
8+
| - `b` dropped here while still borrowed
9+
27 | }
910
| - borrowed value needs to live until here
1011

1112
error: aborting due to previous error

0 commit comments

Comments
 (0)