Rollup merge of #66774 - GuillaumeGomez:cleanup-err-codes-2, r=Dylan-DPC

Clean up error codes

r? @Dylan-DPC
This commit is contained in:
Tyler Mandry 2019-11-27 15:28:48 -06:00 committed by GitHub
commit ae49770918
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 44 additions and 33 deletions

View file

@ -1,5 +1,5 @@
You tried to use structure-literal syntax to create an item that is
not a structure or enum variant.
A structure-literal syntax was used to create an item that is not a structure
or enum variant.
Example of erroneous code:
@ -9,8 +9,8 @@ let t = U32 { value: 4 }; // error: expected struct, variant or union type,
// found builtin type `u32`
```
To fix this, ensure that the name was correctly spelled, and that
the correct form of initializer was used.
To fix this, ensure that the name was correctly spelled, and that the correct
form of initializer was used.
For example, the code above can be fixed to:

View file

@ -1,20 +1,23 @@
When defining a recursive struct or enum, any use of the type being defined
from inside the definition must occur behind a pointer (like `Box` or `&`).
This is because structs and enums must have a well-defined size, and without
the pointer, the size of the type would need to be unbounded.
A recursive type has infinite size because it doesn't have an indirection.
Consider the following erroneous definition of a type for a list of bytes:
Erroneous code example:
```compile_fail,E0072
// error, invalid recursive struct type
struct ListNode {
head: u8,
tail: Option<ListNode>,
tail: Option<ListNode>, // error: no indirection here so impossible to
// compute the type's size
}
```
This type cannot have a well-defined size, because it needs to be arbitrarily
large (since we would be able to nest `ListNode`s to any depth). Specifically,
When defining a recursive struct or enum, any use of the type being defined
from inside the definition must occur behind a pointer (like `Box`, `&` or
`Rc`). This is because structs and enums must have a well-defined size, and
without the pointer, the size of the type would need to be unbounded.
In the example, the type cannot have a well-defined size, because it needs to be
arbitrarily large (since we would be able to nest `ListNode`s to any depth).
Specifically,
```plain
size of `ListNode` = 1 byte for `head`

View file

@ -1,21 +1,23 @@
The `#[simd]` attribute can only be applied to non empty tuple structs, because
it doesn't make sense to try to use SIMD operations when there are no values to
operate on.
A `#[simd]` attribute was applied to an empty tuple struct.
This will cause an error:
Erroneous code example:
```compile_fail,E0075
#![feature(repr_simd)]
#[repr(simd)]
struct Bad;
struct Bad; // error!
```
This will not:
The `#[simd]` attribute can only be applied to non empty tuple structs, because
it doesn't make sense to try to use SIMD operations when there are no values to
operate on.
Fixed example:
```
#![feature(repr_simd)]
#[repr(simd)]
struct Good(u32);
struct Good(u32); // ok!
```

View file

@ -1,21 +1,24 @@
When using the `#[simd]` attribute to automatically use SIMD operations in tuple
struct, the types in the struct must all be of the same type, or the compiler
will trigger this error.
All types in a tuple struct aren't the same when using the `#[simd]`
attribute.
This will cause an error:
Erroneous code example:
```compile_fail,E0076
#![feature(repr_simd)]
#[repr(simd)]
struct Bad(u16, u32, u32);
struct Bad(u16, u32, u32); // error!
```
This will not:
When using the `#[simd]` attribute to automatically use SIMD operations in tuple
struct, the types in the struct must all be of the same type, or the compiler
will trigger this error.
Fixed example:
```
#![feature(repr_simd)]
#[repr(simd)]
struct Good(u32, u32, u32);
struct Good(u32, u32, u32); // ok!
```

View file

@ -1,20 +1,23 @@
When using the `#[simd]` attribute on a tuple struct, the elements in the tuple
must be machine types so SIMD operations can be applied to them.
A tuple struct's element isn't a machine type when using the `#[simd]`
attribute.
This will cause an error:
Erroneous code example:
```compile_fail,E0077
#![feature(repr_simd)]
#[repr(simd)]
struct Bad(String);
struct Bad(String); // error!
```
This will not:
When using the `#[simd]` attribute on a tuple struct, the elements in the tuple
must be machine types so SIMD operations can be applied to them.
Fixed example:
```
#![feature(repr_simd)]
#[repr(simd)]
struct Good(u32, u32, u32);
struct Good(u32, u32, u32); // ok!
```