You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/breaking-changes/prelude.md
+11-1
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
# Breaking changes to the prelude
2
2
3
3
Making changes to the prelude can easily cause breakage because it impacts all Rust code.
4
-
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
+
In most cases the impact is limited since prelude items have the lowest priority in name lookup (lower than glob imports), but there are three cases where this requires additional care or may not be possible.
5
5
6
6
## Traits
7
7
@@ -16,3 +16,13 @@ Unlike other item types, rustc's name resolution for macros does not support giv
16
16
As a general rule, avoid adding macros to the prelude except at edition boundaries.
17
17
18
18
This issues was encoutered when trying to land the [`assert_matches!` macro](https://github.com/rust-lang/rust/issues/82913).
19
+
20
+
## Types
21
+
22
+
Adding a new type usually doesn't create any breakage, because prelude types have a lower priority than names in user code.
23
+
24
+
However, code that declares an enum, *and* has a derive on that enum, *and* attempts to locally import a variant from that enum (e.g. `use EnumType::Variant;`) will break if the prelude starts exporting a type with the same name as that enum.
25
+
26
+
This makes adding a new type to the prelude require a crater run to check for breakage in existing Rust code.
27
+
28
+
If Rust code declares a local variable binding and the prelude adds a type of the same name, this can likewise introduce breakage. This case is much less likely to arise, as it requires declaring a variable name using the `CamelCase` convention typically used for types, and ignoring rustc's warnings about doing so.
0 commit comments