Skip to content

Commit 5f1a989

Browse files
authored
Merge branch 'master' into transparent-enum
2 parents b247e4e + e8f420d commit 5f1a989

29 files changed

+295
-88
lines changed

.github/workflows/main.yml

+5-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
- name: Install mdbook
1818
run: |
1919
mkdir bin
20-
curl -sSL https://github.com/rust-lang/mdBook/releases/download/v0.3.4/mdbook-v0.3.4-x86_64-unknown-linux-gnu.tar.gz | tar -xz --directory=bin
20+
curl -sSL https://github.com/rust-lang/mdBook/releases/download/v0.3.5/mdbook-v0.3.5-x86_64-unknown-linux-gnu.tar.gz | tar -xz --directory=bin
2121
echo "##[add-path]$(pwd)/bin"
2222
- name: Report versions
2323
run: |
@@ -29,4 +29,7 @@ jobs:
2929
- name: Check for unstable features
3030
run: (cd stable-check && cargo run -- ../src)
3131
- name: Check for broken links
32-
run: tests/linkcheck.sh
32+
run: |
33+
curl -sSLo linkcheck.sh \
34+
https://raw.githubusercontent.com/rust-lang/rust/master/src/tools/linkchecker/linkcheck.sh
35+
sh linkcheck.sh --all reference

CONTRIBUTING.md

+7
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ for the Reference. As such, we have the warning saying there's work that needs
1414
to be done. Eventually, we plan to make sure everything is well documented
1515
enough that we can remove the warning.
1616

17+
It is encouraged for you to read the [introduction] to familiarize yourself
18+
with the kind of content the reference is expected to contain and the
19+
conventions it uses. Also, the [style guide] provides more detailed guidelines
20+
for formatting and content.
21+
1722
## Critiquing the Reference
1823

1924
This is the easiest way to contribute. Basically, as you read the reference, if
@@ -63,7 +68,9 @@ This should include links to any relevant information, such as the
6368
stabilization PR, the RFC, the tracking issue, and anything else that would be
6469
helpful for writing the documentation.
6570

71+
[introduction]: src/introduction.md
6672
[issue tracker]: https://github.com/rust-lang/reference/issues
6773
[playpen]: https://play.rust-lang.org/
6874
[rust-lang/rust]: https://github.com/rust-lang/rust/
75+
[style guide]: STYLE.md
6976
[unstable]: https://doc.rust-lang.org/nightly/unstable-book/

STYLE.md

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# Rust reference style guide
2+
3+
Some conventions and content guidelines are specified in the [introduction].
4+
This document serves as a guide for editors and reviewers.
5+
6+
## Markdown formatting
7+
8+
* Use ATX-style heading with sentence case.
9+
* Wrap long lines, preferably at 80-columns.
10+
* Use reference links, with shortcuts if appropriate. Place the sorted link
11+
reference definitions at the bottom of the file, or at the bottom of a
12+
section if there is an unusually large number of links that are specific to
13+
the section.
14+
15+
```
16+
Example of shortcut link: [enumerations]
17+
Example of reference link with label: [block expression][block]
18+
19+
[block]: expressions/block-expr.md
20+
[enumerations]: types/enum.md
21+
```
22+
23+
* Links should be relative with the `.md` extension. Links to other rust-lang
24+
books that are published with the reference or the standard library API
25+
should also be relative so that the linkchecker can validate them.
26+
* See the [Conventions] section for formatting callouts such as notes, edition
27+
differences, and warnings.
28+
* Formatting to avoid:
29+
* Avoid trailing spaces.
30+
* Avoid double blank lines.
31+
32+
### Code examples
33+
34+
Code examples should use code blocks with triple backticks. The language
35+
should always be specified (such as `rust`).
36+
37+
```rust
38+
println!("Hello!");
39+
```
40+
41+
See https://highlightjs.org/ for a list of supported languages.
42+
43+
Rust examples are tested via rustdoc, and should include the appropriate
44+
annotations when tests are expected to fail:
45+
46+
* `edition2018` — If it is edition-specific.
47+
* `no_run` — The example should compile successfully, but should not be
48+
executed.
49+
* `should_panic` — The example should compile and run, but produce a panic.
50+
* `compile_fail` — The example is expected to fail to compile.
51+
* `ignore` — The example shouldn't be built or tested. This should be avoided
52+
if possible. Usually this is only necessary when the testing framework does
53+
not support it (such as external crates or modules, or a proc-macro), or it
54+
contains psuedo-code which is not valid Rust. An HTML comment such as
55+
`<!-- ignore: requires extern crate -->` should be placed before the example
56+
to explain why it is ignored.
57+
58+
See the [rustdoc documentation] for more detail.
59+
60+
## Language and grammar
61+
62+
* Use American English spelling.
63+
* Use Oxford commas.
64+
* Idioms and styling to avoid:
65+
* Avoid slashes for alternatives ("program/binary"), use conjunctions or
66+
rewrite it ("program or binary").
67+
* Avoid qualifying something as "in Rust", the entire reference is about
68+
Rust.
69+
70+
## Content
71+
72+
* Whenever there is a difference between editions, the differences should be
73+
called out with an "Edition Differences" block. The main text should stick
74+
to what is common between the editions. However, for large differences (such
75+
as "async"), the main text may contain edition-specific content as long as
76+
it is made clear which editions it applies to.
77+
78+
[conventions]: src/introduction.md#conventions
79+
[introduction]: src/introduction.md
80+
[rustdoc documentation]: https://doc.rust-lang.org/rustdoc/documentation-tests.html

src/attributes.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ Attributes may be applied to many things in the language:
5050
* [Generic lifetime or type parameter][generics] accept outer attributes.
5151
* Expressions accept outer attributes in limited situations, see [Expression
5252
Attributes] for details.
53-
* [Function][functions], [closure]] and [function pointer]
53+
* [Function][functions], [closure] and [function pointer]
5454
parameters accept outer attributes. This includes attributes on variadic parameters
5555
denoted with `...` in function pointers and [external blocks][variadic functions].
5656

@@ -187,6 +187,8 @@ The following is an index of all built-in attributes.
187187
- [`should_panic`] — Indicates a test should generate a panic.
188188
- Derive
189189
- [`derive`] — Automatic trait implementations.
190+
- [`automatically_derived`] — Marker for implementations created by
191+
`derive`.
190192
- Macros
191193
- [`macro_export`] — Exports a `macro_rules` macro for cross-crate usage.
192194
- [`macro_use`] — Expands macro visibility, or imports macros from other
@@ -255,6 +257,7 @@ The following is an index of all built-in attributes.
255257
[_LiteralExpression_]: expressions/literal-expr.md
256258
[_SimplePath_]: paths.md#simple-paths
257259
[`allow`]: attributes/diagnostics.md#lint-check-attributes
260+
[`automatically_derived`]: attributes/derive.md#the-automatically_derived-attribute
258261
[`cfg_attr`]: conditional-compilation.md#the-cfg_attr-attribute
259262
[`cfg`]: conditional-compilation.md#the-cfg-attribute
260263
[`cold`]: attributes/codegen.md#the-cold-attribute

src/attributes/derive.md

+9
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,19 @@ impl<T: PartialEq> PartialEq for Foo<T> {
3333

3434
You can implement `derive` for your own traits through [procedural macros].
3535

36+
## The `automatically_derived` attribute
37+
38+
The *`automatically_derived` attribute* is automatically added to
39+
[implementations] created by the `derive` attribute for built-in traits. It
40+
has no direct effect, but it may be used by tools and diagnostic lints to
41+
detect these automatically generated implementations.
42+
3643
[_MetaListPaths_]: ../attributes.md#meta-item-attribute-syntax
3744
[`Clone`]: ../../std/clone/trait.Clone.html
3845
[`PartialEq`]: ../../std/cmp/trait.PartialEq.html
3946
[`impl` item]: ../items/implementations.md
4047
[items]: ../items.md
4148
[derive macros]: ../procedural-macros.md#derive-macros
49+
[implementations]: ../items/implementations.md
50+
[items]: ../items.md
4251
[procedural macros]: ../procedural-macros.md#derive-macros

src/behavior-considered-undefined.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ code.
4949
* Invalid metadata in a wide reference, `Box<T>`, or raw pointer:
5050
* `dyn Trait` metadata is invalid if it is not a pointer to a vtable for
5151
`Trait` that matches the actual dynamic trait the pointer or reference points to.
52-
* Slice metadata is invalid if if the length is not a valid `usize`
52+
* Slice metadata is invalid if the length is not a valid `usize`
5353
(i.e., it must not be read from uninitialized memory).
5454
* Non-UTF-8 byte sequences in a `str`.
5555
* Invalid values for a type with a custom definition of invalid values.

src/const_eval.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ to be run.
3131
are implemented, one cannot use both short circuiting operators (`&&` and `||`) and let
3232
statements within the same constant.
3333
* [assignment expressions]
34-
* [assignment operator expressions]
34+
* [compound assignment expressions]
3535
* [expression statements]
3636
* [Field] expressions.
3737
* Index expressions, [array indexing] or [slice] with a `usize`.
@@ -63,7 +63,7 @@ A _const context_ is one of the following:
6363
[array indexing]: expressions/array-expr.md#array-and-slice-indexing-expressions
6464
[array type length expressions]: types/array.md
6565
[assignment expressions]: expressions/operator-expr.md#assignment-expressions
66-
[assignment operator expressions]: expressions/operator-expr.md#compound-assignment-expressions
66+
[compound assignment expressions]: expressions/operator-expr.md#compound-assignment-expressions
6767
[block expressions]: expressions/block-expr.md
6868
[borrow]: expressions/operator-expr.md#borrow-operators
6969
[cast]: expressions/operator-expr.md#type-cast-expressions
@@ -73,7 +73,7 @@ A _const context_ is one of the following:
7373
[constants]: items/constant-items.md
7474
[dereference operator]: expressions/operator-expr.md#the-dereference-operator
7575
[destructors]: destructors.md
76-
[enum discriminants]: items/enumerations.md#custom-discriminant-values-for-field-less-enumerations
76+
[enum discriminants]: items/enumerations.md#custom-discriminant-values-for-fieldless-enumerations
7777
[enum variant]: expressions/enum-variant-expr.md
7878
[expression statements]: statements.md#expression-statements
7979
[expressions]: expressions.md

src/expressions/array-expr.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ in a _panicked state_ if it fails.
6262

6363
```rust,should_panic
6464
// lint is deny by default.
65-
#![warn(const_err)]
65+
#![warn(unconditional_panic)]
6666
6767
([1, 2, 3, 4])[2]; // Evaluates to 3
6868

src/expressions/block-expr.md

+1-4
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,12 @@ of the block.
2222

2323
Blocks are written as `{`, then any [inner attributes], then [statements],
2424
then an optional expression, and finally a `}`. Statements are usually required
25-
to be followed a semicolon, with two exceptions. Item declaration statements do
25+
to be followed by a semicolon, with two exceptions. Item declaration statements do
2626
not need to be followed by a semicolon. Expression statements usually require
2727
a following semicolon except if its outer expression is a flow control
2828
expression. Furthermore, extra semicolons between statements are allowed, but
2929
these semicolons do not affect semantics.
3030

31-
> Note: The semicolon following a statement is not a part of the statement
32-
> itself. They are invalid when using the `stmt` macro matcher.
33-
3431
When evaluating a block expression, each statement, except for item declaration
3532
statements, is executed sequentially. Then the final expression is executed,
3633
if given.

src/expressions/loop-expr.md

+7-3
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ have type compatible with the value of the `break` expression(s).
4545

4646
> **<sup>Syntax</sup>**\
4747
> _PredicateLoopExpression_ :\
48-
> &nbsp;&nbsp; `while` [_Expression_]<sub>except struct expression</sub> [_BlockExpression_]
48+
> &nbsp;&nbsp; `while` [_Expression_]<sub>_except struct expression_</sub> [_BlockExpression_]
4949
5050
A `while` loop begins by evaluating the boolean loop conditional expression. If
5151
the loop conditional expression evaluates to `true`, the loop body block
@@ -67,7 +67,7 @@ while i < 10 {
6767

6868
> **<sup>Syntax</sup>**\
6969
> [_PredicatePatternLoopExpression_] :\
70-
> &nbsp;&nbsp; `while` `let` [_MatchArmPatterns_] `=` [_Expression_]<sub>except struct expression</sub>
70+
> &nbsp;&nbsp; `while` `let` [_MatchArmPatterns_] `=` [_Expression_]<sub>_except struct or lazy boolean operator expression_</sub>
7171
> [_BlockExpression_]
7272
7373
A `while let` loop is semantically similar to a `while` loop but in place of a
@@ -123,11 +123,13 @@ while let Some(v @ 1) | Some(v @ 2) = vals.pop() {
123123
}
124124
```
125125

126+
As is the case in [`if let` expressions], the scrutinee cannot be a [lazy boolean operator expression][_LazyBooleanOperatorExpression_].
127+
126128
## Iterator loops
127129

128130
> **<sup>Syntax</sup>**\
129131
> _IteratorLoopExpression_ :\
130-
> &nbsp;&nbsp; `for` [_Pattern_] `in` [_Expression_]<sub>except struct expression</sub>
132+
> &nbsp;&nbsp; `for` [_Pattern_] `in` [_Expression_]<sub>_except struct expression_</sub>
131133
> [_BlockExpression_]
132134
133135
A `for` expression is a syntactic construct for looping over elements provided
@@ -294,3 +296,5 @@ expression `()`.
294296
[`match` expression]: match-expr.md
295297
[scrutinee]: ../glossary.md#scrutinee
296298
[temporary values]: ../expressions.md#temporary-lifetimes
299+
[_LazyBooleanOperatorExpression_]: operator-expr.md#lazy-boolean-operators
300+
[`if let` expressions]: if-expr.md#if-let-expressions

src/expressions/match-expr.md

+3-4
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
>
1010
> _MatchArms_ :\
1111
> &nbsp;&nbsp; ( _MatchArm_ `=>`
12-
> ( [_BlockExpression_] `,`<sup>?</sup>
13-
> | [_Expression_] `,` )
12+
> ( [_ExpressionWithoutBlock_][_Expression_] `,`
13+
> | [_ExpressionWithBlock_][_Expression_] `,`<sup>?</sup> )
1414
> )<sup>\*</sup>\
15-
> &nbsp;&nbsp; _MatchArm_ `=>` ( [_BlockExpression_] | [_Expression_] ) `,`<sup>?</sup>
15+
> &nbsp;&nbsp; _MatchArm_ `=>` [_Expression_] `,`<sup>?</sup>
1616
>
1717
> _MatchArm_ :\
1818
> &nbsp;&nbsp; [_OuterAttribute_]<sup>\*</sup> _MatchArmPatterns_ _MatchArmGuard_<sup>?</sup>
@@ -146,7 +146,6 @@ expression in the same expression contexts as [attributes on block
146146
expressions].
147147
148148
[_Expression_]: ../expressions.md
149-
[_BlockExpression_]: block-expr.md#block-expressions
150149
[place expression]: ../expressions.md#place-expressions-and-value-expressions
151150
[value expression]: ../expressions.md#place-expressions-and-value-expressions
152151
[_InnerAttribute_]: ../attributes.md

src/interior-mutability.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Interior Mutability
22

3-
Sometimes a type needs be mutated while having multiple aliases. In Rust this
3+
Sometimes a type needs to be mutated while having multiple aliases. In Rust this
44
is achieved using a pattern called _interior mutability_. A type has interior
55
mutability if its internal state can be changed through a [shared reference] to
66
it. This goes against the usual [requirement][ub] that the value pointed to by a

src/items/associated-items.md

+17-11
Original file line numberDiff line numberDiff line change
@@ -98,24 +98,28 @@ Associated functions whose first parameter is named `self` are called *methods*
9898
and may be invoked using the [method call operator], for example, `x.foo()`, as
9999
well as the usual function call notation.
100100

101-
If the type of the `self` parameter is specified, it is limited to one of the
102-
following types:
101+
If the type of the `self` parameter is specified, it is limited to types resolving
102+
to one generated by the following grammar (where `'lt` denotes some arbitrary
103+
lifetime):
103104

104-
- `Self`
105-
- `&Self`
106-
- `&mut Self`
107-
- [`Box<Self>`]
108-
- [`Rc<Self>`]
109-
- [`Arc<Self>`]
110-
- [`Pin<P>`] where `P` is one of the above types except `Self`.
105+
```text
106+
P = &'lt S | &'lt mut S | Box<S> | Rc<S> | Arc<S> | Pin<P>
107+
S = Self | P
108+
```
111109

112-
The `Self` term can be replaced with the type being implemented.
110+
The `Self` terminal in this grammar denotes a type resolving to the implementing type.
111+
This can also include the contextual type alias `Self`, other type aliases,
112+
or associated type projections resolving to the implementing type.
113113

114114
```rust
115115
# use std::rc::Rc;
116116
# use std::sync::Arc;
117117
# use std::pin::Pin;
118+
// Examples of methods implemented on struct `Example`.
118119
struct Example;
120+
type Alias = Example;
121+
trait Trait { type Output; }
122+
impl Trait for Example { type Output = Example; }
119123
impl Example {
120124
fn by_value(self: Self) {}
121125
fn by_ref(self: &Self) {}
@@ -126,6 +130,8 @@ impl Example {
126130
fn by_pin(self: Pin<&Self>) {}
127131
fn explicit_type(self: Arc<Example>) {}
128132
fn with_lifetime<'a>(self: &'a Self) {}
133+
fn nested<'a>(self: &mut &'a Arc<Rc<Box<Alias>>>) {}
134+
fn via_projection(self: <Example as Trait>::Output) {}
129135
}
130136
```
131137

@@ -360,4 +366,4 @@ fn main() {
360366
[function item]: ../types/function-item.md
361367
[method call operator]: ../expressions/method-call-expr.md
362368
[path]: ../paths.md
363-
[regular function parameters]: functions.md#attributes-on-function-parameters
369+
[regular function parameters]: functions.md#attributes-on-function-parameters

src/items/enumerations.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ integer associated to it that is used to determine which variant it holds. An
6161
opaque reference to this discriminant can be obtained with the
6262
[`mem::discriminant`] function.
6363

64-
## Custom Discriminant Values for Field-Less Enumerations
64+
## Custom Discriminant Values for Fieldless Enumerations
6565

6666
If there is no data attached to *any* of the variants of an enumeration,
6767
then the discriminant can be directly chosen and accessed.

0 commit comments

Comments
 (0)