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

FP bool_to_int_with_if if let #9897

Closed
matthiaskrgr opened this issue Nov 20, 2022 · 3 comments
Closed

FP bool_to_int_with_if if let #9897

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

bool_to_int_with_if

Reproducer

I tried this code:

fn main() {}
const _: i32 = if let Some(true) = Some(false) { 0 } else { 1 };

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

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 expression, found `let` statement
 --> src/main.rs:2:28
  |
2 | const _: i32 = i32::from(!(let Some(true) = Some(false)));
  |                            ^^^

error: `let` expressions are not supported here
 --> src/main.rs:2:28
  |
2 | const _: i32 = i32::from(!(let Some(true) = Some(false)));
  |                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: only supported directly in conditions of `if` and `while` expressions
note: `let`s wrapped in parentheses are not supported in a context with let chains
 --> src/main.rs:2:28
  |
2 | const _: i32 = i32::from(!(let Some(true) = Some(false)));
  |                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error[E0658]: `let` expressions in this position are unstable
 --> src/main.rs:2:28
  |
2 | const _: i32 = i32::from(!(let Some(true) = Some(false)));
  |                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: see issue #53667 <https://github.com/rust-lang/rust/issues/53667> for more information
  = help: add `#![feature(let_chains)]` to the crate attributes to enable

error: aborting due to 3 previous errors

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

warning: boolean to int conversion using if
 --> src/main.rs:2:16
  |
2 | const _: i32 = if let Some(true) = Some(false) { 0 } else { 1 };
  |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with from: `i32::from(!(let Some(true) = Some(false)))`
  |
  = note: `!(let Some(true) = Some(false)) as i32` or `(!(let Some(true) = Some(false))).into()` can also be valid options
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#bool_to_int_with_if
  = note: requested on the command line with `-W clippy::bool-to-int-with-if`

warning: `clpy` (bin "clpy" test) generated 1 warning (run `cargo fix --bin "clpy" --tests` to apply 1 suggestion)
warning: `clpy` (bin "clpy") generated 1 warning (1 duplicate)
    Finished dev [unoptimized + debuginfo] target(s) in 0.35s

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 I-false-positive Issue: The lint was triggered on code it shouldn't have labels Nov 20, 2022
@kraktus
Copy link
Contributor

kraktus commented Nov 20, 2022

Should already fixed by #9714.

Running the tool with master clippy would be more adapted here.

@matthiaskrgr
Copy link
Member Author

I'm actually running master, but its the master of the rustc repo and not of the clippy repo 🙃 🙈

@Jarcho
Copy link
Contributor

Jarcho commented Dec 1, 2022

Confirmed fixed with #9714.

@Jarcho Jarcho closed this as completed Dec 1, 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 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