diff options
| author | Michael Wright <mikerite@lavabit.com> | 2019-10-29 08:34:05 +0200 |
|---|---|---|
| committer | Michael Wright <mikerite@lavabit.com> | 2019-10-29 08:34:05 +0200 |
| commit | 5ce8990885eb09c6cc096c207c39b411aa6ce676 (patch) | |
| tree | 460b6d860e22dd44db6dc5961b9d75c84c198b2c | |
| parent | e2104d1e2eec9b22729d4ceb9376fba9ce31ef5a (diff) | |
| download | rust-5ce8990885eb09c6cc096c207c39b411aa6ce676.tar.gz rust-5ce8990885eb09c6cc096c207c39b411aa6ce676.zip | |
Simplify approx const truncation check
| -rw-r--r-- | clippy_lints/src/approx_const.rs | 11 |
1 files changed, 4 insertions, 7 deletions
diff --git a/clippy_lints/src/approx_const.rs b/clippy_lints/src/approx_const.rs index 04530542ef8..81555a4c533 100644 --- a/clippy_lints/src/approx_const.rs +++ b/clippy_lints/src/approx_const.rs @@ -97,14 +97,11 @@ fn check_known_consts(cx: &LateContext<'_, '_>, e: &Expr, s: symbol::Symbol, mod fn is_approx_const(constant: f64, value: &str, min_digits: usize) -> bool { if value.len() <= min_digits { false + } else if constant.to_string().starts_with(value) { + // The value is a truncated constant + true } else { let round_const = format!("{:.*}", value.len() - 2, constant); - - let mut trunc_const = constant.to_string(); - if trunc_const.len() > value.len() { - trunc_const.truncate(value.len()); - } - - (value == round_const) || (value == trunc_const) + value == round_const } } |
