Skip to content

postfix decrement and prefix decrement has no warning  #108495

@nx2k3

Description

@nx2k3

Code

fn main(){
    let mut i=10;
    while i !=0{
        i--;
    }
}

Current output

error: expected expression, found `;`
 --> teste.rs:4:12
  |
4 |         i--;
  |            ^ expected expression

error: aborting due to previous error

Desired output

error: Rust has no postfix decrement operator
 --> ./testt.rs:4:10
  |
4 |         i--;
  |          ^^ not a valid postfix operator
  |
help: use `-= 1` instead
  |
4 |         i -= 1;
  |           ~~~~

error: aborting due to previous error

Rationale and extra context

rust compiler throws error when postfix increment of prefix increment is used, but when decrement is it does not show where the problem is

for example this just compiles with no warning

fn main(){
    let i=10;
    let c=--i +1;
    println!("{c}");
}

the output will be 11 which is not as expected

edit
--i is double negation is rust which I didn't know
but i-- give wrong error

Other cases

No response

Anything else?

No response

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