diff --git a/compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs b/compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs index 638d89f5bcbdb..6bcfa9d8bf9a7 100644 --- a/compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs +++ b/compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs @@ -687,7 +687,7 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> { } } - Some(Cause::DropVar(local, location)) => { + Some(Cause::DropVar(local, location)) if !is_local_boring(local) => { let mut should_note_order = false; if self.local_name(local).is_some() && let Some((WriteKind::StorageDeadOrDrop, place)) = kind_place @@ -705,7 +705,7 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> { } } - Some(Cause::LiveVar(..)) | None => { + Some(Cause::LiveVar(..) | Cause::DropVar(..)) | None => { // Here, under NLL: no cause was found. Under polonius: no cause was found, or a // boring local was found, which we ignore like NLLs do to match its diagnostics. if let Some(region) = self.to_error_region_vid(borrow_region_vid) { diff --git a/tests/ui/nll/polonius/lending-iterator-sanity-checks.polonius.stderr b/tests/ui/nll/polonius/lending-iterator-sanity-checks.polonius.stderr index bf8546b63bf30..fa201b89048af 100644 --- a/tests/ui/nll/polonius/lending-iterator-sanity-checks.polonius.stderr +++ b/tests/ui/nll/polonius/lending-iterator-sanity-checks.polonius.stderr @@ -1,13 +1,15 @@ error[E0499]: cannot borrow `*t` as mutable more than once at a time --> $DIR/lending-iterator-sanity-checks.rs:19:19 | +LL | fn use_live(t: &mut T) -> Option<(T::Item<'_>, T::Item<'_>)> { + | - let's call the lifetime of this reference `'1` LL | let Some(i) = t.next() else { return None }; | - first mutable borrow occurs here LL | let Some(j) = t.next() else { return None }; | ^ second mutable borrow occurs here ... -LL | } - | - first borrow might be used here, when `i` is dropped and runs the destructor for type `::Item<'_>` +LL | Some((i, j)) + | ------------ returning this value requires that `*t` is borrowed for `'1` error[E0499]: cannot borrow `*t` as mutable more than once at a time --> $DIR/lending-iterator-sanity-checks.rs:31:13