Skip to content

Commit 0307ff0

Browse files
committed
Fix ICE in decimal_literal_representation lint
Handling the integer parsing properly instead of just unwrapping. Note that the test is not catching the ICE because plain UI tests [currently hide ICEs][compiletest_issue]. Once that issue is fixed, this test would fail properly again. [compiletest_issue]: Manishearth/compiletest-rs#169
1 parent 949f584 commit 0307ff0

File tree

3 files changed

+26
-9
lines changed

3 files changed

+26
-9
lines changed

clippy_lints/src/literal_representation.rs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -529,19 +529,23 @@ impl LiteralRepresentation {
529529
then {
530530
let digit_info = DigitInfo::new(&src, false);
531531
if digit_info.radix == Radix::Decimal {
532-
let val = digit_info.digits
532+
if let Ok(val) = digit_info.digits
533533
.chars()
534534
.filter(|&c| c != '_')
535535
.collect::<String>()
536-
.parse::<u128>().unwrap();
537-
if val < u128::from(self.threshold) {
538-
return
536+
.parse::<u128>() {
537+
if val < u128::from(self.threshold) {
538+
return
539+
}
540+
let hex = format!("{:#X}", val);
541+
let digit_info = DigitInfo::new(&hex[..], false);
542+
let _ = Self::do_lint(digit_info.digits).map_err(|warning_type| {
543+
warning_type.display(&digit_info.grouping_hint(), cx, lit.span)
544+
});
539545
}
540-
let hex = format!("{:#X}", val);
541-
let digit_info = DigitInfo::new(&hex[..], false);
542-
let _ = Self::do_lint(digit_info.digits).map_err(|warning_type| {
543-
warning_type.display(&digit_info.grouping_hint(), cx, lit.span)
544-
});
546+
else {
547+
return
548+
};
545549
}
546550
}
547551
}

tests/ui/crashes/ice-3891.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fn main() {
2+
1x;
3+
}

tests/ui/crashes/ice-3891.stderr

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
error: invalid suffix `x` for numeric literal
2+
--> $DIR/ice-3891.rs:2:5
3+
|
4+
LL | 1x;
5+
| ^^ invalid suffix `x`
6+
|
7+
= help: the suffix must be one of the integral types (`u32`, `isize`, etc)
8+
9+
error: aborting due to previous error
10+

0 commit comments

Comments
 (0)