Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

postfix decrement and prefix decrement has no warning #108495

Closed
nx2k3 opened this issue Feb 26, 2023 · 1 comment · Fixed by #108496 or #108587
Closed

postfix decrement and prefix decrement has no warning #108495

nx2k3 opened this issue Feb 26, 2023 · 1 comment · Fixed by #108496 or #108587
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@nx2k3
Copy link
Contributor

nx2k3 commented Feb 26, 2023

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

@nx2k3 nx2k3 added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Feb 26, 2023
@nx2k3
Copy link
Contributor Author

nx2k3 commented Feb 26, 2023

@rustbot claim

@nx2k3 nx2k3 changed the title postfix decrement and perfix decrement has no warning postfix decrement and prefix decrement has no warning Feb 26, 2023
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Mar 1, 2023
…pkin

fix rust-lang#108495, postfix decrement and prefix decrement has no warning

Fixes rust-lang#108495
bors added a commit to rust-lang-ci/rust that referenced this issue Mar 1, 2023
…iaskrgr

Rollup of 10 pull requests

Successful merges:

 - rust-lang#108376 (compiler/rustc_session: fix sysroot detection logic)
 - rust-lang#108400 (add llvm cgu instructions stats to perf)
 - rust-lang#108496 (fix rust-lang#108495, postfix decrement and prefix decrement has no warning)
 - rust-lang#108505 (Further unify validity intrinsics)
 - rust-lang#108520 (Small cleanup to `one_bound_for_assoc_type`)
 - rust-lang#108560 (Some `infer/mod.rs` cleanups)
 - rust-lang#108563 (Make mailmap more correct)
 - rust-lang#108564 (Fix `x clean` with specific paths)
 - rust-lang#108571 (Add contains_key to SortedIndexMultiMap)
 - rust-lang#108578 (Update Fuchsia platform team members)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors closed this as completed in 46ea12a Mar 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
1 participant