@@ -282,8 +282,8 @@ be specified exactly one time.
282
282
283
283
E0063 : r##"
284
284
This error indicates that during an attempt to build a struct or struct-like
285
- enum variant, one of the fields was not provided. Each field should be specified
286
- exactly once.
285
+ enum variant, one of the fields was not provided. Each field should be
286
+ specified exactly once.
287
287
"## ,
288
288
289
289
E0066 : r##"
@@ -297,19 +297,36 @@ and [RFC 809] for more details.
297
297
"## ,
298
298
299
299
E0067 : r##"
300
- The left-hand side of an assignment operator must be an lvalue expression. An
301
- lvalue expression represents a memory location and includes item paths (ie,
302
- namespaced variables), dereferences, indexing expressions, and field references.
300
+ The left-hand side of a compound assignment expression must be an lvalue
301
+ expression. An lvalue expression represents a memory location and includes
302
+ item paths (ie, namespaced variables), dereferences, indexing expressions,
303
+ and field references.
303
304
305
+ Let's start with some bad examples:
304
306
```
305
307
use std::collections::LinkedList;
306
308
307
- // Good
308
- let mut list = LinkedList::new();
309
-
310
-
311
309
// Bad: assignment to non-lvalue expression
312
310
LinkedList::new() += 1;
311
+
312
+ // ...
313
+
314
+ fn some_func(i: &mut i32) {
315
+ i += 12; // Error : '+=' operation cannot be applied on a reference !
316
+ }
317
+
318
+ And now some good examples:
319
+ ```
320
+ let mut i : i32 = 0;
321
+
322
+ i += 12; // Good !
323
+
324
+ // ...
325
+
326
+ fn some_func(i: &mut i32) {
327
+ *i += 12; // Good !
328
+ }
329
+
313
330
```
314
331
"## ,
315
332
@@ -328,6 +345,53 @@ Since `return;` is just like `return ();`, there is a mismatch between the
328
345
function's return type and the value being returned.
329
346
"## ,
330
347
348
+ E0070 : r##"
349
+ The left-hand side of an assignment operator must be an lvalue expression. An
350
+ lvalue expression represents a memory location and can be a variable (with
351
+ optional namespacing), a dereference, an indexing expression or a field
352
+ reference.
353
+
354
+ More details can be found here:
355
+ https://doc.rust-lang.org/reference.html#lvalues,-rvalues-and-temporaries
356
+
357
+ Now, we can go further. Here are some bad examples:
358
+ ```
359
+ struct SomeStruct {
360
+ x: i32,
361
+ y: i32
362
+ }
363
+ const SOME_CONST : i32 = 12;
364
+
365
+ fn some_other_func() {}
366
+
367
+ fn some_function() {
368
+ SOME_CONST = 14; // error : a constant value cannot be changed!
369
+ 1 = 3; // error : 1 isn't a valid lvalue!
370
+ some_other_func() = 4; // error : we can't assign value to a function!
371
+ SomeStruct.x = 12; // error : SomeStruct a structure name but it is used
372
+ // like a variable!
373
+ }
374
+ ```
375
+
376
+ And now let's give good examples:
377
+
378
+ ```
379
+ struct SomeStruct {
380
+ x: i32,
381
+ y: i32
382
+ }
383
+ let mut s = SomeStruct {x: 0, y: 0};
384
+
385
+ s.x = 3; // that's good !
386
+
387
+ // ...
388
+
389
+ fn some_func(x: &mut i32) {
390
+ *x = 12; // that's good !
391
+ }
392
+ ```
393
+ "## ,
394
+
331
395
E0072 : r##"
332
396
When defining a recursive struct or enum, any use of the type being defined
333
397
from inside the definition must occur behind a pointer (like `Box` or `&`).
@@ -931,7 +995,6 @@ register_diagnostics! {
931
995
E0060 ,
932
996
E0061 ,
933
997
E0068 ,
934
- E0070 ,
935
998
E0071 ,
936
999
E0074 ,
937
1000
E0075 ,
0 commit comments