-
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 thing
Description
Summary
warning: this if-then-else expression returns a bool literal
--> src/model_view_impl/project_main/mvc_models.rs:1580:11
|
1580 | / if acp_spec.cancellation_required() == false {
1581 | | // ... This is an important comment with a detailed discusion justifying the business logic / business decisions behind this specific behavior.
1582 | | true
1583 | | } else {
1584 | | false
1585 | | }
| |___________^ help: you can reduce it to: `acp_spec.cancellation_required() == false`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_bool
= note: `#[warn(clippy::needless_bool)]` on by default
With the lint above, when used with --fix
causes the following code changes:
(false, _) => true,
// Cancellation info not available...
(true, Some(acp_spec)) => {
- if acp_spec.cancellation_required() == false {
- // ... This is an important comment with a detailed discusion justifying the business logic / business decisions behind this specific behavior.
- true
- } else {
- false
- }
+ !acp_spec.cancellation_required()
}
_ => false,
}
but the comment line is lost.
While I'm not sure where the comments should be retained it seems like a bad idea to remove them, especially if they are describing some important business logic that justifies the behavior.
Reproducer
I tried this code: cargo clippy --fix
if acp_spec.cancellation_required() == false {
// ... This is an important comment with a detailed discusion justifying the business logic / business decisions behind this specific behavior.
true
} else {
false
}
I expected to see this happen:
The comment is somehow preserved, and at the very least, not completely deleted.
Instead, this happened:
The comment was removed, and only !acp_spec.cancellation_required()
remained.
Version
cargo --version
cargo 1.69.0 (6e9a83356 2023-04-12)rustc --version
rustc 1.69.0 (84c898d65 2023-04-16)cargo clippy --version
clippy 0.1.69 (84c898d6 2023-04-16)
Additional Labels
No response
Metadata
Metadata
Assignees
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thing