From 5ce8990885eb09c6cc096c207c39b411aa6ce676 Mon Sep 17 00:00:00 2001 From: Michael Wright Date: Tue, 29 Oct 2019 08:34:05 +0200 Subject: [PATCH] Simplify approx const truncation check --- clippy_lints/src/approx_const.rs | 11 ++++------- 1 file 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 } }