Skip to content

Commit eb7c3b6

Browse files
authored
Merge pull request #450 from rust-lang/KodrAus-patch-1
Updates to Libs docs
2 parents f0b6292 + b8a36dc commit eb7c3b6

File tree

2 files changed

+69
-17
lines changed

2 files changed

+69
-17
lines changed

src/libs/README.md

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,9 @@ This section documents meta processes by the Libs team.
44

55
## Where to find us
66

7-
The libs team hangs out primarily in [the rust-lang Zulip](https://rust-lang.zulipchat.com/) these days in the `#t-libs` stream.
7+
The [`rust-lang/libs-team`](https://github.com/rust-lang/libs-team) GitHub repository is the home of the Libs team.
8+
It has details on current project groups, upcoming meetings, and the status of tracking issues.
89

9-
You can also find out more details about [Zulip and how the Rust community uses it](../../platforms/zulip.html).
10-
11-
## Useful GitHub queries
10+
The Libs team hangs out primarily in [the rust-lang Zulip](https://rust-lang.zulipchat.com/) these days in the `#t-libs` stream.
1211

13-
The Libs team does its work in a number of repositories throughout the `rust-lang` organization and others on GitHub.
14-
15-
| Query | Description |
16-
|----------|------ |
17-
| [Open Libs RFCs](https://github.com/rust-lang/rfcs/pulls?q=is%3Apr+is%3Aopen+label%3AT-libs) | RFCs that need input from the Libs team. |
18-
| [Open Libs PRs](https://github.com/rust-lang/rust/pulls?q=is%3Apr+is%3Aopen+label%3AT-libs) | PRs that need input from the Libs team. |
12+
You can also find out more details about [Zulip and how the Rust community uses it](../../platforms/zulip.html).

src/libs/maintaining-std.md

Lines changed: 65 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -169,14 +169,70 @@ Blanket trait impls can't be added to `#[fundamental]` types because they have d
169169

170170
### Is specialization involved?
171171

172-
[#68358]: https://github.com/rust-lang/rust/pull/68358
173-
[#67194]: https://github.com/rust-lang/rust/issues/67194
174-
[lang_design_specialization]: https://paper.dropbox.com/doc/Specialization-Review-2020-02-03--AuBwAqGbsHDmBlBy~XUlmqUcAg-jFYgiknJi6j00SbN83dWX
175-
176-
**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].
177173

178174
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.
179175

176+
As an example of how to use specialization in the standard library, consider the case of creating an `Rc<[T]>` from a `&[T]`:
177+
178+
```rust
179+
impl<T: Clone> From<&[T]> for Rc<[T]> {
180+
#[inline]
181+
fn from(v: &[T]) -> Rc<[T]> {
182+
unsafe { Self::from_iter_exact(v.iter().cloned(), v.len()) }
183+
}
184+
}
185+
```
186+
187+
It would be nice to have an optimized implementation for the case where `T: Copy`:
188+
189+
```rust
190+
impl<T: Copy> From<&[T]> for Rc<[T]> {
191+
#[inline]
192+
fn from(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:
199+
200+
```rust
201+
impl<T: Clone> From<&[T]> for Rc<[T]> {
202+
#[inline]
203+
fn from(v: &[T]) -> Rc<[T]> {
204+
<Self as RcFromSlice<T>>::from_slice(v)
205+
}
206+
}
207+
208+
/// Specialization trait used for `From<&[T]>`.
209+
trait RcFromSlice<T> {
210+
fn from_slice(slice: &[T]) -> Self;
211+
}
212+
213+
impl<T: Clone> RcFromSlice<T> for Rc<[T]> {
214+
#[inline]
215+
default fn from_slice(v: &[T]) -> Self {
216+
unsafe { Self::from_iter_exact(v.iter().cloned(), v.len()) }
217+
}
218+
}
219+
220+
impl<T: Copy> RcFromSlice<T> for Rc<[T]> {
221+
#[inline]
222+
fn from_slice(v: &[T]) -> Self {
223+
unsafe { Self::copy_from_slice(v) }
224+
}
225+
}
226+
```
227+
228+
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+
180236
### Are there public enums?
181237

182238
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
251307

252308
For Libs PRs, rolling up is usually fine, in particular if it's only a new unstable addition or if it only touches docs.
253309

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.
255311

256312
### When there’s new public items
257313

258314
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.
259315

260316
Unstable features can be merged as normal through [`bors`] once they look ready.
261317

262-
### When theres new trait impls
318+
### When there's new trait impls
263319

264320
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.
265321

@@ -298,5 +354,7 @@ Where `unsafe` and `const` is involved, e.g., for operations which are "unconst"
298354
[Everyone Poops]: http://cglab.ca/~abeinges/blah/everyone-poops
299355
[rust/pull/46799]: https://github.com/rust-lang/rust/pull/46799
300356
[rust/issues/76367]: https://github.com/rust-lang/rust/issues/76367
357+
[rust/issues/31844]: https://github.com/rust-lang/rust/issues/31844
358+
[rust/issues/44580]: https://github.com/rust-lang/rust/issues/44580
301359
[hashbrown/pull/119]: https://github.com/rust-lang/hashbrown/pull/119
302360
[rollup guidelines]: ../compiler/reviews.md#rollups

0 commit comments

Comments
 (0)