Skip to content

Commit 13fb079

Browse files
committed
Do not ICE on deeply nested borrows.
1 parent 1965237 commit 13fb079

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

compiler/rustc_mir_transform/src/ref_prop.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -363,8 +363,10 @@ impl<'tcx> MutVisitor<'tcx> for Replacer<'tcx> {
363363
if let Some((&PlaceElem::Deref, rest)) = target.projection.split_last() {
364364
*place = Place::from(target.local).project_deeper(rest, self.tcx);
365365
self.any_replacement = true;
366-
} else if self.fully_replacable_locals.contains(place.local) {
367-
debuginfo.references += 1;
366+
} else if self.fully_replacable_locals.contains(place.local)
367+
&& let Some(references) = debuginfo.references.checked_add(1)
368+
{
369+
debuginfo.references = references;
368370
*place = target;
369371
self.any_replacement = true;
370372
}

tests/mir-opt/reference_prop.rs

+13
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,18 @@ fn debuginfo() {
548548
}
549549
}
550550

551+
fn many_debuginfo() {
552+
let a = 0;
553+
554+
// Verify that we do not ICE on deeply nested borrows.
555+
let many_borrow =
556+
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
557+
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
558+
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
559+
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
560+
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&a;
561+
}
562+
551563
fn main() {
552564
let mut x = 5_usize;
553565
let mut y = 7_usize;
@@ -562,6 +574,7 @@ fn main() {
562574
mut_raw_then_mut_shr();
563575
unique_with_copies();
564576
debuginfo();
577+
many_debuginfo();
565578
}
566579

567580
// EMIT_MIR reference_prop.reference_propagation.ReferencePropagation.diff

0 commit comments

Comments
 (0)