Skip to content

Commit b7228c8

Browse files
committed
Moved overflow check into end_point function.
1 parent 13f8c82 commit b7228c8

File tree

2 files changed

+4
-7
lines changed

2 files changed

+4
-7
lines changed

src/librustc_mir/build/scope.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -699,12 +699,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
699699
let region_scope_span = region_scope.span(self.hir.tcx(),
700700
&self.hir.region_scope_tree);
701701
// Attribute scope exit drops to scope's closing brace.
702-
// Without this check when finding the endpoint, we'll run into an ICE.
703-
let scope_end = if region_scope_span.hi().0 == 0 {
704-
region_scope_span
705-
} else {
706-
region_scope_span.end_point()
707-
};
702+
let scope_end = region_scope_span.end_point();
708703

709704
scope.drops.push(DropData {
710705
span: scope_end,

src/libsyntax_pos/lib.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,9 @@ impl Span {
219219
/// Returns a new span representing just the end-point of this span
220220
pub fn end_point(self) -> Span {
221221
let span = self.data();
222-
let lo = cmp::max(span.hi.0 - 1, span.lo.0);
222+
// We can avoid an ICE by checking if subtraction would cause an overflow.
223+
let hi = if span.hi.0 == u32::min_value() { span.hi.0 } else { span.hi.0 - 1 };
224+
let lo = cmp::max(hi, span.lo.0);
223225
span.with_lo(BytePos(lo))
224226
}
225227

0 commit comments

Comments
 (0)