Skip to content

Commit 2aeb765

Browse files
Rollup merge of rust-lang#52617 - matthewjasper:remove-unused-code, r=nikomatsakis
Don't match on region kinds when reporting NLL errors First half (by number of tests affected) of the changes to "does not live long enough". Now that lexical MIR borrowck is gone, region kinds are always ReVar, so matching on them to change errors does nothing. Changes "borrowed value only lives until here" to "`x` is dropped here while still borrowed". r? @pnkfelix cc @nikomatsakis
2 parents 0127704 + 338d545 commit 2aeb765

File tree

66 files changed

+135
-198
lines changed

Some content is hidden

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

66 files changed

+135
-198
lines changed

src/librustc_mir/borrow_check/error_reporting.rs

+14-95
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use rustc::mir::{BindingForm, BorrowKind, ClearCrossCrate, Field, Local};
1414
use rustc::mir::{LocalDecl, LocalKind, Location, Operand, Place};
1515
use rustc::mir::{ProjectionElem, Rvalue, Statement, StatementKind};
1616
use rustc::mir::VarBindingForm;
17-
use rustc::ty::{self, RegionKind};
17+
use rustc::ty;
1818
use rustc_data_structures::indexed_vec::Idx;
1919
use rustc_data_structures::sync::Lrc;
2020
use syntax_pos::Span;
@@ -427,34 +427,9 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
427427
self.access_place_error_reported
428428
.insert((root_place.clone(), borrow_span));
429429

430-
match (borrow.region, &self.describe_place(&borrow.borrowed_place)) {
431-
(RegionKind::ReScope(_), Some(name)) => {
432-
self.report_scoped_local_value_does_not_live_long_enough(
433-
context,
434-
name,
435-
&scope_tree,
436-
&borrow,
437-
drop_span,
438-
borrow_span,
439-
proper_span,
440-
);
441-
}
442-
(RegionKind::ReScope(_), None) => {
443-
self.report_scoped_temporary_value_does_not_live_long_enough(
444-
context,
445-
&scope_tree,
446-
&borrow,
447-
drop_span,
448-
borrow_span,
449-
proper_span,
450-
);
451-
}
452-
(RegionKind::ReEarlyBound(_), Some(name))
453-
| (RegionKind::ReFree(_), Some(name))
454-
| (RegionKind::ReStatic, Some(name))
455-
| (RegionKind::ReEmpty, Some(name))
456-
| (RegionKind::ReVar(_), Some(name)) => {
457-
self.report_unscoped_local_value_does_not_live_long_enough(
430+
match &self.describe_place(&borrow.borrowed_place) {
431+
Some(name) => {
432+
self.report_local_value_does_not_live_long_enough(
458433
context,
459434
name,
460435
&scope_tree,
@@ -465,12 +440,8 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
465440
kind.map(|k| (k, place_span.0)),
466441
);
467442
}
468-
(RegionKind::ReEarlyBound(_), None)
469-
| (RegionKind::ReFree(_), None)
470-
| (RegionKind::ReStatic, None)
471-
| (RegionKind::ReEmpty, None)
472-
| (RegionKind::ReVar(_), None) => {
473-
self.report_unscoped_temporary_value_does_not_live_long_enough(
443+
None => {
444+
self.report_temporary_value_does_not_live_long_enough(
474445
context,
475446
&scope_tree,
476447
&borrow,
@@ -479,65 +450,10 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
479450
proper_span,
480451
);
481452
}
482-
(RegionKind::ReLateBound(_, _), _)
483-
| (RegionKind::ReSkolemized(_, _), _)
484-
| (RegionKind::ReClosureBound(_), _)
485-
| (RegionKind::ReCanonical(_), _)
486-
| (RegionKind::ReErased, _) => {
487-
span_bug!(
488-
drop_span,
489-
"region {:?} does not make sense in this context",
490-
borrow.region
491-
);
492-
}
493453
}
494454
}
495455

496-
fn report_scoped_local_value_does_not_live_long_enough(
497-
&mut self,
498-
context: Context,
499-
name: &String,
500-
_scope_tree: &Lrc<ScopeTree>,
501-
borrow: &BorrowData<'tcx>,
502-
drop_span: Span,
503-
borrow_span: Span,
504-
_proper_span: Span,
505-
) {
506-
let tcx = self.tcx;
507-
let mut err =
508-
tcx.path_does_not_live_long_enough(borrow_span, &format!("`{}`", name), Origin::Mir);
509-
err.span_label(borrow_span, "borrowed value does not live long enough");
510-
err.span_label(
511-
drop_span,
512-
format!("`{}` dropped here while still borrowed", name),
513-
);
514-
self.explain_why_borrow_contains_point(context, borrow, None, &mut err);
515-
err.buffer(&mut self.errors_buffer);
516-
}
517-
518-
fn report_scoped_temporary_value_does_not_live_long_enough(
519-
&mut self,
520-
context: Context,
521-
_scope_tree: &Lrc<ScopeTree>,
522-
borrow: &BorrowData<'tcx>,
523-
drop_span: Span,
524-
_borrow_span: Span,
525-
proper_span: Span,
526-
) {
527-
let tcx = self.tcx;
528-
let mut err =
529-
tcx.path_does_not_live_long_enough(proper_span, "borrowed value", Origin::Mir);
530-
err.span_label(proper_span, "temporary value does not live long enough");
531-
err.span_label(
532-
drop_span,
533-
"temporary value dropped here while still borrowed",
534-
);
535-
err.note("consider using a `let` binding to increase its lifetime");
536-
self.explain_why_borrow_contains_point(context, borrow, None, &mut err);
537-
err.buffer(&mut self.errors_buffer);
538-
}
539-
540-
fn report_unscoped_local_value_does_not_live_long_enough(
456+
fn report_local_value_does_not_live_long_enough(
541457
&mut self,
542458
context: Context,
543459
name: &String,
@@ -549,7 +465,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
549465
kind_place: Option<(WriteKind, &Place<'tcx>)>,
550466
) {
551467
debug!(
552-
"report_unscoped_local_value_does_not_live_long_enough(\
468+
"report_local_value_does_not_live_long_enough(\
553469
{:?}, {:?}, {:?}, {:?}, {:?}, {:?}\
554470
)",
555471
context, name, scope_tree, borrow, drop_span, borrow_span
@@ -559,13 +475,16 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
559475
let mut err =
560476
tcx.path_does_not_live_long_enough(borrow_span, &format!("`{}`", name), Origin::Mir);
561477
err.span_label(borrow_span, "borrowed value does not live long enough");
562-
err.span_label(drop_span, "borrowed value only lives until here");
478+
err.span_label(
479+
drop_span,
480+
format!("`{}` dropped here while still borrowed", name),
481+
);
563482

564483
self.explain_why_borrow_contains_point(context, borrow, kind_place, &mut err);
565484
err.buffer(&mut self.errors_buffer);
566485
}
567486

568-
fn report_unscoped_temporary_value_does_not_live_long_enough(
487+
fn report_temporary_value_does_not_live_long_enough(
569488
&mut self,
570489
context: Context,
571490
scope_tree: &Lrc<ScopeTree>,
@@ -575,7 +494,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
575494
proper_span: Span,
576495
) {
577496
debug!(
578-
"report_unscoped_temporary_value_does_not_live_long_enough(\
497+
"report_temporary_value_does_not_live_long_enough(\
579498
{:?}, {:?}, {:?}, {:?}, {:?}\
580499
)",
581500
context, scope_tree, borrow, drop_span, proper_span

src/test/ui/borrowck/borrowck-escaping-closure-error-1.nll.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | spawn(|| books.push(4));
55
| ^^^^^^^^^^^^^^^^ borrowed value does not live long enough
66
LL | //~^ ERROR E0373
77
LL | }
8-
| - borrowed value only lives until here
8+
| - `books` dropped here while still borrowed
99
|
1010
= note: borrowed value must be valid for the static lifetime...
1111

src/test/ui/borrowck/borrowck-escaping-closure-error-2.nll.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | Box::new(|| books.push(4))
55
| ^^^^^^^^^^^^^^^^ borrowed value does not live long enough
66
LL | //~^ ERROR E0373
77
LL | }
8-
| - borrowed value only lives until here
8+
| - `books` dropped here while still borrowed
99
|
1010
note: borrowed value must be valid for the lifetime 'a as defined on the function body at 19:8...
1111
--> $DIR/borrowck-escaping-closure-error-2.rs:19:8

src/test/ui/dropck/dropck-eyepatch-extern-crate.nll.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | dt = Dt("dt", &c_shortest);
77
LL | }
88
| -
99
| |
10-
| borrowed value only lives until here
10+
| `c_shortest` dropped here while still borrowed
1111
| borrow later used here, when `dt` is dropped
1212
|
1313
= note: values in a scope are dropped in the opposite order they are defined

src/test/ui/dropck/dropck-eyepatch-reorder.nll.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | dt = Dt("dt", &c_shortest);
77
LL | }
88
| -
99
| |
10-
| borrowed value only lives until here
10+
| `c_shortest` dropped here while still borrowed
1111
| borrow later used here, when `dt` is dropped
1212
|
1313
= note: values in a scope are dropped in the opposite order they are defined

src/test/ui/dropck/dropck-eyepatch.nll.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | dt = Dt("dt", &c_shortest);
77
LL | }
88
| -
99
| |
10-
| borrowed value only lives until here
10+
| `c_shortest` dropped here while still borrowed
1111
| borrow later used here, when `dt` is dropped
1212
|
1313
= note: values in a scope are dropped in the opposite order they are defined

src/test/ui/error-codes/E0597.nll.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | //~^ `y` does not live long enough [E0597]
77
LL | }
88
| -
99
| |
10-
| borrowed value only lives until here
10+
| `y` dropped here while still borrowed
1111
| borrow later used here, when `x` is dropped
1212
|
1313
= note: values in a scope are dropped in the opposite order they are defined

src/test/ui/generator/borrowing.nll.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | unsafe { (|| yield &a).resume() }
55
| ^^^^^^^^^^^^^ borrowed value does not live long enough
66
LL | //~^ ERROR: `a` does not live long enough
77
LL | };
8-
| - borrowed value only lives until here
8+
| - `a` dropped here while still borrowed
99

1010
error[E0597]: `a` does not live long enough
1111
--> $DIR/borrowing.rs:24:9
@@ -16,7 +16,7 @@ LL | | //~^ ERROR: `a` does not live long enough
1616
LL | | }
1717
| |_________^ borrowed value does not live long enough
1818
LL | };
19-
| - borrowed value only lives until here
19+
| - `a` dropped here while still borrowed
2020
LL | }
2121
| - borrow later used here, when `_b` is dropped
2222

src/test/ui/generator/dropck.nll.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | let ref_ = Box::leak(Box::new(Some(cell.borrow_mut())));
77
LL | }
88
| -
99
| |
10-
| borrowed value only lives until here
10+
| `*cell` dropped here while still borrowed
1111
| borrow later used here, when `gen` is dropped
1212
|
1313
= note: values in a scope are dropped in the opposite order they are defined
@@ -26,7 +26,7 @@ LL | | };
2626
LL | }
2727
| -
2828
| |
29-
| borrowed value only lives until here
29+
| `ref_` dropped here while still borrowed
3030
| borrow later used here, when `gen` is dropped
3131
|
3232
= note: values in a scope are dropped in the opposite order they are defined

src/test/ui/generator/ref-escapes-but-not-over-yield.nll.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | a = &b;
55
| ^^ borrowed value does not live long enough
66
LL | //~^ ERROR `b` does not live long enough
77
LL | };
8-
| - borrowed value only lives until here
8+
| - `b` dropped here while still borrowed
99

1010
error: aborting due to previous error
1111

src/test/ui/issue-12470.nll.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | let bb: &B = &*b; //~ ERROR does not live long enough
55
| ^^^ borrowed value does not live long enough
66
LL | make_a(bb)
77
LL | }
8-
| - borrowed value only lives until here
8+
| - `*b` dropped here while still borrowed
99
|
1010
note: borrowed value must be valid for the lifetime 'a as defined on the function body at 36:16...
1111
--> $DIR/issue-12470.rs:36:16

src/test/ui/issue-13497-2.nll.stderr

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
error[E0597]: `rawLines` does not live long enough
2+
--> $DIR/issue-13497-2.rs:13:5
3+
|
4+
LL | rawLines //~ ERROR `rawLines` does not live long enough
5+
| ^^^^^^^^ borrowed value does not live long enough
6+
LL | .iter().map(|l| l.trim()).collect()
7+
LL | }
8+
| - `rawLines` dropped here while still borrowed
9+
|
10+
note: borrowed value must be valid for the lifetime 'a as defined on the function body at 11:24...
11+
--> $DIR/issue-13497-2.rs:11:24
12+
|
13+
LL | fn read_lines_borrowed<'a>() -> Vec<&'a str> {
14+
| ^^
15+
16+
error: aborting due to previous error
17+
18+
For more information about this error, try `rustc --explain E0597`.

src/test/ui/issue-17954.ast.nll.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | let a = &FOO;
55
| ^^^^ borrowed value does not live long enough
66
...
77
LL | }
8-
| - borrowed value only lives until here
8+
| - `FOO` dropped here while still borrowed
99
|
1010
= note: borrowed value must be valid for the static lifetime...
1111

src/test/ui/issue-17954.mir.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | let a = &FOO;
55
| ^^^^ borrowed value does not live long enough
66
...
77
LL | }
8-
| - borrowed value only lives until here
8+
| - `FOO` dropped here while still borrowed
99
|
1010
= note: borrowed value must be valid for the static lifetime...
1111

src/test/ui/issue-17954.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,5 @@ fn main() {
2929
println!("{}", a);
3030
});
3131
}
32-
//[mir]~^ borrowed value only lives until here
32+
//[mir]~^ `FOO` dropped here while still borrowed
3333
//[ast]~^^ temporary value only lives until here

src/test/ui/issue-18118.nll.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ LL | &p //~ ERROR `p` does not live long enough
5757
| ^^ borrowed value does not live long enough
5858
LL | //~^ ERROR let bindings in constants are unstable
5959
LL | };
60-
| - borrowed value only lives until here
60+
| - `p` dropped here while still borrowed
6161
|
6262
= note: borrowed value must be valid for the static lifetime...
6363

src/test/ui/issue-30438-c.nll.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | &x
55
| ^^ borrowed value does not live long enough
66
LL | //~^ ERROR: `x` does not live long enough
77
LL | }
8-
| - borrowed value only lives until here
8+
| - `x` dropped here while still borrowed
99
|
1010
note: borrowed value must be valid for the lifetime 'y as defined on the function body at 17:10...
1111
--> $DIR/issue-30438-c.rs:17:10

src/test/ui/issue-4335.nll.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ LL | id(Box::new(|| *v))
1111
| ^^^^^ borrowed value does not live long enough
1212
...
1313
LL | }
14-
| - borrowed value only lives until here
14+
| - `v` dropped here while still borrowed
1515
|
1616
note: borrowed value must be valid for the lifetime 'r as defined on the function body at 15:6...
1717
--> $DIR/issue-4335.rs:15:6

src/test/ui/issue-46036.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | let foo = Foo { x: &a }; //~ ERROR E0597
55
| ^^ borrowed value does not live long enough
66
LL | loop { }
77
LL | }
8-
| - borrowed value only lives until here
8+
| - `a` dropped here while still borrowed
99
|
1010
= note: borrowed value must be valid for the static lifetime...
1111

src/test/ui/issue-46471-1.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ LL | | &mut z
2020
LL | | };
2121
| | -
2222
| | |
23-
| |_____borrowed value only lives until here
23+
| |_____`z` dropped here while still borrowed
2424
| borrow later used here
2525

2626
error: aborting due to 2 previous errors

src/test/ui/issue-46471.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ LL | &x
1616
| ^^ borrowed value does not live long enough
1717
...
1818
LL | }
19-
| - borrowed value only lives until here
19+
| - `x` dropped here while still borrowed
2020
|
2121
= note: borrowed value must be valid for the static lifetime...
2222

src/test/ui/issue-52126-assign-op-invariance.nll.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ LL | println!("accumulator before add_assign {:?}", acc.map);
88
| ------- borrow later used here
99
...
1010
LL | }
11-
| - borrowed value only lives until here
11+
| - `line` dropped here while still borrowed
1212

1313
error: aborting due to previous error
1414

src/test/ui/nll/borrowed-local-error.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ LL | | //~^ ERROR `v` does not live long enough [E0597]
1010
LL | | });
1111
| |_____-- borrow later used here
1212
| |
13-
| borrowed value only lives until here
13+
| `v` dropped here while still borrowed
1414

1515
error: aborting due to previous error
1616

src/test/ui/nll/borrowed-universal-error-2.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | &v
55
| ^^ borrowed value does not live long enough
66
LL | //~^ ERROR `v` does not live long enough [E0597]
77
LL | }
8-
| - borrowed value only lives until here
8+
| - `v` dropped here while still borrowed
99
|
1010
note: borrowed value must be valid for the lifetime 'a as defined on the function body at 14:8...
1111
--> $DIR/borrowed-universal-error-2.rs:14:8

0 commit comments

Comments
 (0)