Skip to content

Duplicate errors for overflowing division / remainder #69020

Closed
@RalfJung

Description

@RalfJung

When there is an overflowing division or remainder operation that const_prop can detect, the error is duplicated in release mode only:

#![deny(const_err)]

use std::i32;

fn main() {
    let _ = i32::MIN / -1;
}

shows

error: attempt to divide with overflow
 --> src/main.rs:6:13
  |
6 |     let _ = i32::MIN / -1;
  |             ^^^^^^^^^^^^^
  |
note: the lint level is defined here
 --> src/main.rs:1:9
  |
1 | #![deny(const_err)]
  |         ^^^^^^^^^

error: this expression will panic at runtime
 --> src/main.rs:6:13
  |
6 |     let _ = i32::MIN / -1;
  |             ^^^^^^^^^^^^^ attempt to divide with overflow

This is because !overflow_check is true in release mode but divison and remainder still get overflow checks.

(This test case already covers the problem, so a fix does not need a new test case, it just needs to adjust the existing test case to no longer expect two ERROR per line.)

Cc @oli-obk @wesleywiser

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)C-bugCategory: This is a bug.D-verboseDiagnostics: Too much output caused by a single piece of incorrect code.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