Skip to content

Commit 4422a5c

Browse files
authored
Merge pull request #27 from Amanieu/prelude
Notes on making breaking changes to the prelude
2 parents 5a93e16 + af87c09 commit 4422a5c

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
- [Breakage from changing behavior](./code-considerations/breaking-changes/behavior.md)
2525
- [Breakage from new trait impls](./code-considerations/breaking-changes/new-trait-impls.md)
2626
- [`#[fundamental]` types](./code-considerations/breaking-changes/fundamental.md)
27+
- [Breakage from changing the prelude](./code-considerations/breaking-changes/prelude.md)
2728
- [Safety and soundness](./code-considerations/safety-and-soundness/summary.md)
2829
- [Generics and unsafe](./code-considerations/safety-and-soundness/generics-and-unsafe.md)
2930
- [Drop and `#[may_dangle]`](./code-considerations/safety-and-soundness/may-dangle.md)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Breaking changes to the prelude
2+
3+
Making changes to the prelude can easily cause breakage because it impacts all Rust code. In most cases the impact is limited since prelude items have the lowest priority in name lookup (lower than glob imports), but there are two cases where this doesn't work.
4+
5+
## Traits
6+
7+
Adding a new trait to the prelude causes new methods to become available for existing types. This can cause name resolution errors in user code if a method with the same name is also available from a different trait.
8+
9+
For this reason, [`TryFrom` and `TryInto`](https://github.com/rust-lang/rust/issues/33417) were only added to the prelude for the 2021 edition despite being stabilized in 2019.
10+
11+
## Macros
12+
13+
Unlike other item types, rustc's name resolution for macros does not support giving prelude macros a lower priority than other macros, even if the macro is unstable. As a general rule, avoid adding macros to the prelude except at edition boundaries.
14+
15+
This issues was encoutered when trying to land the [`assert_matches!` macro](https://github.com/rust-lang/rust/issues/82913).

0 commit comments

Comments
 (0)