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

Compile error after applying clippy::identity_op #13924

Open
dhedey opened this issue Jan 1, 2025 · 1 comment
Open

Compile error after applying clippy::identity_op #13924

dhedey opened this issue Jan 1, 2025 · 1 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

Comments

@dhedey
Copy link

dhedey commented Jan 1, 2025

Summary

I was writing tests for preinterpet on this draft PR and encountered the following error after running clippy:

after fixes were automatically applied the compiler reported errors
...
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!
...
clippy::identity_op

The code

The code which tripped up clippy was a little artificial, as it was a test case for building partial expressions from token streams inside macros. In particular, it was the following code:

    assert_preinterpret_eq!({
        0
        [!if! true { + 1 }]
    }, 1);

The full error

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

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

  * tests/control_flow.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: mismatched closing delimiter: `]`
  --> tests/control_flow.rs:21:28
   |
21 |     assert_preinterpret_eq!({
   |                            ^ unclosed delimiter
22 |         1 }]
   |            ^ mismatched closing delimiter

error: unexpected closing delimiter: `)`
  --> tests/control_flow.rs:23:9
   |
22 |         1 }]
   |            - missing open `[` for this delimiter
23 |     }, 1);
   |         ^ unexpected closing delimiter

error: aborting due to 2 previous errors

Original diagnostics will follow.

warning: this operation has no effect
  --> tests/control_flow.rs:22:9
   |
22 | /         0
23 | |         [!if! true { + 1 }]
   | |________________________^ help: consider reducing it to: `1`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#identity_op
   = note: `#[warn(clippy::identity_op)]` on by default

warning: `preinterpret` (test "control_flow") generated 1 warning (run `cargo clippy --fix --test "control_flow"` to apply 1 suggestion)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 1.43s

Reproducer

I tried this code:

    assert_preinterpret_eq!({
        0
        [!if! true { + 1 }]
    }, 1);

Where the assert_preinterpret_eq! macro was defined as:

macro_rules! assert_preinterpret_eq {
    ($input:tt, $($output:tt)*) => {
        assert_eq!(preinterpret!($input), $($output)*);
    };
}

In this WIP branch in this repo.

You can probably substitute the following to reproduce the issue, without using preinterpret:

macro_rules! assert_preinterpret_eq {
    ($($output:tt)*) => {};
}

I expected to see this happen: Clippy ignored it

Instead, this happened: Clippy attempted to fix it and got a compile error.

Version

rustc 1.81.0 (eeb90cda1 2024-09-04)
binary: rustc
commit-hash: eeb90cda1969383f56a2637cbd3037bdf598841c
commit-date: 2024-09-04
host: aarch64-apple-darwin
release: 1.81.0
LLVM version: 18.1.7

Additional Labels

@rustbot label +l-suggestion-causes-error

@dhedey dhedey added the C-bug Category: Clippy is not doing the correct thing label Jan 1, 2025
@rustbot
Copy link
Collaborator

rustbot commented Jan 1, 2025

Error: Label l-suggestion-causes-error can only be set by Rust team members

Please file an issue on GitHub at triagebot if there's a problem with this bot, or reach out on #t-infra on Zulip.

@samueltardieu samueltardieu added the I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied label Jan 1, 2025
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

3 participants