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
**NOTE(2019-02-10):** Due to recent soundness holes introduced by specialization in the standard library (c.f. [#68358] and [#67194]) the language team decided on a design meeting to place a moratorium on new uses of specialization until we have some checks in place ensuring soundness for internal uses.
172
+
Specialization is currently unstable. You can track its progress [here][rust/issues/31844].
177
173
178
174
We try to avoid leaning on specialization too heavily, limiting its use to optimizing specific implementations. These specialized optimizations use a private trait to find the correct implementation, rather than specializing the public method itself. Any use of specialization that changes how methods are dispatched for external callers should be carefully considered.
179
175
176
+
As an example of how to use specialization in the standard library, consider the case of creating an `Rc<[T]>` from a `&[T]`:
It would be nice to have an optimized implementation for the case where `T: Copy`:
188
+
189
+
```rust
190
+
impl<T:Copy> From<&[T]> forRc<[T]> {
191
+
#[inline]
192
+
fnfrom(v:&[T]) ->Rc<[T]> {
193
+
unsafe { Self::copy_from_slice(v) }
194
+
}
195
+
}
196
+
```
197
+
198
+
Unfortunately we couldn't have both of these impls normally, because they'd overlap. This is where private specialization can be used to choose the right implementation internally. In this case, we use a trait called `RcFromSlice` that switches the implementation:
Only specialization using the `min_specialization` feature should be used. The full `specialization` feature is known to be unsound.
229
+
230
+
### Are const generics involved?
231
+
232
+
Const generics are currently unstable. You can track their progress [here][rust/issues/44580].
233
+
234
+
Using const generics in public APIs is ok, but only const generics using the `min_const_generics` feature should be used publicly for now.
235
+
180
236
### Are there public enums?
181
237
182
238
Public enums should have a `#[non_exhaustive]` attribute if there's any possibility of new variants being introduced, so that they can be added without causing breakage.
@@ -251,15 +307,15 @@ PRs to [`rust-lang/rust`] aren’t merged manually using GitHub’s UI or by pus
251
307
252
308
For Libs PRs, rolling up is usually fine, in particular if it's only a new unstable addition or if it only touches docs.
253
309
254
-
See the [rollup guidelines] for more details on when to rollup.
310
+
See the [rollup guidelines] for more details on when to rollup. The idea is to try collect a number of PRs together and merge them all at once, rather than individually. This can get things merged faster, but might not be appropriate for some PRs that are likely to conflict, or have performance characteristics that would be obscured in a rollup.
255
311
256
312
### When there’s new public items
257
313
258
314
If the feature is new, then a tracking issue should be opened for it. Have a look at some previous [tracking issues][Libs tracking issues] to get an idea of what needs to go in there. The `issue` field on `#[unstable]` attributes should be updated with the tracking issue number.
259
315
260
316
Unstable features can be merged as normal through [`bors`] once they look ready.
261
317
262
-
### When there’s new trait impls
318
+
### When there's new trait impls
263
319
264
320
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.
265
321
@@ -298,5 +354,7 @@ Where `unsafe` and `const` is involved, e.g., for operations which are "unconst"
0 commit comments