Skip to content

Commit 33c2952

Browse files
authored
Rollup merge of rust-lang#147729 - lqd:polonius-diagnostics, r=jackh726
ignore boring locals when explaining why a borrow contains a point due to drop of a live local under polonius Polonius liveness has to contain boring locals, and we ignore them in diagnostics, to match NLL diagnostics that never involve any boring locals. When explaining why a borrow contains a point, I ignored these boring locals when it was due to a use of a live var, but forgot to do so when the cause was because of a drop of a live var. This is what was causing the last two (known) diagnostics differences under the polonius compare-mode: - `tests/ui/dropck/dropck_trait_cycle_checked.rs` - `tests/ui/unboxed-closures/unboxed-closures-failed-recursive-fn-1.rs` r? `@jackh726`
2 parents 212826d + 68080de commit 33c2952

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)