Skip to content

Commit 230995c

Browse files
committed
Add Rust 2021 prelude migration details
1 parent 86cdd2b commit 230995c

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

src/rust-2021/prelude.md

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,26 @@ It's identical to the current one, except for three new additions:
3131
- [`std::convert::TryFrom`](https://doc.rust-lang.org/stable/std/convert/trait.TryFrom.html)
3232
- [`std::iter::FromIterator`](https://doc.rust-lang.org/stable/std/iter/trait.FromIterator.html)
3333

34-
The library team still needs to formally approve these, which will likely happen soon.
35-
<!-- TODO: hopefully this happens before we publish this -->
34+
The tracking issue [can be found here](https://github.com/rust-lang/rust/issues/85684).
35+
36+
## Migration
37+
38+
As a part of the 2021 edition a migration lint, currently `future_prelude_collision`, has been added in order to aid in automatic migration of Rust 2018 codebases to Rust 2021.
39+
40+
### Implementation Reference
41+
42+
The lint needs to take a couple of factors into account when determining whether or not introducing 2021 Edition to a codebase will cause a name resolution collision (thus breaking the code after changing edition). These factors include:
43+
44+
- Is the call a [fully-qualified call] or does it use [dot-call method syntax]?
45+
- This will affect how the name is resolved due to auto-reference and auto-dereferencing on method call syntax. Manually dereferencing/referencing will allow specifying priority in the case of dot-call method syntax, while fully-qualified call requires specification of the type and the trait name in the method path (e.g. `<Type as Trait>::method`)
46+
- Is this an [inherent method] or [a trait method]?
47+
- Inherent methods that take `self` will take priority over `TryInto::try_into` as inherent methods take priority over trait methods, but inherent methods that take `&self` or `&mut self` won't take priority due to requiring a auto-reference (while `TryInto::try_into` does not, as it takes `self`)
48+
- Is the origin of this method from `core`/`std`? (As the traits can't have a collision with themselves)
49+
- Does the given type implement the trait it could have a collision against?
50+
- Is the method being called via dynamic dispatch? (i.e. is the `self` type `dyn Trait`)
51+
- If so, trait imports don't affect resolution, and no migration lint needs to occur
52+
53+
[fully qualified call]: https://doc.rust-lang.org/reference/expressions/call-expr.html#disambiguating-function-calls
54+
[dot-call method syntax]: https://doc.rust-lang.org/reference/expressions/method-call-expr.html
55+
[inherent method]: https://doc.rust-lang.org/reference/items/implementations.html#inherent-implementations
56+
[a trait method]: https://doc.rust-lang.org/reference/items/implementations.html#trait-implementations

0 commit comments

Comments
 (0)