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]: https://github.com/laumann/compiletest-rs/issues/169
This commit is contained in:
parent
949f58440b
commit
0307ff020c
3 changed files with 26 additions and 9 deletions
|
@ -529,19 +529,23 @@ impl LiteralRepresentation {
|
||||||
then {
|
then {
|
||||||
let digit_info = DigitInfo::new(&src, false);
|
let digit_info = DigitInfo::new(&src, false);
|
||||||
if digit_info.radix == Radix::Decimal {
|
if digit_info.radix == Radix::Decimal {
|
||||||
let val = digit_info.digits
|
if let Ok(val) = digit_info.digits
|
||||||
.chars()
|
.chars()
|
||||||
.filter(|&c| c != '_')
|
.filter(|&c| c != '_')
|
||||||
.collect::<String>()
|
.collect::<String>()
|
||||||
.parse::<u128>().unwrap();
|
.parse::<u128>() {
|
||||||
if val < u128::from(self.threshold) {
|
if val < u128::from(self.threshold) {
|
||||||
return
|
return
|
||||||
|
}
|
||||||
|
let hex = format!("{:#X}", val);
|
||||||
|
let digit_info = DigitInfo::new(&hex[..], false);
|
||||||
|
let _ = Self::do_lint(digit_info.digits).map_err(|warning_type| {
|
||||||
|
warning_type.display(&digit_info.grouping_hint(), cx, lit.span)
|
||||||
|
});
|
||||||
}
|
}
|
||||||
let hex = format!("{:#X}", val);
|
else {
|
||||||
let digit_info = DigitInfo::new(&hex[..], false);
|
return
|
||||||
let _ = Self::do_lint(digit_info.digits).map_err(|warning_type| {
|
};
|
||||||
warning_type.display(&digit_info.grouping_hint(), cx, lit.span)
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
3
tests/ui/crashes/ice-3891.rs
Normal file
3
tests/ui/crashes/ice-3891.rs
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
fn main() {
|
||||||
|
1x;
|
||||||
|
}
|
10
tests/ui/crashes/ice-3891.stderr
Normal file
10
tests/ui/crashes/ice-3891.stderr
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
error: invalid suffix `x` for numeric literal
|
||||||
|
--> $DIR/ice-3891.rs:2:5
|
||||||
|
|
|
||||||
|
LL | 1x;
|
||||||
|
| ^^ invalid suffix `x`
|
||||||
|
|
|
||||||
|
= help: the suffix must be one of the integral types (`u32`, `isize`, etc)
|
||||||
|
|
||||||
|
error: aborting due to previous error
|
||||||
|
|
Loading…
Add table
Reference in a new issue