Skip to content

Commit 5d57b38

Browse files
authored
Merge pull request #247 from rylev/more-info-warnings-error
Add more info for warnings promoted to errors
2 parents 86cdd2b + 70ac237 commit 5d57b38

File tree

1 file changed

+40
-10
lines changed

1 file changed

+40
-10
lines changed

src/rust-2021/warnings-promoted-to-error.md

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,48 @@
22

33
## Summary
44

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.
66

77
## Details
88

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.
1110

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`:
1512

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

Comments
 (0)