Skip to content

Commit 68080de

Browse files
committed
ignore boring locals when explaining borrow due to drop
Polonius liveness has to contain boring locals, and we ignore them in diagnostics to match NLL diagnostics, since they doesn't contain boring locals. We ignored these when explaining why a loan contained a point due to a use of a live var, but not when it contained a point due to a drop of a live var.
1 parent 4f08307 commit 68080de

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,7 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> {
687687
}
688688
}
689689

690-
Some(Cause::DropVar(local, location)) => {
690+
Some(Cause::DropVar(local, location)) if !is_local_boring(local) => {
691691
let mut should_note_order = false;
692692
if self.local_name(local).is_some()
693693
&& let Some((WriteKind::StorageDeadOrDrop, place)) = kind_place
@@ -705,7 +705,7 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> {
705705
}
706706
}
707707

708-
Some(Cause::LiveVar(..)) | None => {
708+
Some(Cause::LiveVar(..) | Cause::DropVar(..)) | None => {
709709
// Here, under NLL: no cause was found. Under polonius: no cause was found, or a
710710
// boring local was found, which we ignore like NLLs do to match its diagnostics.
711711
if let Some(region) = self.to_error_region_vid(borrow_region_vid) {

tests/ui/nll/polonius/lending-iterator-sanity-checks.polonius.stderr

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
error[E0499]: cannot borrow `*t` as mutable more than once at a time
22
--> $DIR/lending-iterator-sanity-checks.rs:19:19
33
|
4+
LL | fn use_live<T: LendingIterator>(t: &mut T) -> Option<(T::Item<'_>, T::Item<'_>)> {
5+
| - let's call the lifetime of this reference `'1`
46
LL | let Some(i) = t.next() else { return None };
57
| - first mutable borrow occurs here
68
LL | let Some(j) = t.next() else { return None };
79
| ^ second mutable borrow occurs here
810
...
9-
LL | }
10-
| - first borrow might be used here, when `i` is dropped and runs the destructor for type `<T as LendingIterator>::Item<'_>`
11+
LL | Some((i, j))
12+
| ------------ returning this value requires that `*t` is borrowed for `'1`
1113

1214
error[E0499]: cannot borrow `*t` as mutable more than once at a time
1315
--> $DIR/lending-iterator-sanity-checks.rs:31:13

0 commit comments

Comments
 (0)