From 51bb1d28c510b6833066561a2b5709e21b172c5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Linus=20F=C3=A4rnstrand?= Date: Tue, 7 Apr 2020 23:41:00 +0200 Subject: [PATCH] Use assoc const NAN for zero_div_zero lint --- clippy_lints/src/utils/diagnostics.rs | 2 +- clippy_lints/src/zero_div_zero.rs | 9 ++++----- src/lintlist/mod.rs | 2 +- tests/ui/zero_div_zero.stderr | 8 ++++---- 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/clippy_lints/src/utils/diagnostics.rs b/clippy_lints/src/utils/diagnostics.rs index cc519d52552..409bb2043d4 100644 --- a/clippy_lints/src/utils/diagnostics.rs +++ b/clippy_lints/src/utils/diagnostics.rs @@ -60,7 +60,7 @@ pub fn span_lint(cx: &T, lint: &'static Lint, sp: impl Into(cx: &'a T, lint: &'static Lint, span: Span, msg: &str, help: &str) { cx.struct_span_lint(lint, span, |ldb| { diff --git a/clippy_lints/src/zero_div_zero.rs b/clippy_lints/src/zero_div_zero.rs index 42cb9a77db0..afd10d9ed53 100644 --- a/clippy_lints/src/zero_div_zero.rs +++ b/clippy_lints/src/zero_div_zero.rs @@ -8,8 +8,7 @@ use rustc_session::{declare_lint_pass, declare_tool_lint}; declare_clippy_lint! { /// **What it does:** Checks for `0.0 / 0.0`. /// - /// **Why is this bad?** It's less readable than `std::f32::NAN` or - /// `std::f64::NAN`. + /// **Why is this bad?** It's less readable than `f32::NAN` or `f64::NAN`. /// /// **Known problems:** None. /// @@ -19,7 +18,7 @@ declare_clippy_lint! { /// ``` pub ZERO_DIVIDED_BY_ZERO, complexity, - "usage of `0.0 / 0.0` to obtain NaN instead of `std::f32::NAN` or `std::f64::NAN`" + "usage of `0.0 / 0.0` to obtain NaN instead of `f32::NAN` or `f64::NAN`" } declare_lint_pass!(ZeroDiv => [ZERO_DIVIDED_BY_ZERO]); @@ -38,7 +37,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ZeroDiv { if Constant::F32(0.0) == lhs_value || Constant::F64(0.0) == lhs_value; if Constant::F32(0.0) == rhs_value || Constant::F64(0.0) == rhs_value; then { - // since we're about to suggest a use of std::f32::NaN or std::f64::NaN, + // since we're about to suggest a use of f32::NAN or f64::NAN, // match the precision of the literals that are given. let float_type = match (lhs_value, rhs_value) { (Constant::F64(_), _) @@ -51,7 +50,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ZeroDiv { expr.span, "constant division of `0.0` with `0.0` will always result in NaN", &format!( - "Consider using `std::{}::NAN` if you would like a constant representing NaN", + "Consider using `{}::NAN` if you would like a constant representing NaN", float_type, ), ); diff --git a/src/lintlist/mod.rs b/src/lintlist/mod.rs index 8a6d0af5f8a..0e5757fe588 100644 --- a/src/lintlist/mod.rs +++ b/src/lintlist/mod.rs @@ -2526,7 +2526,7 @@ pub static ref ALL_LINTS: Vec = vec![ Lint { name: "zero_divided_by_zero", group: "complexity", - desc: "usage of `0.0 / 0.0` to obtain NaN instead of `std::f32::NAN` or `std::f64::NAN`", + desc: "usage of `0.0 / 0.0` to obtain NaN instead of `f32::NAN` or `f64::NAN`", deprecation: None, module: "zero_div_zero", }, diff --git a/tests/ui/zero_div_zero.stderr b/tests/ui/zero_div_zero.stderr index e4d6f168038..d0e88f3c5a5 100644 --- a/tests/ui/zero_div_zero.stderr +++ b/tests/ui/zero_div_zero.stderr @@ -13,7 +13,7 @@ LL | let nan = 0.0 / 0.0; | ^^^^^^^^^ | = note: `-D clippy::zero-divided-by-zero` implied by `-D warnings` - = help: Consider using `std::f64::NAN` if you would like a constant representing NaN + = help: Consider using `f64::NAN` if you would like a constant representing NaN error: equal expressions as operands to `/` --> $DIR/zero_div_zero.rs:5:19 @@ -27,7 +27,7 @@ error: constant division of `0.0` with `0.0` will always result in NaN LL | let f64_nan = 0.0 / 0.0f64; | ^^^^^^^^^^^^ | - = help: Consider using `std::f64::NAN` if you would like a constant representing NaN + = help: Consider using `f64::NAN` if you would like a constant representing NaN error: equal expressions as operands to `/` --> $DIR/zero_div_zero.rs:6:25 @@ -41,7 +41,7 @@ error: constant division of `0.0` with `0.0` will always result in NaN LL | let other_f64_nan = 0.0f64 / 0.0; | ^^^^^^^^^^^^ | - = help: Consider using `std::f64::NAN` if you would like a constant representing NaN + = help: Consider using `f64::NAN` if you would like a constant representing NaN error: equal expressions as operands to `/` --> $DIR/zero_div_zero.rs:7:28 @@ -55,7 +55,7 @@ error: constant division of `0.0` with `0.0` will always result in NaN LL | let one_more_f64_nan = 0.0f64 / 0.0f64; | ^^^^^^^^^^^^^^^ | - = help: Consider using `std::f64::NAN` if you would like a constant representing NaN + = help: Consider using `f64::NAN` if you would like a constant representing NaN error: aborting due to 8 previous errors