-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
The From
/Into
traits are not allowed in const
contexts, so the lint triggering in those situations is undesirable.
Lint Name
bool_to_int_with_if
Reproducer
I tried this code:
pub const FOO: usize = if true {
1
} else {
0
};
I saw this happen:
warning: boolean to int conversion using if
--> src/lib.rs:1:24
|
1 | pub const FOO: usize = if true {
| ________________________^
2 | | 1
3 | | } else {
4 | | 0
5 | | };
| |_^ help: replace with from: `usize::from(true)`
|
= note: `true as usize` or `true.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: `#[warn(clippy::bool_to_int_with_if)]` on by default
I expected to see this happen:
The lint shouldn't trigger.
Version
rustc 1.66.0-nightly (1898c34e9 2022-10-26)
binary: rustc
commit-hash: 1898c34e923bad763e723c68dd9f23a09f9eb0fc
commit-date: 2022-10-26
host: x86_64-apple-darwin
release: 1.66.0-nightly
LLVM version: 15.0.2
Additional Labels
@rustbot label +I-suggestion-causes-error
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