Skip to content

Failed to evaluate constant value #2394

Closed
@MahadMuhammad

Description

@MahadMuhammad

Failed to evaluate constant value E0080

  • Fixing this issue, help gccrs to emit more user friendly error code and error emission similiar to rustc.
  • You can view the same on compiler-explorer

I tried this code from E0080:

#![allow(unused)]
fn main() {
enum Enum {
    X = (1 << 500),
    Y = (1 / 0),
}
}

I expected to see this happen:

  • Emit error message, similiar to rustc .i.e.,
    • evaluation of constant value failed
  • Error message emitted by rustc:
error[E0080]: evaluation of constant value failed
 --> <source>:4:9
  |
4 |     X = (1 << 500),
  |         ^^^^^^^^^^ attempt to shift left by `500_i32`, which would overflow

error[E0080]: evaluation of constant value failed
 --> <source>:5:9
  |
5 |     Y = (1 / 0),
  |         ^^^^^^^ attempt to divide `1_isize` by zero

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0080`.
Compiler returned: 1

Instead, this happened:

  • Compiled Successfully.
  • This is the output of gccrs:
Compiler returned: 0

Meta

  • What version of Rust GCC were you using, git sha b9566fd.
  • gccrs (Compiler-Explorer-Build-gcc-2f91d511200bf85558c9013b09a458c06edd1e02-binutils-2.40) 13.0.1 20230417 (experimental)

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

Status

Done

Relationships

None yet

Development

No branches or pull requests

Issue actions