Skip to content

Commit 61b7fa3

Browse files
committed
Minor updates and fixes.
1 parent fc172c1 commit 61b7fa3

File tree

6 files changed

+37
-23
lines changed

6 files changed

+37
-23
lines changed

src/expressions/closure-expr.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
99
A _closure expression_ defines a closure and denotes it as a value, in a single
1010
expression. A closure expression is a pipe-symbol-delimited (`|`) list of
11-
patterns followed by an expression. Type annotations may optionally be added
11+
irrefutable [patterns] followed by an expression. Type annotations may optionally be added
1212
for the type of the parameters or for the return type. If there is a return
1313
type, the expression used for the body of the closure must be a normal
1414
[block]. A closure expression also may begin with the
@@ -63,6 +63,7 @@ ten_times(move |j| println!("{}, {}", word, j));
6363

6464
[block]: expressions/block-expr.html
6565
[function definitions]: items/functions.html
66+
[patterns]: patterns.html
6667

6768
[_Expression_]: expressions.html
6869
[_BlockExpression_]: expressions/block-expr.html

src/items/functions.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ fn answer_to_life_the_universe_and_everything() -> i32 {
1818
}
1919
```
2020

21-
As with `let` bindings, function arguments are irrefutable patterns, so any
21+
As with `let` bindings, function arguments are irrefutable [patterns], so any
2222
pattern that is valid in a let binding is also valid as an argument:
2323

2424
```rust
@@ -120,7 +120,7 @@ implemented by executing an illegal instruction.
120120
[Outer attributes][attributes] are allowed on functions. [Inner
121121
attributes][attributes] are allowed directly after the `{` inside its [block].
122122

123-
This example shows an inner attribute on a function. The function will only be
123+
This example shows an inner attribute on a function. The function will only be
124124
available while running tests.
125125

126126
```
@@ -153,4 +153,5 @@ attributes].
153153
[the optimization hint attributes]: attributes.html#optimization-hints
154154
[`deprecated`]: attributes.html#deprecation
155155
[`doc`]: attributes.html#documentation
156-
[`must_use`]: attributes.html#must_use
156+
[`must_use`]: attributes.html#must_use
157+
[patterns]: patterns.html

src/macros-by-example.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ syntax named by _designator_. Valid designators are:
3636
[item]: items.html
3737
[block]: expressions/block-expr.html
3838
[statement]: statements.html
39-
[pattern]: expressions/match-expr.html
39+
[pattern]: patterns.html
4040
[expression]: expressions.html
4141
[type]: types.html
4242
[identifier]: identifiers.html

src/patterns.md

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ match message {
9898

9999
## Refutability
100100

101-
A pattern is said to be *Refutable* when it **has the possibily of not being matched**
101+
A pattern is said to be *Refutable* when it **has the possibility of not being matched**
102102
by the value it is being matched against. *Irrefutable* patterns, on the other hand,
103103
always match the value they are being matched against. Examples:
104104

@@ -163,7 +163,7 @@ for i in -2..5 {
163163

164164
> **<sup>Syntax</sup>**\
165165
> _IdentifierPattern_ :\
166-
> &nbsp;&nbsp; &nbsp;&nbsp; `ref`<sup>?</sup> `mut`<sup>?</sup> IDENTIFIER (`@` [_Pattern_] ) <sup>?</sup>
166+
> &nbsp;&nbsp; &nbsp;&nbsp; `ref`<sup>?</sup> `mut`<sup>?</sup> [IDENTIFIER] (`@` [_Pattern_] ) <sup>?</sup>
167167
168168
_Identifier patterns_ bind the value they match to a **previously undeclared** variable.
169169

@@ -410,8 +410,11 @@ let b = match int_reference { &0 => "zero", _ => "some" };
410410
assert_eq!(a, b);
411411
```
412412

413-
The grammar production for reference patterns has to match the token `&&`
414-
because it is a token by itself, not two `&` tokens.
413+
The grammar production for reference patterns has to match the token `&&` to match a
414+
reference to a reference because it is a token by itself, not two `&` tokens.
415+
416+
Adding the `mut` keyword dereferences a mutable reference. The mutability must match the
417+
mutability of the reference.
415418

416419
Reference patterns are always irrefutable.
417420

@@ -431,17 +434,19 @@ Reference patterns are always irrefutable.
431434
> &nbsp;&nbsp; _StructPatternField_ (`,` _StructPatternField_) <sup>\*</sup>
432435
>
433436
> _StructPatternField_ :\
434-
> &nbsp;&nbsp; _OuterAttribute_ <sup>\*</sup>\
437+
> &nbsp;&nbsp; [_OuterAttribute_] <sup>\*</sup>\
435438
> &nbsp;&nbsp; (\
436-
> &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; INTEGER_LITERAL `:` [_Pattern_]\
437-
> &nbsp;&nbsp; &nbsp;&nbsp; | IDENTIFIER `:` [_Pattern_]\
438-
> &nbsp;&nbsp; &nbsp;&nbsp; | `ref`<sup>?</sup> `mut`<sup>?</sup> IDENTIFIER\
439+
> &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; [INTEGER_LITERAL] `:` [_Pattern_]\
440+
> &nbsp;&nbsp; &nbsp;&nbsp; | [IDENTIFIER] `:` [_Pattern_]\
441+
> &nbsp;&nbsp; &nbsp;&nbsp; | `ref`<sup>?</sup> `mut`<sup>?</sup> [IDENTIFIER]\
439442
> &nbsp;&nbsp; )
440443
>
441444
> _StructPatternEtCetera_ :\
442-
> &nbsp;&nbsp; _OuterAttribute_ <sup>\*</sup>\
445+
> &nbsp;&nbsp; [_OuterAttribute_] <sup>\*</sup>\
443446
> &nbsp;&nbsp; `..`
444447
448+
[_OuterAttribute_]: attributes.html
449+
445450
Struct patterns match struct values that match all criteria defined by its subpatterns.
446451
They are also used to [destructure](#destructuring) a struct.
447452

@@ -531,7 +536,7 @@ A TupleStruct pattern is refutable when one of its subpatterns is refutable.
531536

532537
> **<sup>Syntax</sup>**\
533538
> _TuplePattern_ :<a name="tuple-pattern-syntax"></a>\
534-
> &nbsp;&nbsp; `(` _TupplePatternItems_<sup>?</sup> `)`
539+
> &nbsp;&nbsp; `(` _TuplePatternItems_<sup>?</sup> `)`
535540
>
536541
> _TuplePatternItems_ :\
537542
> &nbsp;&nbsp; &nbsp;&nbsp; [_Pattern_] `,`\
@@ -604,3 +609,4 @@ refer to refutable constants or enum variants for enums with multiple variants.
604609
[_PathPattern_]: #path-patterns
605610

606611
[Copy trait]: special-types-and-traits.html#copy
612+
[IDENTIFIER]: identifiers.html

src/statements.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ fn outer() {
4242

4343
### `let` statements
4444

45-
A *`let` statement* introduces a new set of [variables], given by a pattern. The
45+
A *`let` statement* introduces a new set of [variables], given by a [pattern]. The
4646
pattern is followed optionally by a type annotation and then optionally by an
4747
initializer expression. When no type annotation is given, the compiler will
4848
infer the type, or signal an error if insufficient type information is
@@ -106,3 +106,4 @@ statement are [`cfg`], and [the lint check attributes].
106106
[outer attributes]: attributes.html
107107
[`cfg`]: conditional-compilation.html
108108
[the lint check attributes]: attributes.html#lint-check-attributes
109+
[pattern]: patterns.html

src/tokens.md

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -524,9 +524,9 @@ usages and meanings are defined in the linked pages.
524524
| `%` | Percent | [Remainder][arith]
525525
| `^` | Caret | [Bitwise and Logical XOR][arith]
526526
| `!` | Not | [Bitwise and Logical NOT][negation], [Macro Calls][macros], [Inner Attributes][attributes], [Never Type]
527-
| `&` | And | [Bitwise and Logical AND][arith], [Borrow], [References]
527+
| `&` | And | [Bitwise and Logical AND][arith], [Borrow], [References], [Reference patterns]
528528
| <code>\|</code> | Or | [Bitwise and Logical OR][arith], [Closures], [Match]
529-
| `&&` | AndAnd | [Lazy AND][lazy-bool], [Borrow], [References]
529+
| `&&` | AndAnd | [Lazy AND][lazy-bool], [Borrow], [References], [Reference patterns]
530530
| <code>\|\|</code> | OrOr | [Lazy OR][lazy-bool], [Closures]
531531
| `<<` | Shl | [Shift Left][arith], [Nested Generics][generics]
532532
| `>>` | Shr | [Shift Right][arith], [Nested Generics][generics]
@@ -547,12 +547,12 @@ usages and meanings are defined in the linked pages.
547547
| `<` | Lt | [Less than][comparison], [Generics], [Paths]
548548
| `>=` | Ge | [Greater than or equal to][comparison], [Generics]
549549
| `<=` | Le | [Less than or equal to][comparison]
550-
| `@` | At | [Subpattern binding][match]
551-
| `_` | Underscore | [Placeholder patterns][match], Inferred types
550+
| `@` | At | [Subpattern binding]
551+
| `_` | Underscore | [Wildcard patterns], Inferred types
552552
| `.` | Dot | [Field access][field], [Tuple index]
553-
| `..` | DotDot | [Range][range], [Struct expressions], [Wildcard patterns][match]
554-
| `...` | DotDotDot | [Variadic functions][extern]
555-
| `..=` | DotDotEq | [Inclusive Range][range]
553+
| `..` | DotDot | [Range][range], [Struct expressions], [Patterns]
554+
| `...` | DotDotDot | [Variadic functions][extern], [Range patterns]
555+
| `..=` | DotDotEq | [Inclusive Range][range], [Range patterns]
556556
| `,` | Comma | Various separators
557557
| `;` | Semi | Terminator for various items and statements, [Array types]
558558
| `:` | Colon | Various separators
@@ -611,3 +611,8 @@ them are referred to as "token trees" in [macros]. The three types of brackets
611611
[extern]: items/external-blocks.html
612612
[struct expressions]: expressions/struct-expr.html
613613
[tuple index]: expressions/tuple-expr.html#tuple-indexing-expressions
614+
[Wildcard patterns]: patterns.html#wildcard-pattern
615+
[patterns]: patterns.html
616+
[Subpattern binding]: patterns.html#identifier-patterns
617+
[Range patterns]: patterns.html#range-patterns
618+
[Reference patterns]: patterns.html#reference-patterns

0 commit comments

Comments
 (0)