File tree Expand file tree Collapse file tree 2 files changed +30
-13
lines changed
compiler/rustc_error_codes/src/error_codes Expand file tree Collapse file tree 2 files changed +30
-13
lines changed Original file line number Diff line number Diff line change 1
1
Trait objects must include the ` dyn ` keyword.
2
2
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:
8
4
9
- ``` no_run
5
+ ``` edition2021,compile_fail,E782
10
6
trait Foo {}
11
7
fn test(arg: Box<Foo>) {}
12
8
```
13
9
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
+
14
16
This makes it harder to see that ` arg ` is a trait object and not a
15
17
simply a heap allocated type called ` Foo ` .
16
18
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
+
17
26
This used to be allowed before edition 2021, but is now an error.
Original file line number Diff line number Diff line change 1
1
The range pattern ` ... ` is no longer allowed.
2
2
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
+
3
14
Older Rust code using previous editions allowed ` ... ` to stand for exclusive
4
15
ranges which are now signified using ` ..= ` .
5
16
6
- The following code use to compile, but now it now longer does .
17
+ To make this code compile replace the ` ... ` with ` ..= ` .
7
18
8
- ``` no_run
19
+ ```
9
20
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"),
13
23
_ => println!("Got a number 10 or more")
14
24
}
15
25
}
16
26
```
17
-
18
- To make this code compile replace the ` ... ` with ` ..= ` .
You can’t perform that action at this time.
0 commit comments