# Suggestion for misusing the operator \`-⁢-\`

**URL:** <https://internals.rust-lang.org/t/suggestion-for-misusing-the-operator/14765>\
**Category:** compiler\
**Created:** [May 24, 2021, 11:11am UTC](https://internals.rust-lang.org/t/suggestion-for-misusing-the-operator/14765 "2021-05-24T11:11:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![uint256\_t](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/uint256_t/32/6673_2.png) [@uint256\_t](https://internals.rust-lang.org/u/uint256_t)\
**Post date:** [May 24, 2021, 11:11am UTC](https://internals.rust-lang.org/t/suggestion-for-misusing-the-operator/14765/1 "2021-05-24T11:11:04Z")

</div>

Rust doesn't have `--` operator, which some other languages have. When misusing `--` operator in Rust [code](https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=45d4ca013ae38a16785cfc68c782d984), the compiler yields warnings as follows:

```rust
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:

```rust
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

```

---

<div class="post-metadata">

**Author:** ![matklad](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/matklad/32/12266_2.png) [@matklad](https://internals.rust-lang.org/u/matklad)\
**Post date:** [May 24, 2021, 1:13pm UTC](https://internals.rust-lang.org/t/suggestion-for-misusing-the-operator/14765/2 "2021-05-24T13:13:34Z")

</div>

See

- [Suggest `i += 1` when we see `i++` or `++i` by camelid · Pull Request #83536 · rust-lang/rust · GitHub](https://github.com/rust-lang/rust/pull/83536)
- [Uplift clippy::double\_neg into rustc · Issue #82987 · rust-lang/rust · GitHub](https://github.com/rust-lang/rust/issues/82987)

---

<div class="post-metadata">

**Author:** ![uint256\_t](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/uint256_t/32/6673_2.png) [@uint256\_t](https://internals.rust-lang.org/u/uint256_t)\
**Post date:** [May 24, 2021, 1:25pm UTC](https://internals.rust-lang.org/t/suggestion-for-misusing-the-operator/14765/3 "2021-05-24T13:25:20Z")

</div>

Thanks!

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/system/32/14092_2.png) [@system](https://internals.rust-lang.org/u/system)\
**Post date:** [August 22, 2021, 1:25pm UTC](https://internals.rust-lang.org/t/suggestion-for-misusing-the-operator/14765/4 "2021-08-22T13:25:32Z")

</div>

Closed on August 22, 2021, 1:25pm UTC

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
