Skip to content

Commit 152c862

Browse files
committed
Proper format for error code explanations
1 parent 1d84947 commit 152c862

File tree

2 files changed

+30
-13
lines changed

2 files changed

+30
-13
lines changed
Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,26 @@
11
Trait objects must include the `dyn` keyword.
22

3-
Trait objects are a way to call methods on types that are not known until
4-
runtime but conform to some trait.
5-
6-
In the following code the trait object should be formed with
7-
`Box<dyn Foo>`, but `dyn` is left off.
3+
Erroneous code example:
84

9-
```no_run
5+
```edition2021,compile_fail,E782
106
trait Foo {}
117
fn test(arg: Box<Foo>) {}
128
```
139

10+
Trait objects are a way to call methods on types that are not known until
11+
runtime but conform to some trait.
12+
13+
Trait objects should be formed with `Box<dyn Foo>`, but in the code above
14+
`dyn` is left off.
15+
1416
This makes it harder to see that `arg` is a trait object and not a
1517
simply a heap allocated type called `Foo`.
1618

19+
To fix this issue, add `dyn` before the trait name.
20+
21+
```
22+
trait Foo {}
23+
fn test(arg: Box<dyn Foo>) {}
24+
```
25+
1726
This used to be allowed before edition 2021, but is now an error.

compiler/rustc_error_codes/src/error_codes/E0783.md

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,26 @@
11
The range pattern `...` is no longer allowed.
22

3+
Erroneous code example:
4+
5+
```edition2021,compile_fail,E782
6+
fn main() {
7+
match 2u8 {
8+
0...9 => println!("Got a number less than 10"),
9+
_ => println!("Got a number 10 or more")
10+
}
11+
}
12+
```
13+
314
Older Rust code using previous editions allowed `...` to stand for exclusive
415
ranges which are now signified using `..=`.
516

6-
The following code use to compile, but now it now longer does.
17+
To make this code compile replace the `...` with `..=`.
718

8-
```no_run
19+
```
920
fn main() {
10-
let n = 2u8;
11-
match n {
12-
...9 => println!("Got a number less than 10"),
21+
match 2u8 {
22+
0..=9 => println!("Got a number less than 10"),
1323
_ => println!("Got a number 10 or more")
1424
}
1525
}
1626
```
17-
18-
To make this code compile replace the `...` with `..=`.

0 commit comments

Comments
 (0)