]> git.proxmox.com Git - rustc.git/blob - compiler/rustc_error_codes/src/error_codes/E0070.md
New upstream version 1.48.0~beta.8+dfsg1
[rustc.git] / compiler / rustc_error_codes / src / error_codes / E0070.md
1 An assignment operator was used on a non-place expression.
2
3 Erroneous code examples:
4
5 ```compile_fail,E0070
6 struct SomeStruct {
7 x: i32,
8 y: i32,
9 }
10
11 const SOME_CONST: i32 = 12;
12
13 fn some_other_func() {}
14
15 fn some_function() {
16 SOME_CONST = 14; // error: a constant value cannot be changed!
17 1 = 3; // error: 1 isn't a valid place!
18 some_other_func() = 4; // error: we cannot assign value to a function!
19 SomeStruct::x = 12; // error: SomeStruct a structure name but it is used
20 // like a variable!
21 }
22 ```
23
24 The left-hand side of an assignment operator must be a place expression. A
25 place expression represents a memory location and can be a variable (with
26 optional namespacing), a dereference, an indexing expression or a field
27 reference.
28
29 More details can be found in the [Expressions] section of the Reference.
30
31 [Expressions]: https://doc.rust-lang.org/reference/expressions.html#places-rvalues-and-temporaries
32
33 And now let's give working examples:
34
35 ```
36 struct SomeStruct {
37 x: i32,
38 y: i32,
39 }
40 let mut s = SomeStruct { x: 0, y: 0 };
41
42 s.x = 3; // that's good !
43
44 // ...
45
46 fn some_func(x: &mut i32) {
47 *x = 12; // that's good !
48 }
49 ```