Auto merge of #83213 - rylev:update-lints-to-errors, r=nikomatsakis
Update BARE_TRAIT_OBJECT and ELLIPSIS_INCLUSIVE_RANGE_PATTERNS to errors in Rust 2021 This addresses https://github.com/rust-lang/rust/pull/81244 by updating two lints to errors in the Rust 2021 edition. r? `@estebank`
This commit is contained in:
26
compiler/rustc_error_codes/src/error_codes/E0782.md
Normal file
26
compiler/rustc_error_codes/src/error_codes/E0782.md
Normal file
@@ -0,0 +1,26 @@
|
||||
Trait objects must include the `dyn` keyword.
|
||||
|
||||
Erroneous code example:
|
||||
|
||||
```edition2021,compile_fail,E0782
|
||||
trait Foo {}
|
||||
fn test(arg: Box<Foo>) {} // error!
|
||||
```
|
||||
|
||||
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
|
||||
simply a heap allocated type called `Foo`.
|
||||
|
||||
To fix this issue, add `dyn` before the trait name.
|
||||
|
||||
```edition2021
|
||||
trait Foo {}
|
||||
fn test(arg: Box<dyn Foo>) {} // ok!
|
||||
```
|
||||
|
||||
This used to be allowed before edition 2021, but is now an error.
|
||||
22
compiler/rustc_error_codes/src/error_codes/E0783.md
Normal file
22
compiler/rustc_error_codes/src/error_codes/E0783.md
Normal file
@@ -0,0 +1,22 @@
|
||||
The range pattern `...` is no longer allowed.
|
||||
|
||||
Erroneous code example:
|
||||
|
||||
```edition2021,compile_fail,E0783
|
||||
match 2u8 {
|
||||
0...9 => println!("Got a number less than 10"), // error!
|
||||
_ => 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 `..=`.
|
||||
|
||||
```edition2021
|
||||
match 2u8 {
|
||||
0..=9 => println!("Got a number less than 10"), // ok!
|
||||
_ => println!("Got a number 10 or more"),
|
||||
}
|
||||
```
|
||||
Reference in New Issue
Block a user