-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Suggestion for add-assigning chars to u32 could be improved #91063
Comments
I think that it's not an issue |
Could you elaborate on the reason you think so? In general, rust tries to provide helpful diagnostics for errors that someone might reasonably make. It's not that there aren't other solutions, such as asking for help, but simply that it saves time and makes the language more approachable for newcomers. |
I agree that the suggestion can be improved.
We also don't offer useful advice for the cases of simple LHS or RHS It is particularly worth offering special diagnostics for the cases of u32 with char: Our char type offers an easy conversion to/from u32, and our char is explicitly a USV, backed by a u32 (what other languages call a "rune", which is sometimes a type alias for u32 or i32), so it is easy to assume they wanted that. People used to some languages may be used to working with an 8-bit char, and might make an incorrect assumption about our char type, but I become less and less confident in that direction as it requires making more and more assumptions. |
We already provide suggestions for casting between numeric literals, it could be extended to also account for
|
Hi, I'm looking at implementing @estebank 's solution, my current plan is to check for the case of "expected |
Go for it! |
…st, r=nagisa suggest casting between i/u32 and char As discussed in rust-lang#91063 , this adds a suggestion for converting between i32/u32 <-> char with `as`, and a short explanation for why this is safe
…st, r=nagisa suggest casting between i/u32 and char As discussed in rust-lang#91063 , this adds a suggestion for converting between i32/u32 <-> char with `as`, and a short explanation for why this is safe
PR merged, issue can be closed? |
Hm, should it be? Diagnostic seems unchanged for the example given, even with a type annotation:
|
I apologize for the early close. It looked like the PR should have taken care of this. |
I should have done some amount of due diligence before suggesting we close it, my b |
Current output:
|
Given the following code:
https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=005f59d63a84412a73cfe88146c11f39
The current output is:
Ideally the output should look like:
The text was updated successfully, but these errors were encountered: