]> git.lizzy.rs Git - rust.git/commitdiff
Moved overflow check into end_point function.
authorDavid Wood <david@davidtw.co>
Sun, 14 Jan 2018 00:23:35 +0000 (00:23 +0000)
committerDavid Wood <david@davidtw.co>
Sat, 27 Jan 2018 11:46:26 +0000 (11:46 +0000)
src/librustc_mir/build/scope.rs
src/libsyntax_pos/lib.rs

index 389e06e93349050ea359492fd205caa1b3024ec9..50e50b95f7750401cff775c2e15c1a271e630322 100644 (file)
@@ -699,12 +699,7 @@ pub fn schedule_drop(&mut self,
                 let region_scope_span = region_scope.span(self.hir.tcx(),
                                                           &self.hir.region_scope_tree);
                 // Attribute scope exit drops to scope's closing brace.
-                // Without this check when finding the endpoint, we'll run into an ICE.
-                let scope_end = if region_scope_span.hi().0 == 0 {
-                    region_scope_span
-                } else {
-                    region_scope_span.end_point()
-                };
+                let scope_end = region_scope_span.end_point();
 
                 scope.drops.push(DropData {
                     span: scope_end,
index 85f0925b98210383459cc783e35cc131af6165aa..5866d8e4aa9323668195c87b2a67c6e9cdaac95e 100644 (file)
@@ -219,7 +219,9 @@ pub fn with_ctxt(self, ctxt: SyntaxContext) -> Span {
     /// Returns a new span representing just the end-point of this span
     pub fn end_point(self) -> Span {
         let span = self.data();
-        let lo = cmp::max(span.hi.0 - 1, span.lo.0);
+        // We can avoid an ICE by checking if subtraction would cause an overflow.
+        let hi = if span.hi.0 == u32::min_value() { span.hi.0 } else { span.hi.0 - 1 };
+        let lo = cmp::max(hi, span.lo.0);
         span.with_lo(BytePos(lo))
     }