Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error codes cleanup #66737

Merged
merged 5 commits into from
Nov 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/librustc_error_codes/error_codes/E0062.md
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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 {
Expand Down
5 changes: 3 additions & 2 deletions src/librustc_error_codes/error_codes/E0063.md
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
32 changes: 7 additions & 25 deletions src/librustc_error_codes/error_codes/E0067.md
Original file line number Diff line number Diff line change
@@ -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!
```
4 changes: 3 additions & 1 deletion src/librustc_error_codes/error_codes/E0069.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
38 changes: 20 additions & 18 deletions src/librustc_error_codes/error_codes/E0070.md
Original file line number Diff line number Diff line change
@@ -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 !

Expand Down