Return early to avoid failing assertion

This commit is contained in:
Yuki Okushi 2019-08-08 13:38:23 +09:00
parent 476af31d59
commit e2b3543eab
3 changed files with 23 additions and 1 deletions

View 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.

View file

@ -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);
}
}

View file

@ -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