Keep original literal notation in suggestion

This commit is contained in:
koka 2022-11-18 21:23:16 +09:00
parent dfe37f13cf
commit 921f4d317e
No known key found for this signature in database
GPG Key ID: A5917A40697774CD
4 changed files with 18 additions and 2 deletions

View File

@ -36,7 +36,7 @@ fn is_useless_rounding(expr: &Expr) -> Option<(&str, String)> {
&& let ExprKind::Lit(spanned) = &receiver.kind
&& let LitKind::Float(symbol, ty) = spanned.kind {
let f = symbol.as_str().parse::<f64>().unwrap();
let f_str = symbol.to_string() + if let LitFloatType::Suffixed(ty) = ty {
let f_str = spanned.token_lit.symbol.to_string() + if let LitFloatType::Suffixed(ty) = ty {
ty.name_str()
} else {
""

View File

@ -6,4 +6,9 @@ fn main() {
let _ = 1.0f64;
let _ = 1.00f32;
let _ = 2e-54f64.floor();
// issue9866
let _ = 3.3_f32.round();
let _ = 3.3_f64.round();
let _ = 3.0_f32;
}

View File

@ -6,4 +6,9 @@ fn main() {
let _ = 1.0f64.floor();
let _ = 1.00f32.round();
let _ = 2e-54f64.floor();
// issue9866
let _ = 3.3_f32.round();
let _ = 3.3_f64.round();
let _ = 3.0_f32.round();
}

View File

@ -18,5 +18,11 @@ error: used the `round` method with a whole number float
LL | let _ = 1.00f32.round();
| ^^^^^^^^^^^^^^^ help: remove the `round` method call: `1.00f32`
error: aborting due to 3 previous errors
error: used the `round` method with a whole number float
--> $DIR/unused_rounding.rs:13:13
|
LL | let _ = 3.0_f32.round();
| ^^^^^^^^^^^^^^^ help: remove the `round` method call: `3.0_f32`
error: aborting due to 4 previous errors