From bf5c64abff4994c2743b675d1d39c57571155a53 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 25 Nov 2019 13:31:05 +0100 Subject: [PATCH 1/5] Clean up E0062 long explanation --- src/librustc_error_codes/error_codes/E0062.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/librustc_error_codes/error_codes/E0062.md b/src/librustc_error_codes/error_codes/E0062.md index 0ebeb1bd78ed0..64fc027b885b6 100644 --- a/src/librustc_error_codes/error_codes/E0062.md +++ b/src/librustc_error_codes/error_codes/E0062.md @@ -1,6 +1,6 @@ -This error indicates that during an attempt to build a struct or struct-like -enum variant, one of the fields was specified more than once. Erroneous code -example: +A struct's or struct-like enum variant's field was specified more than once. + +Erroneous code example: ```compile_fail,E0062 struct Foo { @@ -15,7 +15,9 @@ fn main() { } ``` -Each field should be specified exactly one time. Example: +This error indicates that during an attempt to build a struct or struct-like +enum variant, one of the fields was specified more than once. Each field should +be specified exactly one time. Example: ``` struct Foo { From 7e813c4a014de141a09b4e8b74532b2896b2766a Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 25 Nov 2019 13:32:11 +0100 Subject: [PATCH 2/5] Clean up E0063 long explanation --- src/librustc_error_codes/error_codes/E0063.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/librustc_error_codes/error_codes/E0063.md b/src/librustc_error_codes/error_codes/E0063.md index 0d1f60437acf0..0e611deac426f 100644 --- a/src/librustc_error_codes/error_codes/E0063.md +++ b/src/librustc_error_codes/error_codes/E0063.md @@ -1,5 +1,6 @@ -This error indicates that during an attempt to build a struct or struct-like -enum variant, one of the fields was not provided. Erroneous code example: +A struct's or struct-like enum variant's field was not provided. + +Erroneous code example: ```compile_fail,E0063 struct Foo { From 98e29176264635da8a8c0b2f2ccabf282cfa2282 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 25 Nov 2019 13:49:32 +0100 Subject: [PATCH 3/5] Clean up E0067 long explanation --- src/librustc_error_codes/error_codes/E0067.md | 32 ++++--------------- 1 file changed, 7 insertions(+), 25 deletions(-) diff --git a/src/librustc_error_codes/error_codes/E0067.md b/src/librustc_error_codes/error_codes/E0067.md index 101b96f7983f6..11041bb53ee55 100644 --- a/src/librustc_error_codes/error_codes/E0067.md +++ b/src/librustc_error_codes/error_codes/E0067.md @@ -1,33 +1,15 @@ -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. +An invalid left-hand side expression was used on an assignment operation. -Let's start with some erroneous code examples: +Erroneous code example: ```compile_fail,E0067 -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 ! -} +12 += 1; // error! ``` -And now some working examples: +You need to have a place expression to be able to assign it something. For +example: ``` -let mut i : i32 = 0; - -i += 12; // Good ! - -// ... - -fn some_func(i: &mut i32) { - *i += 12; // Good ! -} +let mut x: i8 = 12; +x += 1; // ok! ``` From ef35980ffbdf70870c37b78aa2da1bcf1ee775a2 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 25 Nov 2019 13:50:25 +0100 Subject: [PATCH 4/5] Clean up E0069 long explanation --- src/librustc_error_codes/error_codes/E0069.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/librustc_error_codes/error_codes/E0069.md b/src/librustc_error_codes/error_codes/E0069.md index ad3b1803b54db..7367a5c0922ea 100644 --- a/src/librustc_error_codes/error_codes/E0069.md +++ b/src/librustc_error_codes/error_codes/E0069.md @@ -1,5 +1,7 @@ The compiler found a function whose body contains a `return;` statement but -whose return type is not `()`. An example of this is: +whose return type is not `()`. + +Erroneous code example: ```compile_fail,E0069 // error From 1bd28b1087b067df4037cbbe2f48db7776e3deaa Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 25 Nov 2019 13:53:55 +0100 Subject: [PATCH 5/5] Clean up E0070 long explanation --- src/librustc_error_codes/error_codes/E0070.md | 38 ++++++++++--------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/src/librustc_error_codes/error_codes/E0070.md b/src/librustc_error_codes/error_codes/E0070.md index 1a56080a09734..97522af3da867 100644 --- a/src/librustc_error_codes/error_codes/E0070.md +++ b/src/librustc_error_codes/error_codes/E0070.md @@ -1,41 +1,43 @@ -The left-hand side of an assignment operator must be a place expression. A -place expression represents a memory location and can be a variable (with -optional namespacing), a dereference, an indexing expression or a field -reference. +An assignment operator was used on a non-place expression. -More details can be found in the [Expressions] section of the Reference. - -[Expressions]: https://doc.rust-lang.org/reference/expressions.html#places-rvalues-and-temporaries - -Now, we can go further. Here are some erroneous code examples: +Erroneous code examples: ```compile_fail,E0070 struct SomeStruct { x: i32, - y: i32 + y: i32, } -const SOME_CONST : i32 = 12; +const SOME_CONST: i32 = 12; fn some_other_func() {} fn some_function() { - SOME_CONST = 14; // error : a constant value cannot be changed! - 1 = 3; // error : 1 isn't a valid place! - some_other_func() = 4; // error : we cannot assign value to a function! - SomeStruct.x = 12; // error : SomeStruct a structure name but it is used - // like a variable! + SOME_CONST = 14; // error: a constant value cannot be changed! + 1 = 3; // error: 1 isn't a valid place! + some_other_func() = 4; // error: we cannot assign value to a function! + SomeStruct::x = 12; // error: SomeStruct a structure name but it is used + // like a variable! } ``` +The left-hand side of an assignment operator must be a place expression. A +place expression represents a memory location and can be a variable (with +optional namespacing), a dereference, an indexing expression or a field +reference. + +More details can be found in the [Expressions] section of the Reference. + +[Expressions]: https://doc.rust-lang.org/reference/expressions.html#places-rvalues-and-temporaries + And now let's give working examples: ``` struct SomeStruct { x: i32, - y: i32 + y: i32, } -let mut s = SomeStruct {x: 0, y: 0}; +let mut s = SomeStruct { x: 0, y: 0 }; s.x = 3; // that's good !