Skip to content

Borrowing an overflowing expression supresses arithmetic_overflow #104578

Open
@Jarcho

Description

@Jarcho

This is possibly related to #98444

I tried this code:

fn main() {
    let x = &-(-127i8 - 1);
}

I expected to see this happen:

error: this arithmetic operation will overflow
 --> src/main.rs:3:13
  |
3 |     let x = &-(-127i8 - 1);
  |              ^^^^^^^^^^^^^ attempt to negate `i8::MIN`, which would overflow
  |
  = note: `#[deny(arithmetic_overflow)]` on by default

Instead, this happened: No diagnostic

Meta

Tested on the playground 1.65 and nightly 2022-11-17

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.C-bugCategory: This is a bug.L-arithmetic_overflowLint: arithmetic_overflowT-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