rust-lang / rust-lang/rust-clippy

`clippy::suspicious_operation_groupings` creates code that fails to compile

Open
#13,137 2 comments 0 reactions 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.