Auto merge of #10952 - Centri3:excessive_precision, r=dswij
Don't lint `excessive_precision` on inf Fixes #9910 changelog: [`excessive_precision`]: No longer lints overflowing literals
This commit is contained in:
commit
62972ae2dd
7 changed files with 70 additions and 31 deletions
|
|
@ -82,19 +82,24 @@ impl<'tcx> LateLintPass<'tcx> for FloatLiteral {
|
|||
LitFloatType::Suffixed(ast::FloatTy::F64) => Some("f64"),
|
||||
LitFloatType::Unsuffixed => None
|
||||
};
|
||||
let (is_whole, mut float_str) = match fty {
|
||||
let (is_whole, is_inf, mut float_str) = match fty {
|
||||
FloatTy::F32 => {
|
||||
let value = sym_str.parse::<f32>().unwrap();
|
||||
|
||||
(value.fract() == 0.0, formatter.format(value))
|
||||
(value.fract() == 0.0, value.is_infinite(), formatter.format(value))
|
||||
},
|
||||
FloatTy::F64 => {
|
||||
let value = sym_str.parse::<f64>().unwrap();
|
||||
|
||||
(value.fract() == 0.0, formatter.format(value))
|
||||
|
||||
(value.fract() == 0.0, value.is_infinite(), formatter.format(value))
|
||||
},
|
||||
};
|
||||
|
||||
if is_inf {
|
||||
return;
|
||||
}
|
||||
|
||||
if is_whole && !sym_str.contains(|c| c == 'e' || c == 'E') {
|
||||
// Normalize the literal by stripping the fractional portion
|
||||
if sym_str.split('.').next().unwrap() != float_str {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue