Skip to content

Add diagnostic for ++ and -- usages #83502

Closed
@dbofmmbt

Description

@dbofmmbt

Given the following code in the playground:

fn main() {
    let i = 0;
    i++;
}

The current output is:

   Compiling playground v0.0.1 (/playground)
error: expected expression, found `+`
 --> src/main.rs:3:7
  |
3 |     i++;
  |       ^ expected expression

error: aborting due to previous error

error: could not compile `playground`

To learn more, run the command again with --verbose.

I think the message for errors involving ++ or -- should understand that the user is trying to use an operator which doesn't exist in Rust and suggest an idiomatic way to do the increment/decrement operation.

Explanation

Languages like C, Java or Javascript use ++ and -- to increment or decrement integer variables, respectively. As Rust does not support them, it may be good to add an specific diagnostic for those cases, suggesting the user to use something like i += 1 instead.

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsA-parserArea: The lexing & parsing of Rust source code to an ASTC-enhancementCategory: An issue proposing an enhancement or a PR with one.D-newcomer-roadblockDiagnostics: Confusing error or lint; hard to understand for new users.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