Skip to content

Commit

Permalink
Auto merge of #3931 - phansch:3891, r=flip1995
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bors committed Apr 10, 2019
2 parents 3efc3e2 + ab6b949 commit 2278814
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 17 deletions.
4 changes: 3 additions & 1 deletion ci/base-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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!"
Expand Down
29 changes: 13 additions & 16 deletions clippy_lints/src/literal_representation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
});
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions tests/ui/crashes/ice-3891.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
1x;
}
10 changes: 10 additions & 0 deletions tests/ui/crashes/ice-3891.stderr
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 2278814

Please sign in to comment.