Proper format for error code explanations
This commit is contained in:
parent
1d84947bb5
commit
152c86211b
2 changed files with 31 additions and 14 deletions
|
@ -1,17 +1,26 @@
|
||||||
Trait objects must include the `dyn` keyword.
|
Trait objects must include the `dyn` keyword.
|
||||||
|
|
||||||
Trait objects are a way to call methods on types that are not known until
|
Erroneous code example:
|
||||||
runtime but conform to some trait.
|
|
||||||
|
|
||||||
In the following code the trait object should be formed with
|
```edition2021,compile_fail,E782
|
||||||
`Box<dyn Foo>`, but `dyn` is left off.
|
|
||||||
|
|
||||||
```no_run
|
|
||||||
trait Foo {}
|
trait Foo {}
|
||||||
fn test(arg: Box<Foo>) {}
|
fn test(arg: Box<Foo>) {}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Trait objects are a way to call methods on types that are not known until
|
||||||
|
runtime but conform to some trait.
|
||||||
|
|
||||||
|
Trait objects should be formed with `Box<dyn Foo>`, but in the code above
|
||||||
|
`dyn` is left off.
|
||||||
|
|
||||||
This makes it harder to see that `arg` is a trait object and not a
|
This makes it harder to see that `arg` is a trait object and not a
|
||||||
simply a heap allocated type called `Foo`.
|
simply a heap allocated type called `Foo`.
|
||||||
|
|
||||||
|
To fix this issue, add `dyn` before the trait name.
|
||||||
|
|
||||||
|
```
|
||||||
|
trait Foo {}
|
||||||
|
fn test(arg: Box<dyn Foo>) {}
|
||||||
|
```
|
||||||
|
|
||||||
This used to be allowed before edition 2021, but is now an error.
|
This used to be allowed before edition 2021, but is now an error.
|
||||||
|
|
|
@ -1,18 +1,26 @@
|
||||||
The range pattern `...` is no longer allowed.
|
The range pattern `...` is no longer allowed.
|
||||||
|
|
||||||
Older Rust code using previous editions allowed `...` to stand for exclusive
|
Erroneous code example:
|
||||||
ranges which are now signified using `..=`.
|
|
||||||
|
|
||||||
The following code use to compile, but now it now longer does.
|
```edition2021,compile_fail,E782
|
||||||
|
|
||||||
```no_run
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let n = 2u8;
|
match 2u8 {
|
||||||
match n {
|
0...9 => println!("Got a number less than 10"),
|
||||||
...9 => println!("Got a number less than 10"),
|
|
||||||
_ => println!("Got a number 10 or more")
|
_ => println!("Got a number 10 or more")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Older Rust code using previous editions allowed `...` to stand for exclusive
|
||||||
|
ranges which are now signified using `..=`.
|
||||||
|
|
||||||
To make this code compile replace the `...` with `..=`.
|
To make this code compile replace the `...` with `..=`.
|
||||||
|
|
||||||
|
```
|
||||||
|
fn main() {
|
||||||
|
match 2u8 {
|
||||||
|
0..=9 => println!("Got a number less than 10"),
|
||||||
|
_ => println!("Got a number 10 or more")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue