Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integer literal type suggestions do not account for parentheses #138392

Closed
cyrgani opened this issue Mar 12, 2025 · 1 comment · Fixed by #138484
Closed

Integer literal type suggestions do not account for parentheses #138392

cyrgani opened this issue Mar 12, 2025 · 1 comment · Fixed by #138484
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@cyrgani
Copy link
Contributor

cyrgani commented Mar 12, 2025

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

@cyrgani cyrgani added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 12, 2025
@xizheyin
Copy link
Contributor

@rustbot claim

rust-timer added a commit to rust-lang-ci/rust that referenced this issue Mar 16, 2025
Rollup merge of rust-lang#138484 - xizheyin:issue-138392, r=compiler-errors

Use lit span when suggesting suffix lit cast

Fixes rust-lang#138392
@bors bors closed this as completed in f4372f5 Mar 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants