Skip to content

Commit 8ef36b8

Browse files
authored
Merge pull request #56 from rust-lang/update
Reorganise and clean up the whole guide.
2 parents 7d27d1d + ced20ea commit 8ef36b8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+164
-458
lines changed

book.toml

+3
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,6 @@ renderer = ["html"]
2222
git-repository-icon = "fa-github"
2323
git-repository-url = "https://github.com/rust-lang/std-dev-guide"
2424
edit-url-template = "https://github.com/rust-lang/std-dev-guide/edit/master/{path}"
25+
26+
[output.html.redirect]
27+
"/feature-lifecycle/stabilization.html" = "/development/stabilization.html"

src/SUMMARY.md

+28-58
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,30 @@
11
# Summary
22

3-
[About this guide](./about-this-guide.md)
4-
5-
[Getting started](./getting-started.md)
6-
7-
- [The library team](./team.md)
8-
- [Meetings](./meetings.md)
9-
- [Membership](./membership.md)
10-
- [Reviewing](./reviewing.md)
11-
12-
---
13-
14-
- [Building and debugging libraries](./development/building-and-debugging.md)
15-
- [Performance optimizations and benchmarking](./development/perf-benchmarking.md)
16-
17-
18-
---
19-
20-
- [The feature lifecycle](./feature-lifecycle/summary.md)
21-
- [API Change Proposals](./feature-lifecycle/api-change-proposals.md)
22-
- [Using tracking issues](./feature-lifecycle/tracking-issues.md)
23-
- [Stabilizing features](./feature-lifecycle/stabilization.md)
24-
- [Deprecating features](./feature-lifecycle/deprecation.md)
25-
26-
---
27-
28-
- [Code considerations](./code-considerations/summary.md)
29-
- [Design](./code-considerations/design/summary.md)
30-
- [Public APIs](./code-considerations/design/public-apis.md)
31-
- [When to add `#[must_use]`](./code-considerations/design/must-use.md)
32-
- [Breaking changes](./code-considerations/breaking-changes/summary.md)
33-
- [Breakage from changing behavior](./code-considerations/breaking-changes/behavior.md)
34-
- [Breakage from new trait impls](./code-considerations/breaking-changes/new-trait-impls.md)
35-
- [`#[fundamental]` types](./code-considerations/breaking-changes/fundamental.md)
36-
- [Breakage from changing the prelude](./code-considerations/breaking-changes/prelude.md)
37-
- [Safety and soundness](./code-considerations/safety-and-soundness/summary.md)
38-
- [Generics and unsafe](./code-considerations/safety-and-soundness/generics-and-unsafe.md)
39-
- [Drop and `#[may_dangle]`](./code-considerations/safety-and-soundness/may-dangle.md)
40-
- [`std::mem` and exclusive references](./code-considerations/safety-and-soundness/mem-and-exclusive-refs.md)
41-
- [Using unstable language features](./code-considerations/using-unstable-lang/summary.md)
42-
- [Const generics](./code-considerations/using-unstable-lang/const-generics.md)
43-
- [Specialization](./code-considerations/using-unstable-lang/specialization.md)
44-
- [Performance](./code-considerations/performance/summary.md)
45-
- [When to `#[inline]`](./code-considerations/performance/inline.md)
46-
47-
---
48-
49-
- [Documentation](./documentation/summary.md)
50-
- [doc alias policy](./documentation/doc-alias-policy.md)
51-
- [safety comments policy](./documentation/safety-comments.md)
52-
- [how to write documentation](./documentation/how-to-write-documentation.md)
53-
- [reviewing doc changes](./documentation/reviewing-doc-changes.md)
54-
55-
---
56-
57-
- [Tools and bots](./tools-and-bots/summary.md)
58-
- [`@bors`](./tools-and-bots/bors.md)
59-
- [`@rust-timer`](./tools-and-bots/timer.md)
60-
- [`@craterbot`](./tools-and-bots/crater.md)
3+
- [About this Guide](about.md)
4+
5+
- [Contributing to the standard libraries]()
6+
- [Building and debugging](./development/building-and-debugging.md)
7+
- [Performance optimizations and benchmarking](./development/perf-benchmarking.md)
8+
- [Writing documentation](./development/how-to-write-documentation.md)
9+
- [Stabilizing a feature](./development/stabilization.md)
10+
11+
- [Breaking changes](./breaking-changes/summary.md)
12+
- [New trait implementations](./breaking-changes/new-trait-impls.md)
13+
- [Prelude](./breaking-changes/prelude.md)
14+
- [Doc changes](./breaking-changes/doc-changes.md)
15+
16+
- [Policies]()
17+
- [When to add `#[must_use]`](./policy/must-use.md)
18+
- [Specialization](./policy/specialization.md)
19+
- [When to `#[inline]`](./policy/inline.md)
20+
- [Doc alias policy](./policy/doc-alias.md)
21+
- [Safety comments policy](./policy/safety-comments.md)
22+
23+
- [Tricky situations]()
24+
- [Drop and `#[may_dangle]`](./tricky/may-dangle.md)
25+
- [Generics and unsafe](./tricky/generics-and-unsafe.md)
26+
27+
- [The library team](./team/summary.md)
28+
- [Meetings](./team/meetings.md)
29+
- [Membership](./team/membership.md)
30+
- [Reviewing](./team/reviewing.md)

src/about-this-guide.md

-19
This file was deleted.

src/about.md

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# About this Guide
2+
3+
Welcome to the std dev guide.
4+
5+
This guide is maintained by the library team.
6+
7+
The guide is not very complete yet.
8+
Contributions to this guide are very welcome.
9+
10+
Other useful documentation:
11+
12+
- https://forge.rust-lang.org/
13+
- https://rustc-dev-guide.rust-lang.org/

src/documentation/reviewing-doc-changes.md renamed to src/breaking-changes/doc-changes.md

+1-10
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,4 @@
1-
# Reviewing doc changes
2-
3-
Most of the time, it is mostly reviewing that the documentation isn't wrong
4-
in any way and that it follows the
5-
[how to write documentation](./how-to-write-documentation.md) guideline.
6-
7-
There is however something where we need to be extra careful: stability
8-
guarantees.
9-
10-
## Stability guarantees
1+
# Breaking documentation changes
112

123
First, short explanation about what a stability guarantee is: a statement in
134
the document which explains what the item is doing in a precise case. For
+93
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# Breakage from new trait impls
2+
3+
A lot of PRs to the standard library are adding new impls for already stable traits,
4+
which can break consumers in many weird and wonderful ways.
5+
Below are some examples of breakage from new trait impls that
6+
may not be obvious just from the change made to the standard library.
7+
8+
## Inference breaks when a second generic impl is introduced
9+
10+
Rust will use the fact that there's only a single impl for a generic trait during inference.
11+
This breaks once a second impl makes the type of that generic ambiguous.
12+
Say we have:
13+
14+
```rust,ignore
15+
// in `std`
16+
impl From<&str> for Arc<str> { .. }
17+
```
18+
19+
```rust,ignore
20+
// in an external `lib`
21+
let b = Arc::from("a");
22+
```
23+
24+
then we add:
25+
26+
```diff
27+
impl From<&str> for Arc<str> { .. }
28+
+ impl From<&str> for Arc<String> { .. }
29+
```
30+
31+
then
32+
33+
```rust,ignore
34+
let b = Arc::from("a");
35+
```
36+
37+
will no longer compile, because we've previously been relying on inference to figure out the `T` in `Box<T>`.
38+
39+
This kind of breakage can be ok, but a [crater](https://github.com/rust-lang/crater/blob/master/docs/bot-usage.md) run should estimate the scope.
40+
41+
## Deref coercion breaks when a new impl is introduced
42+
43+
Rust will use deref coercion to find a valid trait impl if the arguments don't type check directly.
44+
This only seems to occur if there's a single impl so introducing a new one may break consumers relying on deref coercion.
45+
Say we have:
46+
47+
```rust,ignore
48+
// in `std`
49+
impl Add<&str> for String { .. }
50+
51+
impl Deref for String { type Target = str; .. }
52+
```
53+
54+
```rust,ignore
55+
// in an external `lib`
56+
let a = String::from("a");
57+
let b = String::from("b");
58+
59+
let c = a + &b;
60+
```
61+
62+
then we add:
63+
64+
```diff,ignore
65+
impl Add<&str> for String { .. }
66+
+ impl Add<char> for String { .. }
67+
```
68+
69+
then
70+
71+
```rust,ignore
72+
let c = a + &b;
73+
```
74+
75+
will no longer compile, because we won't attempt to use deref to coerce the `&String` into `&str`.
76+
77+
This kind of breakage can be ok, but a [crater](https://github.com/rust-lang/crater/blob/master/docs/bot-usage.md) run should estimate the scope.
78+
79+
## `#[fundamental]` types
80+
81+
Type annotated with the `#[fundamental]` attribute have different coherence rules.
82+
See [RFC 1023](https://rust-lang.github.io/rfcs/1023-rebalancing-coherence.html) for details.
83+
That includes:
84+
85+
- `&T`
86+
- `&mut T`
87+
- `Box<T>`
88+
- `Pin<T>`
89+
90+
Typically, the scope of breakage in new trait impls is limited to inference and deref-coercion.
91+
New trait impls on `#[fundamental]` types may overlap with downstream impls and cause other kinds of breakage.
92+
93+
[RFC 1023]: https://rust-lang.github.io/rfcs/1023-rebalancing-coherence.html
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
# Breaking changes to the prelude
22

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

56
## Traits
67

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+
Adding a new trait to the prelude causes new methods to become available for existing types.
9+
This can cause name resolution errors in user code if a method with the same name is also available from a different trait.
810

911
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.
1012

1113
## Macros
1214

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.
15+
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.
16+
As a general rule, avoid adding macros to the prelude except at edition boundaries.
1417

1518
This issues was encoutered when trying to land the [`assert_matches!` macro](https://github.com/rust-lang/rust/issues/82913).

src/breaking-changes/summary.md

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Breaking changes
2+
3+
Breaking changes should be avoided when possible.
4+
[RFC 1105](https://rust-lang.github.io/rfcs/1105-api-evolution.html) lays the foundations for what constitutes a breaking change.
5+
Breakage may be deemed acceptable or not based on its actual impact,
6+
which can be approximated with a [crater](https://github.com/rust-lang/crater/blob/master/docs/bot-usage.md) run.
7+
8+
If the impact isn't too high, looping in maintainers of broken crates and submitting PRs to fix them can be a valid strategy.

src/code-considerations/breaking-changes/behavior.md

-9
This file was deleted.

src/code-considerations/breaking-changes/fundamental.md

-31
This file was deleted.

src/code-considerations/breaking-changes/new-trait-impls.md

-76
This file was deleted.

0 commit comments

Comments
 (0)