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

u32 as char: suggested code is unchanged #97160

Closed
Zoybean opened this issue May 19, 2022 · 3 comments · Fixed by #97169
Closed

u32 as char: suggested code is unchanged #97160

Zoybean opened this issue May 19, 2022 · 3 comments · Fixed by #97169
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

@Zoybean
Copy link

Zoybean commented May 19, 2022

Given the following code: playground link

pub fn u32_as_char(x: u32) -> char {
    (x as u32) as char
}

The current output is:

error[[E0604]](https://doc.rust-lang.org/stable/error-index.html#E0604): only `u8` can be cast as `char`, not `u32`
 --> src/lib.rs:3:5
  |
3 |     (x as u32) as char
  |     ^^^^^^^^^^^^^^^^^^ invalid cast
  |
help: try `char::from_u32` instead
 --> src/lib.rs:3:5
  |
3 |     (x as u32) as char
  |     ^^^^^^^^^^^^^^^^^^

For more information about this error, try `rustc --explain E0604`.

Ideally the output should look like:

error[[E0604]](https://doc.rust-lang.org/stable/error-index.html#E0604): only `u8` can be cast as `char`, not `u32`
 --> src/lib.rs:3:5
  |
3 |     (x as u32) as char
  |     ^^^^^^^^^^^^^^^^^^ invalid cast
  |
help: try `char::from_u32` instead
 --> src/lib.rs:3:5
  |
3 |     char::from_u32(x as u32)
  |     ^^^^^^^^^^^^^^^^^^^^^^^^

For more information about this error, try `rustc --explain E0604`.
@Zoybean Zoybean 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 May 19, 2022
@ghost
Copy link

ghost commented May 19, 2022

@rustbot claim

@rustbot rustbot assigned ghost May 19, 2022
@ghost
Copy link

ghost commented May 19, 2022

Et Voila!

image

@Zoybean Here's the final result, pushing a PR soon 👋🏻

@ghost
Copy link

ghost commented May 19, 2022

Should be fixed by #97169

@bors bors closed this as completed in 3913d99 May 20, 2022
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.

1 participant