Skip to content

Commit 3156e09

Browse files
committed
Auto merge of #4753 - mikerite:approx-const-20191029, r=flip1995
Simplify approx const truncation check changelog: none
2 parents e2104d1 + 5ce8990 commit 3156e09

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

clippy_lints/src/approx_const.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,11 @@ fn check_known_consts(cx: &LateContext<'_, '_>, e: &Expr, s: symbol::Symbol, mod
9797
fn is_approx_const(constant: f64, value: &str, min_digits: usize) -> bool {
9898
if value.len() <= min_digits {
9999
false
100+
} else if constant.to_string().starts_with(value) {
101+
// The value is a truncated constant
102+
true
100103
} else {
101104
let round_const = format!("{:.*}", value.len() - 2, constant);
102-
103-
let mut trunc_const = constant.to_string();
104-
if trunc_const.len() > value.len() {
105-
trunc_const.truncate(value.len());
106-
}
107-
108-
(value == round_const) || (value == trunc_const)
105+
value == round_const
109106
}
110107
}

0 commit comments

Comments
 (0)