rust/src/librustc_error_codes/error_codes/E0067.md

676 B

The left-hand side of a compound assignment expression must be a place expression. A place expression represents a memory location and includes item paths (ie, namespaced variables), dereferences, indexing expressions, and field references.

Let's start with some erroneous code examples:

use std::collections::LinkedList;

// Bad: assignment to non-place expression
LinkedList::new() += 1;

// ...

fn some_func(i: &mut i32) {
    i += 12; // Error : '+=' operation cannot be applied on a reference !
}

And now some working examples:

let mut i : i32 = 0;

i += 12; // Good !

// ...

fn some_func(i: &mut i32) {
    *i += 12; // Good !
}