]> git.lizzy.rs Git - rust.git/commitdiff
Return early to avoid failing assertion
authorYuki Okushi <huyuumi.dev@gmail.com>
Thu, 8 Aug 2019 04:38:23 +0000 (13:38 +0900)
committerYuki Okushi <huyuumi.dev@gmail.com>
Thu, 8 Aug 2019 04:38:23 +0000 (13:38 +0900)
src/librustc_lint/types.rs
src/test/ui/issues/issue-63364.rs [new file with mode: 0644]
src/test/ui/issues/issue-63364.stderr [new file with mode: 0644]

index fdfc6f68590a4b308abf99a4a2bbdb1257f2a5b5..e86230437f2771cc1dc1f5fca45d78c8da95de23 100644 (file)
@@ -73,7 +73,9 @@ fn lint_overflowing_range_endpoint<'a, 'tcx>(
     // We only want to handle exclusive (`..`) ranges,
     // which are represented as `ExprKind::Struct`.
     if let ExprKind::Struct(_, eps, _) = &parent_expr.node {
-        debug_assert_eq!(eps.len(), 2);
+        if eps.len() != 2 {
+            return false;
+        }
         // We can suggest using an inclusive range
         // (`..=`) instead only if it is the `end` that is
         // overflowing and only by 1.
diff --git a/src/test/ui/issues/issue-63364.rs b/src/test/ui/issues/issue-63364.rs
new file mode 100644 (file)
index 0000000..5223267
--- /dev/null
@@ -0,0 +1,10 @@
+fn part(_: u16) -> u32 {
+    1
+}
+
+fn main() {
+    for n in 100_000.. {
+    //~^ ERROR: literal out of range for `u16`
+        let _ = part(n);
+    }
+}
diff --git a/src/test/ui/issues/issue-63364.stderr b/src/test/ui/issues/issue-63364.stderr
new file mode 100644 (file)
index 0000000..60ff318
--- /dev/null
@@ -0,0 +1,10 @@
+error: literal out of range for `u16`
+  --> $DIR/issue-63364.rs:6:14
+   |
+LL |     for n in 100_000.. {
+   |              ^^^^^^^
+   |
+   = note: `#[deny(overflowing_literals)]` on by default
+
+error: aborting due to previous error
+