Skip to content

arithmetic_overflow is missed after x >>= n when overflow checks are on #164191

Open

Description

@zxt5

I tried this code:

pub fn f() -> u8 {
    let mut c: u8 = 10;
    c >>= 1;
    0xff + c
}
rustc --crate-type=lib a.rs      # compiles
rustc --crate-type=lib -O a.rs   # error

I expected to see this happen: the same result in both builds. 0xff + c overflows (c is 5), so the deny-by-default arithmetic_overflow lint should reject it either way.

Instead, this happened: the debug build compiles, and the -O build fails:

error: this arithmetic operation will overflow
 --> a.rs:4:5
  |
4 |     0xff + c
  |     ^^^^^^^^ attempt to compute `u8::MAX + 5_u8`, which would overflow
  |
  = note: `#[deny(arithmetic_overflow)]` on by default

Meta

rustc --version --verbose:

rustc 1.99.0 (b940084d7 2026-09-28)
binary: rustc
commit-hash: b940084d7eb6a299eb4bfeb8e34901bc051e7ac4
commit-date: 2026-09-28
host: x86_64-unknown-linux-gnu
release: 1.99.0
LLVM version: 23.1.1
Backtrace

<backtrace>

Activity

  1. added
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Oct 12, 2026
  2. added
    A-diagnosticsArea: Messages for errors, warnings, and lints
    L-false-negativeLint: False negative (should have fired but didn't).
    and removed
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Oct 12, 2026
  3. added
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    on Oct 12, 2026
  4. yashaggarwal85d commented on Oct 26, 2026

    @yashaggarwal85d
  5. yashaggarwal85d commented on Oct 26, 2026

    @yashaggarwal85d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsC-bugCategory: This is a bug.L-arithmetic_overflowLint: arithmetic_overflowL-false-negativeLint: False negative (should have fired but didn't).T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions