mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-21 11:23:03 +00:00
Use assoc const NAN for zero_div_zero lint
This commit is contained in:
parent
645b62e436
commit
51bb1d28c5
@ -60,7 +60,7 @@ pub fn span_lint<T: LintContext>(cx: &T, lint: &'static Lint, sp: impl Into<Mult
|
||||
/// 6 | 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
|
||||
/// ```
|
||||
pub fn span_lint_and_help<'a, T: LintContext>(cx: &'a T, lint: &'static Lint, span: Span, msg: &str, help: &str) {
|
||||
cx.struct_span_lint(lint, span, |ldb| {
|
||||
|
@ -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,
|
||||
),
|
||||
);
|
||||
|
@ -2526,7 +2526,7 @@ pub static ref ALL_LINTS: Vec<Lint> = 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",
|
||||
},
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user