Skip to content

Commit 2278814

Browse files
committed
Auto merge of #3931 - phansch:3891, r=flip1995
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. Fixes #3891 [compiletest_issue]: Manishearth/compiletest-rs#169
2 parents 3efc3e2 + ab6b949 commit 2278814

File tree

4 files changed

+29
-17
lines changed

4 files changed

+29
-17
lines changed

ci/base-tests.sh

+3-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ rustup override set nightly
5959
# avoid loop spam and allow cmds with exit status != 0
6060
set +ex
6161

62-
for file in `find tests | grep "\.rs$"` ; do
62+
# Excluding `ice-3891.rs` because the code triggers a rustc parse error which
63+
# makes rustfmt fail.
64+
for file in `find tests -not -path "tests/ui/crashes/ice-3891.rs" | grep "\.rs$"` ; do
6365
rustfmt ${file} --check
6466
if [ $? -ne 0 ]; then
6567
echo "${file} needs reformatting!"

clippy_lints/src/literal_representation.rs

+13-16
Original file line numberDiff line numberDiff line change
@@ -526,23 +526,20 @@ impl LiteralRepresentation {
526526
if let Some(src) = snippet_opt(cx, lit.span);
527527
if let Some(firstch) = src.chars().next();
528528
if char::to_digit(firstch, 10).is_some();
529+
let digit_info = DigitInfo::new(&src, false);
530+
if digit_info.radix == Radix::Decimal;
531+
if let Ok(val) = digit_info.digits
532+
.chars()
533+
.filter(|&c| c != '_')
534+
.collect::<String>()
535+
.parse::<u128>();
536+
if val >= u128::from(self.threshold);
529537
then {
530-
let digit_info = DigitInfo::new(&src, false);
531-
if digit_info.radix == Radix::Decimal {
532-
let val = digit_info.digits
533-
.chars()
534-
.filter(|&c| c != '_')
535-
.collect::<String>()
536-
.parse::<u128>().unwrap();
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-
});
545-
}
538+
let hex = format!("{:#X}", val);
539+
let digit_info = DigitInfo::new(&hex, false);
540+
let _ = Self::do_lint(digit_info.digits).map_err(|warning_type| {
541+
warning_type.display(&digit_info.grouping_hint(), cx, lit.span)
542+
});
546543
}
547544
}
548545
}

tests/ui/crashes/ice-3891.rs

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fn main() {
2+
1x;
3+
}

tests/ui/crashes/ice-3891.stderr

+10
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)