]> git.proxmox.com Git - rustc.git/blob - src/doc/edition-guide/src/rust-2021/warnings-promoted-to-error.md
New upstream version 1.55.0+dfsg1
[rustc.git] / src / doc / edition-guide / src / rust-2021 / warnings-promoted-to-error.md
1 # Warnings promoted to errors
2
3 ## Summary
4
5 - Code that triggered the `bare_trait_objects` and `ellipsis_inclusive_range_patterns` lints will error in Rust 2021.
6
7 ## Details
8
9 Two existing lints are becoming hard errors in Rust 2021, but these lints will remain warnings in older editions.
10
11 ### `bare_trait_objects`:
12
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`.