Skip to content

Integer literal type suggestions do not account for parentheses #138392

Closed
@cyrgani

Description

@cyrgani

Code

fn main() {
    let x: u8 = (4i32);
}

Current output

error[E0308]: mismatched types
 --> src/main.rs:2:17
  |
2 |     let x: u8 = (4i32);
  |            --   ^^^^^^ expected `u8`, found `i32`
  |            |
  |            expected due to this
  |
help: change the type of the numeric literal from `i32` to `u8`
  |
2 |     let x: u8 = (4i32)u8;
  |                       ++

Desired output

error[E0308]: mismatched types
 --> src/main.rs:2:17
  |
2 |     let x: u8 = (4i32);
  |            --   ^^^^^^ expected `u8`, found `i32`
  |            |
  |            expected due to this
  |
help: change the type of the numeric literal from `i32` to `u8`
  |
2 |     let x: u8 = 4u8;
  |

Rationale and extra context

No response

Other cases

Rust Version

1.87.0-nightly

(2025-03-11 6650252439d4e03368b3)

Anything else?

No response

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsT-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