Skip to content

Suggestion for add-assigning chars to u32 could be improved #91063

Description

@VoleurVolant

Given the following code:

https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=005f59d63a84412a73cfe88146c11f39

fnmain(){let greeting = "Hello, World!";letmut output = 0;for c in greeting.chars(){
output += c;}println!("The values of the characters in \"{greeting}\" sum to {output}");}

The current output is:

error[E0277]: cannot add-assign `char` to `{integer}`
--> src/main.rs:5:10
|
5 | output += c;
| ^^ no implementation for `{integer} += char`
|
= help: the trait `AddAssign<char>` is not implemented for `{integer}`
For more information about this error, try `rustc --explain E0277`.

Ideally the output should look like:

error[E0277]: cannot add-assign `char` to `{integer}`
--> src/main.rs:5:10
|
5 | output += c;
| ^^ no implementation for `{integer} += char`
|
= help: the trait `AddAssign<char>` is not implemented for `{integer}`. You may have meant to use `as u32` or `to_digit` on the `char`.
For more information about this error, try `rustc --explain E0277`.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.D-newcomer-roadblockDiagnostics: Confusing error or lint; hard to understand for new users.D-papercutDiagnostics: An error or lint that needs small tweaks.T-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