Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 51bb1d2

Browse files
committed
Use assoc const NAN for zero_div_zero lint
1 parent 645b62e commit 51bb1d2

File tree

4 files changed

+10
-11
lines changed

4 files changed

+10
-11
lines changed

clippy_lints/src/utils/diagnostics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ pub fn span_lint<T: LintContext>(cx: &T, lint: &'static Lint, sp: impl Into<Mult
6060
/// 6 | let other_f64_nan = 0.0f64 / 0.0;
6161
/// | ^^^^^^^^^^^^
6262
/// |
63-
/// = help: Consider using `std::f64::NAN` if you would like a constant representing NaN
63+
/// = help: Consider using `f64::NAN` if you would like a constant representing NaN
6464
/// ```
6565
pub fn span_lint_and_help<'a, T: LintContext>(cx: &'a T, lint: &'static Lint, span: Span, msg: &str, help: &str) {
6666
cx.struct_span_lint(lint, span, |ldb| {

clippy_lints/src/zero_div_zero.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ use rustc_session::{declare_lint_pass, declare_tool_lint};
88
declare_clippy_lint! {
99
/// **What it does:** Checks for `0.0 / 0.0`.
1010
///
11-
/// **Why is this bad?** It's less readable than `std::f32::NAN` or
12-
/// `std::f64::NAN`.
11+
/// **Why is this bad?** It's less readable than `f32::NAN` or `f64::NAN`.
1312
///
1413
/// **Known problems:** None.
1514
///
@@ -19,7 +18,7 @@ declare_clippy_lint! {
1918
/// ```
2019
pub ZERO_DIVIDED_BY_ZERO,
2120
complexity,
22-
"usage of `0.0 / 0.0` to obtain NaN instead of `std::f32::NAN` or `std::f64::NAN`"
21+
"usage of `0.0 / 0.0` to obtain NaN instead of `f32::NAN` or `f64::NAN`"
2322
}
2423

2524
declare_lint_pass!(ZeroDiv => [ZERO_DIVIDED_BY_ZERO]);
@@ -38,7 +37,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ZeroDiv {
3837
if Constant::F32(0.0) == lhs_value || Constant::F64(0.0) == lhs_value;
3938
if Constant::F32(0.0) == rhs_value || Constant::F64(0.0) == rhs_value;
4039
then {
41-
// since we're about to suggest a use of std::f32::NaN or std::f64::NaN,
40+
// since we're about to suggest a use of f32::NAN or f64::NAN,
4241
// match the precision of the literals that are given.
4342
let float_type = match (lhs_value, rhs_value) {
4443
(Constant::F64(_), _)
@@ -51,7 +50,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ZeroDiv {
5150
expr.span,
5251
"constant division of `0.0` with `0.0` will always result in NaN",
5352
&format!(
54-
"Consider using `std::{}::NAN` if you would like a constant representing NaN",
53+
"Consider using `{}::NAN` if you would like a constant representing NaN",
5554
float_type,
5655
),
5756
);

src/lintlist/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2526,7 +2526,7 @@ pub static ref ALL_LINTS: Vec<Lint> = vec![
25262526
Lint {
25272527
name: "zero_divided_by_zero",
25282528
group: "complexity",
2529-
desc: "usage of `0.0 / 0.0` to obtain NaN instead of `std::f32::NAN` or `std::f64::NAN`",
2529+
desc: "usage of `0.0 / 0.0` to obtain NaN instead of `f32::NAN` or `f64::NAN`",
25302530
deprecation: None,
25312531
module: "zero_div_zero",
25322532
},

tests/ui/zero_div_zero.stderr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ LL | let nan = 0.0 / 0.0;
1313
| ^^^^^^^^^
1414
|
1515
= note: `-D clippy::zero-divided-by-zero` implied by `-D warnings`
16-
= help: Consider using `std::f64::NAN` if you would like a constant representing NaN
16+
= help: Consider using `f64::NAN` if you would like a constant representing NaN
1717

1818
error: equal expressions as operands to `/`
1919
--> $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
2727
LL | let f64_nan = 0.0 / 0.0f64;
2828
| ^^^^^^^^^^^^
2929
|
30-
= help: Consider using `std::f64::NAN` if you would like a constant representing NaN
30+
= help: Consider using `f64::NAN` if you would like a constant representing NaN
3131

3232
error: equal expressions as operands to `/`
3333
--> $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
4141
LL | let other_f64_nan = 0.0f64 / 0.0;
4242
| ^^^^^^^^^^^^
4343
|
44-
= help: Consider using `std::f64::NAN` if you would like a constant representing NaN
44+
= help: Consider using `f64::NAN` if you would like a constant representing NaN
4545

4646
error: equal expressions as operands to `/`
4747
--> $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
5555
LL | let one_more_f64_nan = 0.0f64 / 0.0f64;
5656
| ^^^^^^^^^^^^^^^
5757
|
58-
= help: Consider using `std::f64::NAN` if you would like a constant representing NaN
58+
= help: Consider using `f64::NAN` if you would like a constant representing NaN
5959

6060
error: aborting due to 8 previous errors
6161

0 commit comments

Comments
 (0)