rust-lang / rust-lang/rust-clippy
identity_op: span could point at the redundant expression instead of the rest of it?
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
Description
fn main() {
let _ = (1 + 2) * 1 - 1;
}
warning:
warning: this operation has no effect
--> src/main.rs:2:14
|
2 | let _ = (1 + 2) * 1 - 1;
| ^^^^^^^^^^^ help: consider reducing it to: `(1 + 2)`
|
= note: `#[warn(clippy::identity_op)]` on by default
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#identity_op
it's a bit weird that clippy says "this operation has no effect" and then underlines everything BUT the operation that has no effect... 😅
would it make sense to underline the * 1 instead?
Perhaps this newer fancier diff-like diagnostic format could be used here?
- let _ = (1 + 2) * 1 - 1;
~~~ // this part ^ would be red
+ let _ = (1 + 2) - 1;
Version
clippy 0.1.65 (3f83906 2022-09-24)
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 at the identity_op lint entry point and reproduce the diagnostic with the Rust example in this issue. Adjust the reported span so it highlights the redundant * 1 operation rather than the surrounding expression, then verify that the warning and suggested reduction use the intended range.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100