Skip to content

constant evaluation should not mask overflow for cases that are otherwise checked #22531

Description

@pnkfelix

While working on rebasing #20795 I discovered that the new run-fail tests it adds were failing to panic, because the arithmetic in question was being handled by the constant evaluation, and the overflow was thus happening at compile time rather than run time.

An example of such an expression:

fn main() {
    let x = 200u8 + 200u8 + 200u8;
}

(Thank goodness it didn't cause my rustc to panic! That would have been a bit frustrating.)

Anyway, we should fix that, as part of #22020.

That is, the program above should fail to compile, and it should not cause an ICE; it should signal a proper error message saying that the arithmetic expression overflowed (because 200+200+200 == 600 > 255 == u8::MAX).

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions