rust-lang / rust-lang/rust-clippy

Compiler error created by running clippy fix on floating point expression upgrading to 1.66

Open
#10,092 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug I-false-positive I-suggestion-causes-error
Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

Description

I got linked here after running clippy fix upgrading our codebase to 1.66.

cargo clippy --all-features --tests --fix

I tried this code:

warning: failed to automatically apply fixes suggested by rustc to crate `foo`

after fixes were automatically applied the compiler reported errors within these files:

  * crates/foo/src/bar.rs

This likely indicates a bug in either rustc or cargo itself,
and we would appreciate a bug report! You're likely to see
a number of compiler warnings after this message which cargo
attempted to fix but failed. If you could open an issue at
https://github.com/rust-lang/rust/issues
quoting the full output of this command we'd be very appreciative!
Note that you may be able to make some more progress in the near-term
fixing code with the `--broken-code` flag

The following errors were reported:
error[E0689]: can't call method `ln` on ambiguous numeric type `{float}`
   --> crates/foo/src/bar.rs:163:51
    |
163 |         let foo = 1.0 * (1.0 / (1.0 / 7.0)).ln();
    |                                                   ^^

error: aborting due to previous error

For more information about this error, try `rustc --explain E0689`.
Original diagnostics will follow.

warning: casting to the same type is unnecessary (`f64` -> `f64`)
   --> crates/algo/src/categorical_relative_entropy.rs:163:30
    |
163 |         let foo = 1.0 * ((1.0 / (1.0 / 7.0)) as f64).ln();
    |                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `(1.0 / (1.0 / 7.0))`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_cast
    = note: `#[warn(clippy::unnecessary_cast)]` on by default

Like the output says afterward, there are a bunch of fixes that do not get applied.

For example formatting strings.

    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args
help: change this to
435 -         println!("foo={:?}", foo);
435 +         println!("foo={foo:?}");

And some warnings for elided lifetimes.

warning: the following explicit lifetimes could be elided: 'a
   --> crates/foo/src/bar/mod.rs:258:5
    |
258 | /     fn baz<'a, 'b>(
259 | |         &'a mut self,
260 | |         batch: &'b Foo,
261 | |     ) -> anyhow::Result<Bar<'b>> {
    | |_________________________________________^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes`

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing cargo clippy --all-features --tests --fix with the floating-point expression and diagnostics shown in the issue, then inspect the reported paths crates/foo/src/bar.rs and crates/algo/src/categorical_relative_entropy.rs. Done means clippy fixes no longer leave compiler errors and the reported fixes are applied successfully.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.