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

Automatic fix fails for assert_eq! macros #13806

Open
yourlogarithm opened this issue Dec 10, 2024 · 0 comments
Open

Automatic fix fails for assert_eq! macros #13806

yourlogarithm opened this issue Dec 10, 2024 · 0 comments
Labels
C-bug Category: Clippy is not doing the correct thing I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied

Comments

@yourlogarithm
Copy link

yourlogarithm commented Dec 10, 2024

Summary

When running cargo clippy --fix on the provided test module, cargo writes an additional assert_eq! statement like this
assert_eq!assert_eq!(, leading to reported errors:

error: expected one of `(`, `[`, or `{`, found `assert_eq`
   --> validator-api/src/main.rs:166:19
    |
166 |         assert_eq!assert_eq!(
    |                   ^^^^^^^^^ expected one of `(`, `[`, or `{`

Reproducer

I tried this code:

#[cfg(test)]
mod test {
    #[tokio::test]
    async fn foo() {
        assert_eq!(2 + 2, 4)
    }
}

I expected to see this happen:

$ cargo clippy --fix --allow-dirty --allow-staged
    Checking validator-api v0.1.0
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 7.04s

Instead, this happened:

$ cargo clippy --fix --allow-dirty --allow-staged
    Checking validator-api v0.1.0
warning: failed to automatically apply fixes suggested by rustc to crate `validator_api`

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

  * validator-api/src/main.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-clippy/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: expected one of `(`, `[`, or `{`, found `assert_eq`
   --> validator-api/src/main.rs:332:19
    |
332 |         assert_eq!assert_eq!(2 + 2, 4)
    |                   ^^^^^^^^^ expected one of `(`, `[`, or `{`

error: aborting due to 1 previous error

Original diagnostics will follow.

warning: unneeded `return` statement
   --> validator-api/src/main.rs:332:19
    |
332 |         assert_eq!(2 + 2, 4)
    |                   ^^^^^^^^^^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_return
    = note: `#[warn(clippy::needless_return)]` on by default
help: remove `return`
    |
332 |         assert_eq!assert_eq!(2 + 2, 4)
    |                   ~~~~~~~~~~~~~~~~~~~~

warning: `validator-api` (bin "validator-api" test) generated 1 warning (run `cargo clippy --fix --bin "validator-api" --tests` to apply 1 suggestion)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 5.94s

Version

rustc 1.83.0-nightly (7608018cb 2024-09-29)
binary: rustc
commit-hash: 7608018cbdac9e55d0d13529cf43adc33d53efcf
commit-date: 2024-09-29
host: x86_64-unknown-linux-gnu
release: 1.83.0-nightly
LLVM version: 19.1.0

Additional Labels

No response

@yourlogarithm yourlogarithm added the C-bug Category: Clippy is not doing the correct thing label Dec 10, 2024
@y21 y21 added the I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied label Dec 10, 2024
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-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied
Projects
None yet
Development

No branches or pull requests

2 participants