Prevent symbocalypse
This commit is contained in:
@@ -1,13 +1,10 @@
|
||||
use crate::utils::span_lint;
|
||||
use crate::utils::sym;
|
||||
use lazy_static::lazy_static;
|
||||
use rustc::hir::*;
|
||||
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
|
||||
use rustc::{declare_lint_pass, declare_tool_lint};
|
||||
use std::f64::consts as f64;
|
||||
use syntax::ast::{FloatTy, LitKind};
|
||||
use syntax::symbol;
|
||||
use syntax::symbol::Symbol;
|
||||
|
||||
declare_clippy_lint! {
|
||||
/// **What it does:** Checks for floating point literals that approximate
|
||||
@@ -33,27 +30,25 @@ declare_clippy_lint! {
|
||||
"the approximate of a known float constant (in `std::fXX::consts`)"
|
||||
}
|
||||
|
||||
lazy_static! {
|
||||
// Tuples are of the form (constant, name, min_digits)
|
||||
static ref KNOWN_CONSTS: [(f64, Symbol, usize); 16] = [
|
||||
(f64::E, *sym::E, 4),
|
||||
(f64::FRAC_1_PI, *sym::FRAC_1_PI, 4),
|
||||
(f64::FRAC_1_SQRT_2, *sym::FRAC_1_SQRT_2, 5),
|
||||
(f64::FRAC_2_PI, *sym::FRAC_2_PI, 5),
|
||||
(f64::FRAC_2_SQRT_PI, *sym::FRAC_2_SQRT_PI, 5),
|
||||
(f64::FRAC_PI_2, *sym::FRAC_PI_2, 5),
|
||||
(f64::FRAC_PI_3, *sym::FRAC_PI_3, 5),
|
||||
(f64::FRAC_PI_4, *sym::FRAC_PI_4, 5),
|
||||
(f64::FRAC_PI_6, *sym::FRAC_PI_6, 5),
|
||||
(f64::FRAC_PI_8, *sym::FRAC_PI_8, 5),
|
||||
(f64::LN_10, *sym::LN_10, 5),
|
||||
(f64::LN_2, *sym::LN_2, 5),
|
||||
(f64::LOG10_E, *sym::LOG10_E, 5),
|
||||
(f64::LOG2_E, *sym::LOG2_E, 5),
|
||||
(f64::PI, *sym::PI, 3),
|
||||
(f64::SQRT_2, *sym::SQRT_2, 5),
|
||||
const KNOWN_CONSTS: [(f64, &str, usize); 16] = [
|
||||
(f64::E, "E", 4),
|
||||
(f64::FRAC_1_PI, "FRAC_1_PI", 4),
|
||||
(f64::FRAC_1_SQRT_2, "FRAC_1_SQRT_2", 5),
|
||||
(f64::FRAC_2_PI, "FRAC_2_PI", 5),
|
||||
(f64::FRAC_2_SQRT_PI, "FRAC_2_SQRT_PI", 5),
|
||||
(f64::FRAC_PI_2, "FRAC_PI_2", 5),
|
||||
(f64::FRAC_PI_3, "FRAC_PI_3", 5),
|
||||
(f64::FRAC_PI_4, "FRAC_PI_4", 5),
|
||||
(f64::FRAC_PI_6, "FRAC_PI_6", 5),
|
||||
(f64::FRAC_PI_8, "FRAC_PI_8", 5),
|
||||
(f64::LN_10, "LN_10", 5),
|
||||
(f64::LN_2, "LN_2", 5),
|
||||
(f64::LOG10_E, "LOG10_E", 5),
|
||||
(f64::LOG2_E, "LOG2_E", 5),
|
||||
(f64::PI, "PI", 3),
|
||||
(f64::SQRT_2, "SQRT_2", 5),
|
||||
];
|
||||
}
|
||||
|
||||
declare_lint_pass!(ApproxConstant => [APPROX_CONSTANT]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user