Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

float_cmp changes #11948

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6045,6 +6045,9 @@ Released 2018-09-13
[`enum-variant-name-threshold`]: https://doc.rust-lang.org/clippy/lint_configuration.html#enum-variant-name-threshold
[`enum-variant-size-threshold`]: https://doc.rust-lang.org/clippy/lint_configuration.html#enum-variant-size-threshold
[`excessive-nesting-threshold`]: https://doc.rust-lang.org/clippy/lint_configuration.html#excessive-nesting-threshold
[`float-cmp-allowed-constants`]: https://doc.rust-lang.org/clippy/lint_configuration.html#float-cmp-allowed-constants
[`float-cmp-ignore-change-detection`]: https://doc.rust-lang.org/clippy/lint_configuration.html#float-cmp-ignore-change-detection
[`float-cmp-ignore-constant-comparisons`]: https://doc.rust-lang.org/clippy/lint_configuration.html#float-cmp-ignore-constant-comparisons
[`future-size-threshold`]: https://doc.rust-lang.org/clippy/lint_configuration.html#future-size-threshold
[`ignore-interior-mutability`]: https://doc.rust-lang.org/clippy/lint_configuration.html#ignore-interior-mutability
[`large-error-threshold`]: https://doc.rust-lang.org/clippy/lint_configuration.html#large-error-threshold
Expand Down
53 changes: 53 additions & 0 deletions book/src/lint_configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,59 @@ The maximum amount of nesting a block can reside in
* [`excessive_nesting`](https://rust-lang.github.io/rust-clippy/master/index.html#excessive_nesting)


## `float-cmp-allowed-constants`
#### Example
```no_run
const VALUE: f64 = 1.0;
fn is_value(x: f64) -> bool {
// Will warn unless `crate_name::VALUE` is allowed
x == VALUE
}
```

**Default Value:** `[]`

---
**Affected lints:**
* [`float_cmp`](https://rust-lang.github.io/rust-clippy/master/index.html#float_cmp)


## `float-cmp-ignore-change-detection`
#### Example
```no_run
fn f(x: f64) -> bool {
// Will warn if the config is `false`
x == x + 1.0
}
```

**Default Value:** `true`

---
**Affected lints:**
* [`float_cmp`](https://rust-lang.github.io/rust-clippy/master/index.html#float_cmp)


## `float-cmp-ignore-constant-comparisons`
#### Example
```no_run
const fn f(x: f64) -> f64 {
todo!()
}

// Will warn if the config is `false`
if f(1.0) == f(2.0) {
// ...
}
```

**Default Value:** `true`

---
**Affected lints:**
* [`float_cmp`](https://rust-lang.github.io/rust-clippy/master/index.html#float_cmp)


## `future-size-threshold`
The maximum byte size a `Future` can have, before it triggers the `clippy::large_futures` lint

Expand Down
41 changes: 41 additions & 0 deletions clippy_config/src/conf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,47 @@ define_Conf! {
///
/// Whether to also emit warnings for unsafe blocks with metavariable expansions in **private** macros.
(warn_unsafe_macro_metavars_in_private_macros: bool = false),
/// Lint: FLOAT_CMP
///
/// The list of constants which can be checked for exact equality.
///
/// #### Example
/// ```no_run
/// const VALUE: f64 = 1.0;
/// fn is_value(x: f64) -> bool {
/// // Will warn unless `crate_name::VALUE` is allowed
/// x == VALUE
/// }
/// ```
(float_cmp_allowed_constants: Vec<String> = Vec::new()),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest adding "*" as a magic value that says that all constants are allowed. THis should also be documented.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be better done in a more uniform way across all the multi-value configs.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While true, I'm not sure how many lints would benefit from an everything "*" configuration. #12571 comes to mind, where I also suggested this with a Zulip thread.

/// Lint: FLOAT_CMP
///
/// Whether to ignore comparisons which have a constant result.
///
/// #### Example
/// ```no_run
/// const fn f(x: f64) -> f64 {
/// todo!()
/// }
///
/// // Will warn if the config is `false`
/// if f(1.0) == f(2.0) {
/// // ...
/// }
/// ```
(float_cmp_ignore_constant_comparisons: bool = true),
/// Lint: FLOAT_CMP
///
/// Whether to ignore comparisons which check if an operation changes the value of it's operand.
///
/// #### Example
/// ```no_run
/// fn f(x: f64) -> bool {
/// // Will warn if the config is `false`
/// x == x + 1.0
/// }
/// ```
(float_cmp_ignore_change_detection: bool = true),
}

/// Search for the configuration file.
Expand Down
1 change: 0 additions & 1 deletion clippy_lints/src/declared_lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,6 @@ pub(crate) static LINTS: &[&crate::LintInfo] = &[
crate::operators::ERASING_OP_INFO,
crate::operators::FLOAT_ARITHMETIC_INFO,
crate::operators::FLOAT_CMP_INFO,
crate::operators::FLOAT_CMP_CONST_INFO,
crate::operators::FLOAT_EQUALITY_WITHOUT_ABS_INFO,
crate::operators::IDENTITY_OP_INFO,
crate::operators::IMPOSSIBLE_COMPARISONS_INFO,
Expand Down
11 changes: 11 additions & 0 deletions clippy_lints/src/deprecated_lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,3 +241,14 @@ declare_deprecated_lint! {
pub MISMATCHED_TARGET_OS,
"this lint has been replaced by `unexpected_cfgs`"
}

declare_deprecated_lint! {
/// ### What it does
/// Nothing. This lint has been deprecated.
///
/// ### Deprecation reason
/// `float_cmp` handles this via config options
#[clippy::version = "1.76.0"]
pub FLOAT_CMP_CONST,
"`float_cmp` handles this via config options"
}
4 changes: 4 additions & 0 deletions clippy_lints/src/lib.deprecated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,8 @@
"clippy::mismatched_target_os",
"this lint has been replaced by `unexpected_cfgs`",
);
store.register_removed(
"clippy::float_cmp_const",
"`float_cmp` handles this via config options",
);
}
2 changes: 1 addition & 1 deletion clippy_lints/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -816,7 +816,7 @@ pub fn register_lints(store: &mut rustc_lint::LintStore, conf: &'static Conf) {
store.register_late_pass(move |_| Box::new(manual_rem_euclid::ManualRemEuclid::new(conf)));
store.register_late_pass(move |_| Box::new(manual_retain::ManualRetain::new(conf)));
store.register_late_pass(move |_| Box::new(manual_rotate::ManualRotate));
store.register_late_pass(move |_| Box::new(operators::Operators::new(conf)));
store.register_late_pass(move |tcx| Box::new(operators::Operators::new(tcx, conf)));
store.register_late_pass(|_| Box::<std_instead_of_core::StdReexports>::default());
store.register_late_pass(move |_| Box::new(instant_subtraction::InstantSubtraction::new(conf)));
store.register_late_pass(|_| Box::new(partialeq_to_none::PartialeqToNone));
Expand Down
Loading
Loading