Suggestion for misusing the operator `-⁢-`

Rust doesn't have -- operator, which some other languages have. When misusing -- operator in Rust code, the compiler yields warnings as follows:

warning: variable does not need to be mutable
 --> src/main.rs:2:9
  |
2 |     let mut dec = 10;
  |         ----^^^
  |         |
  |         help: remove this `mut`
  |
  = note: `#[warn(unused_mut)]` on by default

warning: unused unary operation that must be used
 --> src/main.rs:4:9
  |
4 |         --dec;
  |         ^^^^^
  |
  = note: `#[warn(unused_must_use)]` on by default

warning: 2 warnings emitted

These warnings are useful to notice the operator doesn't exist, but I think it's still not a proper warning for beginners. How about a suggestion like this:

warning: -- operator doesn't exist
 --> src/main.rs:4:9
  |
4 |         --dec;
  |         ^^^^^
  |         help: do you mean "dec -= 1;"
  = note: `#[warn(unused_must_use)]` on by default
13 Likes

See

9 Likes

Thanks!