diff options
| author | bors <bors@rust-lang.org> | 2019-04-10 20:57:15 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2019-04-10 20:57:15 +0000 |
| commit | 2278814c8e33573b1c870c65f5fcbe69ea20601d (patch) | |
| tree | eca8b4e44cf4d4025182feab626389b89da39460 | |
| parent | 3efc3e2455f1ebb7f74239c3398bae872ce0549e (diff) | |
| parent | ab6b949224a4704641e7c9d24163b9b99d3b47ea (diff) | |
| download | rust-2278814c8e33573b1c870c65f5fcbe69ea20601d.tar.gz rust-2278814c8e33573b1c870c65f5fcbe69ea20601d.zip | |
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]: https://github.com/laumann/compiletest-rs/issues/169
| -rwxr-xr-x | ci/base-tests.sh | 4 | ||||
| -rw-r--r-- | clippy_lints/src/literal_representation.rs | 29 | ||||
| -rw-r--r-- | tests/ui/crashes/ice-3891.rs | 3 | ||||
| -rw-r--r-- | tests/ui/crashes/ice-3891.stderr | 10 |
4 files changed, 29 insertions, 17 deletions
diff --git a/ci/base-tests.sh b/ci/base-tests.sh index fbb5d1cba48..64214e3be86 100755 --- a/ci/base-tests.sh +++ b/ci/base-tests.sh @@ -59,7 +59,9 @@ rustup override set nightly # avoid loop spam and allow cmds with exit status != 0 set +ex -for file in `find tests | grep "\.rs$"` ; do +# Excluding `ice-3891.rs` because the code triggers a rustc parse error which +# makes rustfmt fail. +for file in `find tests -not -path "tests/ui/crashes/ice-3891.rs" | grep "\.rs$"` ; do rustfmt ${file} --check if [ $? -ne 0 ]; then echo "${file} needs reformatting!" diff --git a/clippy_lints/src/literal_representation.rs b/clippy_lints/src/literal_representation.rs index 5c2ca4b1c93..e97845314f9 100644 --- a/clippy_lints/src/literal_representation.rs +++ b/clippy_lints/src/literal_representation.rs @@ -526,23 +526,20 @@ impl LiteralRepresentation { if let Some(src) = snippet_opt(cx, lit.span); if let Some(firstch) = src.chars().next(); if char::to_digit(firstch, 10).is_some(); + let digit_info = DigitInfo::new(&src, false); + if digit_info.radix == Radix::Decimal; + if let Ok(val) = digit_info.digits + .chars() + .filter(|&c| c != '_') + .collect::<String>() + .parse::<u128>(); + if val >= u128::from(self.threshold); then { - let digit_info = DigitInfo::new(&src, false); - if digit_info.radix == Radix::Decimal { - let val = digit_info.digits - .chars() - .filter(|&c| c != '_') - .collect::<String>() - .parse::<u128>().unwrap(); - if val < u128::from(self.threshold) { - 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); + 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) + }); } } } diff --git a/tests/ui/crashes/ice-3891.rs b/tests/ui/crashes/ice-3891.rs new file mode 100644 index 00000000000..05c5134c845 --- /dev/null +++ b/tests/ui/crashes/ice-3891.rs @@ -0,0 +1,3 @@ +fn main() { + 1x; +} diff --git a/tests/ui/crashes/ice-3891.stderr b/tests/ui/crashes/ice-3891.stderr new file mode 100644 index 00000000000..16aedbd98de --- /dev/null +++ b/tests/ui/crashes/ice-3891.stderr @@ -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 + |
