Skip to content

Wrong error on wrapping arithmetic with -Zmir-opt-level=2 #82646

Open
@bytwise

Description

@bytwise

I tried this code with -Z mir-opt-level=2:

fn main() {
    println!("{}", 1_u32.wrapping_sub(2_u32));
}

It compiles and runs without mir-opt, but with -Z mir-opt-level=2 or above I get:

error: this arithmetic operation will overflow
   --> src/main.rs:2:13
    |
2   |       println!("{}", 1_u32.wrapping_sub(2_u32));
    |                      ^^^^^^^^^^^^^^^^^^^^^^^^^ attempt to compute `1_u32 - 2_u32`, which would overflow
    |

Meta

rustc --version --verbose:

rustc 1.52.0-nightly (0148b971c 2021-02-18)
binary: rustc
commit-hash: 0148b971c921a0831fbf3357e5936eec724e3566
commit-date: 2021-02-18
host: x86_64-apple-darwin
release: 1.52.0-nightly
LLVM version: 11.0.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-mir-optArea: MIR optimizationsA-mir-opt-inliningArea: MIR inliningC-bugCategory: This is a bug.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.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