forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#83213 - rylev:update-lints-to-errors, r=nikom…
…atsakis Update BARE_TRAIT_OBJECT and ELLIPSIS_INCLUSIVE_RANGE_PATTERNS to errors in Rust 2021 This addresses rust-lang#81244 by updating two lints to errors in the Rust 2021 edition. r? `@estebank`
- Loading branch information
Showing
48 changed files
with
541 additions
and
196 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"), | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.