Skip to content

const-propagated arithmetic_overflow in unreachable code #109731

@cuviper

Description

@cuviper

Code

I tried this code: playground

fn main() {
    let x = 2u32;
    let y = 3u32;
    // ...
    if y <= x {
        dbg!(x - y);
    }
}

I expected to see this happen: compiles, nothing printed

Instead, this happened:

error: this arithmetic operation will overflow
 --> src/main.rs:6:14
  |
6 |         dbg!(x - y);
  |              ^^^^^ attempt to compute `2_u32 - 3_u32`, which would overflow
  |
  = note: `#[deny(arithmetic_overflow)]` on by default

The original code comes from macro-generated test cases in num-integer, which failed here:
rust-num/num-integer#54 (comment)

Version it worked on

It most recently worked on: 1.69.0-beta.3

Version with regression

rustc --version --verbose:

rustc 1.70.0-nightly (478cbb42b 2023-03-28)
binary: rustc
commit-hash: 478cbb42b730ba4739351b72ce2aa928e78e2f81
commit-date: 2023-03-28
host: x86_64-unknown-linux-gnu
release: 1.70.0-nightly
LLVM version: 16.0.0

@rustbot modify labels: +regression-from-stable-to-nightly -regression-untriaged

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.P-mediumMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions