Skip to content

Commit

Permalink
Rollup merge of rust-lang#66774 - GuillaumeGomez:cleanup-err-codes-2,…
Browse files Browse the repository at this point in the history
… r=Dylan-DPC

Clean up error codes

r? @Dylan-DPC
  • Loading branch information
tmandry authored Nov 27, 2019
2 parents 4c51d58 + d05a914 commit ae49770
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 33 deletions.
8 changes: 4 additions & 4 deletions src/librustc_error_codes/error_codes/E0071.md
Original file line number Diff line number Diff line change
@@ -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:

Expand All @@ -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:

Expand Down
21 changes: 12 additions & 9 deletions src/librustc_error_codes/error_codes/E0072.md
Original file line number Diff line number Diff line change
@@ -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`
Expand Down
16 changes: 9 additions & 7 deletions src/librustc_error_codes/error_codes/E0075.md
Original file line number Diff line number Diff line change
@@ -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!
```
17 changes: 10 additions & 7 deletions src/librustc_error_codes/error_codes/E0076.md
Original file line number Diff line number Diff line change
@@ -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!
```
15 changes: 9 additions & 6 deletions src/librustc_error_codes/error_codes/E0077.md
Original file line number Diff line number Diff line change
@@ -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!
```

0 comments on commit ae49770

Please sign in to comment.