Skip to content

Diagnostic: Update invalid number suffix error message to match rustc #4495

@nsvke

Description

@nsvke

Description:

Currently, when an invalid number suffix is provided, gccrs emits a different error message compared to rustc.

Code:

fn main() {
    let _ = 0x1h12;
}

Expected Error Message:

error: invalid suffix `h12` for number literal
  --> <source>:14:13
   |
14 |     let _ = 0x1h12;
   |             ^^^^^^ invalid suffix `h12`
   |
   = help: the suffix must be one of the numeric types (`u32`, `isize`, `f32`, etc.)

error: aborting due to 1 previous error

Compiler returned: 1

Current Error Message:

<source>:14:13: error: unknown number suffix 'h12'
   14 |     let _ = 0x1h12;
      |             ^
Compiler returned: 1 

Possible Fix Location:

Leaving the exact location and steps here in case it helps someone looking for a quick first contribution:

  1. The error seems to be emitted in gcc/rust/lex/rust-lex.cc, roughly around lines 1236-1237.
  2. Changing the format string in the rust_error_at call from "unknown number suffix %qs" to "invalid suffix %qs for number literal" should fix the core message.
  3. A corresponding DejaGnu test in gcc/testsuite/rust/compile/ would also need to be updated or added (e.g., using // { dg-error "invalid suffix .h12. for number literal" }).

Note: Only the error message text needs to match rustc — the output format difference between gccrs and rustc is expected and out of scope.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions