mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-29 02:03:53 +00:00
Auto merge of #4753 - mikerite:approx-const-20191029, r=flip1995
Simplify approx const truncation check changelog: none
This commit is contained in:
commit
3156e0957f
@ -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
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user