Repository navigation
Closed
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveIssue: The lint was triggered on code it shouldn't haveI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when appliedIssue: The suggestions provided by this Lint cause an ICE/error when applied
Description
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
Metadata
Metadata
Assignees
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveIssue: The lint was triggered on code it shouldn't haveI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when appliedIssue: The suggestions provided by this Lint cause an ICE/error when applied
Activity
kraktus commentedon Nov 20, 2022
Should already fixed by #9714.
Running the tool with master clippy would be more adapted here.
matthiaskrgr commentedon Nov 21, 2022
I'm actually running master, but its the master of the rustc repo and not of the clippy repo 🙃 🙈
Jarcho commentedon Dec 1, 2022
Confirmed fixed with #9714.