Clarify error on casting larger integers to char#91939
Clarify error on casting larger integers to char#91939bors merged 2 commits intorust-lang:masterfrom
Conversation
|
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @cjgillot (or someone else) soon. Please see the contribution instructions for more information. |
This comment has been minimized.
This comment has been minimized.
| self.expr_ty | ||
| ) | ||
| .span_label(self.span, "invalid cast") | ||
| .span_help(self.span, "try `char::from_u32` instead") |
There was a problem hiding this comment.
This should only be suggested if self.expr_ty is u32. Pseudocode:
| .span_help(self.span, "try `char::from_u32` instead") | |
| let err = type_error_struct!(...).span_label(...); | |
| if self.expr_ty == fcx.tcx.types.u32 { | |
| err.span_help(self.span, "try `char::from_u32` instead"); | |
| } | |
| err.emit(); |
|
Once you do that, you'll need to update test output with |
|
Ping from triage: |
|
Apologies for the late reply. I have one comment on the feedback. If someone tries to cast (e.g.) u16 to char, I think they still should be using if self.expr_ty.is_numeric() {
err.span_help(self.span, if self.expr_ty == fcx.tcx.types.i8 {
"try casting from `u8` instead"
} else if self.expr_ty == fcx.tcx.types.u32 {
"try `char::from_u32` instead"
} else {
"try `char::from_u32` instead (via a `u32`)"
});
} |
This comment has been minimized.
This comment has been minimized.
|
@rustbot label -S-waiting-on-author +S-waiting-on-review |
|
📌 Commit badb81a has been approved by |
Clarify error on casting larger integers to char Closes rust-lang#91836 with changes to E0604.md and a `span_help`.
…askrgr Rollup of 9 pull requests Successful merges: - rust-lang#91939 (Clarify error on casting larger integers to char) - rust-lang#92300 (mips64-openwrt-linux-musl: Add Tier 3 target) - rust-lang#92383 (Add new target armv7-unknown-linux-uclibceabi (softfloat)) - rust-lang#92651 (Remove "up here" arrow on item-infos) - rust-lang#93556 (Change struct expr pretty printing to match rustfmt style) - rust-lang#93649 (Add regression tests for issue 80309) - rust-lang#93657 (Update CPU idle tracking for apple hosts) - rust-lang#93659 (Refactor conditional) - rust-lang#93669 (Resolve lifetimes for const generic defaults) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Closes #91836 with changes to E0604.md and a
span_help.