rust-lang / rust-lang/rust-clippy
suspicious-operation-groupings false positive
Open
@soniasingla is already working on this.
Since Feb 12, 2021.
C-bug
good first issue
I-false-positive
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
Lint name: suspicious-operation-groupings
I tried this code:
pub fn truncated_cone_volume([r0, r1]: [f32; 2], height: f32) -> f32 {
use std::f32::consts::PI;
PI * height * (r0 * r0 + r0 * r1 + r1 * r1) / 3.0
}
Latest clippy gives me this:
warning: This sequence of operators looks suspiciously like a bug.
--> src/lib.rs:3:40
|
3 | PI * height * (r0 * r0 + r0 * r1 + r1 * r1) / 3.0
| ^^^^^^^ help: I think you meant: `PI * r1`
|
= note: `#[warn(clippy::suspicious_operation_groupings)]` on by default
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#suspicious_operation_groupings
(playground link: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=4dbce29a2cf5bed0efc48214538bea53)
Minimal reproduce:
pub fn false_positive(r0: f32, r1: f32) -> f32 {
r0 * r0 + r0 * r1 + r1 * r1
}
2 | r0 * r0 + r0 * r1 + r1 * r1
| ^^^^^^^ help: I think you meant: `r0 * r1`
I don't know how this lint is implemented, but maybe it should only trigger if the number of variables involved is the same as the number of binary expressions?
For instance, this is a true positive:
pub fn true_positive(r0: f32, r1: f32, r2: f32) -> f32 {
r0 * r0 + r1 * r1 + r2 * r1
}
…although the suggestion is probably not the best:
2 | r0 * r0 + r1 * r1 + r2 * r1
| ^^^^^^^ help: I think you meant: `r0 * r1`
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.
Assessment
This issue has not been assessed yet.