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/libs/maintaining-std.md
+13-8Lines changed: 13 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -61,8 +61,6 @@ You should just about never need `#[inline(always)]`. It may be beneficial for p
61
61
62
62
Breaking changes should be avoided when possible. [RFC 1105] lays the foundations for what constitutes a breaking change. Breakage may be deemed acceptable or not based on its actual impact, which can be approximated with a [`crater`] run.
63
63
64
-
#### Managing breakage
65
-
66
64
There are strategies for mitigating breakage depending on the impact.
67
65
68
66
For changes where the value is high and the impact is high too:
@@ -73,11 +71,11 @@ If the impact isn't too high:
73
71
74
72
- Looping in maintainers of broken crates and submitting PRs to fix them.
75
73
76
-
#### Trait impls break things
74
+
###Are there new impls for stable traits?
77
75
78
-
The following sections outline some kinds of breakage from new trait impls that may not be obvious just from the change made to the standard library.
76
+
A lot of PRs to the standard library are adding new impls for already stable traits, which can break consumers in many weird and wonderful ways. The following sections gives some examples of breakage from new trait impls that may not be obvious just from the change made to the standard library.
79
77
80
-
#####Inference breaks when a second generic impl is introduced
78
+
#### Inference breaks when a second generic impl is introduced
81
79
82
80
Rust will use the fact that there's only a single impl for a generic trait during inference. This breaks once a second impl makes the type of that generic ambiguous. Say we have:
83
81
@@ -108,7 +106,7 @@ will no longer compile, because we've previously been relying on inference to fi
108
106
109
107
This kind of breakage can be ok, but a [`crater`] run should estimate the scope.
110
108
111
-
#####Deref coercion breaks when a new impl is introduced
109
+
#### Deref coercion breaks when a new impl is introduced
112
110
113
111
Rust will use deref coercion to find a valid trait impl if the arguments don't type check directly. This only seems to occur if there's a single impl so introducing a new one may break consumers relying on deref coercion. Say we have:
114
112
@@ -144,6 +142,10 @@ will no longer compile, because we won't attempt to use deref to coerce the `&St
144
142
145
143
This kind of breakage can be ok, but a [`crater`] run should estimate the scope.
146
144
145
+
### Could an implementation use existing functionality?
146
+
147
+
Types like `String` are implemented in terms of `Vec<u8>` and can use methods on `str` through deref coersion. `Vec<T>` can use methods on `[T]` through deref coersion. When possible, methods on a wrapping type like `String` should defer to methods that already exis on their underlying storage or deref target.
148
+
147
149
### Are there `#[fundamental]` items involved?
148
150
149
151
Blanket trait impls can't be added to `#[fundamental]` types because they have different coherence rules. See [RFC 1023] for details. That includes:
@@ -165,7 +167,7 @@ Changes to collection internals may affect the order their items are dropped in.
165
167
166
168
#### `mem::replace` and `mem::swap`
167
169
168
-
Any value behind a `&mut` reference can be replaced with a new one using `mem::replace` or `mem::swap`.
170
+
Any value behind a `&mut` reference can be replaced with a new one using `mem::replace` or `mem::swap`, so code shouldn't assume any reachable mutable references can't have their internals changed by replacing.
169
171
170
172
#### `mem::forget`
171
173
@@ -199,12 +201,14 @@ Unstable features can be merged as normal through [`bors`] once they look ready.
199
201
200
202
### When there’s new trait impls
201
203
202
-
There’s no way to make a trait impl `#[unstable]`, so **any PRs that add new impls for already stable traits must go through a FCP before merging.** If the trait itself is unstable though, then the impl needs to be unstable too.
204
+
There’s no way to make a trait impl for a stable trait unstable, so **any PRs that add new impls for already stable traits must go through a FCP before merging.** If the trait itself is unstable though, then the impl needs to be unstable too.
203
205
204
206
### When a feature is being stabilized
205
207
206
208
Features can be stabilized in a PR that replaces `#[unstable]` attributes with `#[stable]` ones. The feature needs to have an accepted RFC before stabilizing. They also need to go through a FCP before merging.
207
209
210
+
You can find the right version to use in the `#[stable]` attribute by checking the [Forge].
0 commit comments