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

False positive from cmp_owned? #7365

Closed
djc opened this issue Jun 17, 2021 · 0 comments · Fixed by #8807
Closed

False positive from cmp_owned? #7365

djc opened this issue Jun 17, 2021 · 0 comments · Fixed by #8807
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have

Comments

@djc
Copy link
Contributor

djc commented Jun 17, 2021

Lint name:

cmp_owned

I tried this code:

if OrderedFloat::from(dist) < OrderedFloat::from(val.0) {
    val.0 = dist;
}

I expected to see this happen: nothing.

Instead, this happened:

warning: this creates an owned instance just for comparison
  --> vectors/src/generator.rs:59:16
   |
59 |             if OrderedFloat::from(dist) < OrderedFloat::from(val.0) {
   |                ^^^^^^^^^^^^^^^^^^^^^^^^----------------------------
   |                |
   |                help: try: `OrderedFloat::from(val.0) == dist`
   |
   = note: `#[warn(clippy::cmp_owned)]` on by default
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#cmp_owned

First, it's weird that the comparison operator changes from < to ==. Second, the suggestion doesn't even work because OrderedFloat doesn't implement Ord with f32 itself. Third, since OrderedFloat is Copy clippy should probably not warn about creating an owned value of that type anyway.

Meta

  • cargo clippy -V: e.g. clippy 0.1.53 (53cb7b09 2021-06-17)
  • rustc -Vv:
rustc 1.53.0 (53cb7b09b 2021-06-17)
binary: rustc
commit-hash: 53cb7b09b00cbea8754ffb78e7e3cb521cb8af4b
commit-date: 2021-06-17
host: x86_64-apple-darwin
release: 1.53.0
LLVM version: 12.0.1
@djc djc added C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have labels Jun 17, 2021
@bors bors closed this as completed in bf2e631 May 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant