rust-lang / rust-lang/rust-clippy
Clippy removes comments from suggestions
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
Summary
When applying suggestions to obfuscated_if_else clippy removes comments.
Reproducer
I tried this code:
fn width(min: f64) -> f64 {
min.is_infinite()
.then_some(
// must do something
min,
)
.unwrap_or(12.4)
}
I expected to see it replaced to this or refusing to apply the fix at all and asking user to do it manually
min.is_infinite() {
// must do something
min
} else {
12.4
}
Instead, this happened:
cargo fix removed comments and replaced the code with this:
min.is_infinite() { min } else { 12.4 }
Version
rustc 1.86.0 (05f9846f8 2025-03-31)
binary: rustc
commit-hash: 05f9846f893b09a1be1fc8560e33fc3c815cfecb
commit-date: 2025-03-31
host: x86_64-unknown-linux-gnu
release: 1.86.0
LLVM version: 19.1.7
Additional Labels
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the issue with the provided Rust example and applying the obfuscated_if_else suggestion through cargo fix. Trace the obfuscated_if_else lint and its suggestion generation, then verify that applying the suggestion preserves the comment or declines to apply the fix. Done means the reproducer no longer loses its comment.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100