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

short-circuit-statement misses final ";" #9889

Open
matthiaskrgr opened this issue Nov 20, 2022 · 0 comments
Open

short-circuit-statement misses final ";" #9889

matthiaskrgr opened this issue Nov 20, 2022 · 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

@matthiaskrgr
Copy link
Member

Summary

.

Lint Name

short-circuit-statement

Reproducer

I tried this code:

fn unused_template_func<T>(x: T) {
    let mut i = 0;
    while i < 10 {
        i != 0 || i != 0;
        i += 1;
    }
}

fn main() -> Result<(), u8> {
    Ok(())
}

I saw this happen:
cargo clippy --fix -- -Aclippy::all -Wclippy::short_circuit_statement

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

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

  * 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/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 `;`, found `i`
 --> src/main.rs:4:38
  |
4 |         let _ = if i == 0 { i != 0; }
  |                                      ^ help: add `;` here
5 |         i += 1;
  |         - unexpected token

error: aborting due to previous error

Original diagnostics will follow.

warning: unused variable: `x`
 --> src/main.rs:1:28
  |
1 | fn unused_template_func<T>(x: T) {
  |                            ^ help: if this is intentional, prefix it with an underscore: `_x`
  |
  = note: `#[warn(unused_variables)]` on by default

warning: function `unused_template_func` is never used
 --> src/main.rs:1:4
  |
1 | fn unused_template_func<T>(x: T) {
  |    ^^^^^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(dead_code)]` on by default

warning: boolean short circuit operator in statement may be clearer using an explicit test
 --> src/main.rs:4:9
  |
4 |         i != 0 || i != 0;
  |         ^^^^^^^^^^^^^^^^^ help: replace it with: `if i == 0 { i != 0; }`
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#short_circuit_statement
  = note: requested on the command line with `-W clippy::short-circuit-statement`

warning: unused logical operation that must be used
 --> src/main.rs:4:9
  |
4 |         i != 0 || i != 0;
  |         ^^^^^^^^^^^^^^^^ the logical operation produces a value
  |
  = note: `#[warn(unused_must_use)]` on by default
help: use `let _ = ...` to ignore the resulting value
  |
4 |         let _ = i != 0 || i != 0;
  |         +++++++

I expected to see this happen:

Version

rustc 1.67.0-nightly (c5d82ed7a 2022-11-19)
binary: rustc
commit-hash: c5d82ed7a4ad94a538bb87e5016e7d5ce0bd434b
commit-date: 2022-11-19
host: x86_64-unknown-linux-gnu
release: 1.67.0-nightly
LLVM version: 15.0.4

Additional Labels

No response

@matthiaskrgr matthiaskrgr added 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 labels Nov 20, 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-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

1 participant