rust-lang / rust-lang/rust-clippy
`clippy::suspicious_operation_groupings` creates code that fails to compile
Open
Nobody has claimed this yet.
C-bug
I-false-positive
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
Summary
I was using clippy when I found it generated incorrect code, so I made a minimal reproducer.
Lint Name
clippy::suspicious_operation_groupings
Reproducer
fn bug() {
#[derive(Clone, Copy)]
struct A {
value: f32,
time: f32,
}
struct T(f32);
let a = A {
value:1.0,
time:2.0
};
let a1 = a;
let b = T(2.0);
let t = (b.0 - a.time) / (a1.time - a.time); // this line
}
Version
rustc 1.79.0 (129f3b996 2024-06-10)
binary: rustc
commit-hash: 129f3b9964af4d4a709d1383930ade12dfe7c081
commit-date: 2024-06-10
host: x86_64-unknown-linux-gnu
release: 1.79.0
LLVM version: 18.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 running the minimal Rust reproducer with clippy::suspicious_operation_groupings on the reported Rust 1.79.0 toolchain and inspect the generated suggestion. Trace the lint's implementation from that lint entry point, then add a regression test showing the suggested code compiles and preserves the intended operation grouping.
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
- 42/100