|
2 | 2 |
|
3 | 3 | ## Summary
|
4 | 4 |
|
5 |
| -- `bare-trait-objects` and `ellipsis-inclusive-range-patters` are now hard errors. |
| 5 | +- Code that triggered the `bare_trait_objects` and `ellipsis_inclusive_range_patterns` lints will error in Rust 2021. |
6 | 6 |
|
7 | 7 | ## Details
|
8 | 8 |
|
9 |
| -Two existing lints are becoming hard errors in Rust 2021. |
10 |
| -These lints will remain warnings in older editions. |
| 9 | +Two existing lints are becoming hard errors in Rust 2021, but these lints will remain warnings in older editions. |
11 | 10 |
|
12 |
| -* `bare-trait-objects`: |
13 |
| - The use of the `dyn` keyword to identify [trait objects](https://doc.rust-lang.org/book/ch17-02-trait-objects.html) |
14 |
| - will be mandatory in Rust 2021. |
| 11 | +### `bare_trait_objects`: |
15 | 12 |
|
16 |
| -* `ellipsis-inclusive-range-patterns`: |
17 |
| - The [deprecated `...` syntax](https://doc.rust-lang.org/stable/reference/patterns.html#range-patterns) |
18 |
| - for inclusive range patterns is no longer accepted in Rust 2021. |
19 |
| - It has been superseded by `..=`, which is consistent with expressions. |
| 13 | +The use of the `dyn` keyword to identify [trait objects](https://doc.rust-lang.org/book/ch17-02-trait-objects.html) |
| 14 | +will be mandatory in Rust 2021. |
| 15 | + |
| 16 | +For example, the following code which does not include the `dyn` keyword in `&MyTrait` |
| 17 | +will produce an error instead of just a lint in Rust 2021: |
| 18 | + |
| 19 | +```rust |
| 20 | +pub trait MyTrait {} |
| 21 | + |
| 22 | +pub fn my_function(_trait_object: &MyTrait) { // should be `&dyn MyTrait` |
| 23 | + unimplemented!() |
| 24 | +} |
| 25 | +``` |
| 26 | + |
| 27 | +### `ellipsis_inclusive_range_patterns`: |
| 28 | + |
| 29 | +The [deprecated `...` syntax](https://doc.rust-lang.org/stable/reference/patterns.html#range-patterns) |
| 30 | +for inclusive range patterns (i.e., ranges where the end value is *included* in the range) is no longer |
| 31 | +accepted in Rust 2021. It has been superseded by `..=`, which is consistent with expressions. |
| 32 | + |
| 33 | +For example, the following code which uses `...` in a pattern will produce an error instead of |
| 34 | +just a lint in Rust 2021: |
| 35 | + |
| 36 | +```rust |
| 37 | +pub fn less_or_eq_to_100(n: u8) -> bool { |
| 38 | + matches!(n, 0...100) // should be `0..=100` |
| 39 | +} |
| 40 | +``` |
| 41 | + |
| 42 | +## Migrations |
| 43 | + |
| 44 | +If your Rust 2015 or 2018 code does not produce any warnings for `bare_trait_objects` |
| 45 | +or `ellipsis_inclusive_range_patterns` and you've not allowed these lints through the |
| 46 | +use of `#![allow()]` or some other mechanism, then there's no need to migrate. |
| 47 | + |
| 48 | +To automatically migrate any crate that uses `...` in patterns or does not use `dyn` with |
| 49 | +trait objects, you can run `cargo fix --edition`. |
0 commit comments