Update BARE_TRAIT_OBJECT and ELLIPSIS_INCLUSIVE_RANGE_PATTERNS to errors in Rust 2021

This commit is contained in:
Ryan Levick
2021-03-16 21:47:06 +01:00
parent 69e1d22ddb
commit c2d0f1457a
9 changed files with 177 additions and 32 deletions

View File

@@ -0,0 +1,17 @@
Trait objects must include the `dyn` keyword.
Trait objects are a way to call methods on types that are not known until
runtime but conform to some trait.
In the following code the trait object should be formed with
`Box<dyn Foo>`, but `dyn` is left off.
```compile_fail,E0782
trait Foo {}
fn test(arg: Box<Foo>) {}
```
This makes it harder to see that `arg` is a trait object and not a
simply a heap allocated type called `Foo`.
This used to be allowed before edition 2021, but is now an error.

View File

@@ -0,0 +1,18 @@
The range pattern `...` is no longer allowed.
Older Rust code using previous editions allowed `...` to stand for exclusive
ranges which are now signified using `..=`.
The following code use to compile, but now it now longer does.
```compile_fail,E0783
fn main() {
let n = 2u8;
match n {
...9 => println!("Got a number less than 10),
_ => println!("Got a number 10 or more")
}
}
```
To make this code compile replace the `...` with `..=`.