Skip to content

Commit c795406

Browse files
Add error explanation for E0070
1 parent 2dd5ad0 commit c795406

File tree

1 file changed

+51
-4
lines changed

1 file changed

+51
-4
lines changed

src/librustc_typeck/diagnostics.rs

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ be specified exactly one time.
124124

125125
E0063: r##"
126126
This error indicates that during an attempt to build a struct or struct-like
127-
enum variant, one of the fields was not provided. Each field should be specified
128-
exactly once.
127+
enum variant, one of the fields was not provided. Each field should be
128+
specified exactly once.
129129
"##,
130130

131131
E0066: r##"
@@ -141,7 +141,8 @@ and [RFC 809] for more details.
141141
E0067: r##"
142142
The left-hand side of an assignment operator must be an lvalue expression. An
143143
lvalue expression represents a memory location and includes item paths (ie,
144-
namespaced variables), dereferences, indexing expressions, and field references.
144+
namespaced variables), dereferences, indexing expressions, and field
145+
references.
145146
146147
```
147148
use std::collections::LinkedList;
@@ -170,6 +171,53 @@ Since `return;` is just like `return ();`, there is a mismatch between the
170171
function's return type and the value being returned.
171172
"##,
172173

174+
E0070: r##"
175+
The left-hand side of an assignment operator must be an lvalue expression. An
176+
lvalue expression represents a memory location and can be a variable (with
177+
optional namespacing), a dereference, an indexing expression or a field
178+
reference.
179+
180+
More details can be found here:
181+
https://doc.rust-lang.org/reference.html#lvalues,-rvalues-and-temporaries
182+
183+
Now, we can go further. Here are some bad examples:
184+
```
185+
struct SomeStruct {
186+
x: i32,
187+
y: i32
188+
}
189+
const SOME_CONST : i32 = 12;
190+
191+
fn some_other_func() {}
192+
193+
fn some_function() {
194+
SOME_CONST = 14; // error : a constant value cannot be changed!
195+
1 = 3; // error : 1 isn't a valid lvalue!
196+
some_other_func() = 4; // error : we can't assign value to a function!
197+
SomeStruct.x = 12; // error : SomeStruct a structure name but it is used
198+
// like a variable!
199+
}
200+
```
201+
202+
And now let's give good examples:
203+
204+
```
205+
struct SomeStruct {
206+
x: i32,
207+
y: i32
208+
}
209+
let mut s = SomeStruct {x: 0, y: 0};
210+
211+
s.x = 3; // that's good !
212+
213+
// ...
214+
215+
fn some_func(x: &mut i32) {
216+
*x = 12; // that's good !
217+
}
218+
```
219+
"##,
220+
173221
E0072: r##"
174222
When defining a recursive struct or enum, any use of the type being defined
175223
from inside the definition must occur behind a pointer (like `Box` or `&`).
@@ -779,7 +827,6 @@ register_diagnostics! {
779827
E0060,
780828
E0061,
781829
E0068,
782-
E0070,
783830
E0071,
784831
E0074,
785832
E0075,

0 commit comments

Comments
 (0)