Skip to content

postfix_increment show both type of suggestion for single statement #104867

Closed
@chenyukang

Description

@chenyukang

Story from here

Given the following code:

fn main() {
    let mut i = 0;
    i++;
    println!("i: {:?}", i);
}

The current output is:

error: Rust has no postfix increment operator
 --> ./p/inc.rs:3:6
  |
3 |     i++;
  |      ^^ not a valid postfix operator
  |
help: use `+= 1` instead
  |
3 |     { let tmp = i; i += 1; tmp };
  |     +++++++++++  ~~~~~~~~~~~~~~~
3 |     i += 1;
  |       ~~~~

Ideally the output should look like:

error: Rust has no postfix increment operator
 --> ./p/inc.rs:3:6
  |
3 |     i++;
  |      ^^ not a valid postfix operator
  |
help: use `+= 1` instead
3 |     i += 1;
  |       ~~~~

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsT-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