Skip to content

Commit 2c19f51

Browse files
committed
doc: fix rust.md fallout
1 parent e33b1da commit 2c19f51

File tree

1 file changed

+25
-21
lines changed

1 file changed

+25
-21
lines changed

doc/rust.md

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2890,8 +2890,9 @@ match x {
28902890

28912891
The first pattern matches lists constructed by applying `Cons` to any head value, and a
28922892
tail value of `~Nil`. The second pattern matches _any_ list constructed with `Cons`,
2893-
ignoring the values of its arguments. The difference between `_` and `*` is that the pattern `C(_)` is only type-correct if
2894-
`C` has exactly one argument, while the pattern `C(..)` is type-correct for any enum variant `C`, regardless of how many arguments `C` has.
2893+
ignoring the values of its arguments. The difference between `_` and `*` is that the pattern
2894+
`C(_)` is only type-correct if `C` has exactly one argument, while the pattern `C(..)` is
2895+
type-correct for any enum variant `C`, regardless of how many arguments `C` has.
28952896

28962897
A `match` behaves differently depending on whether or not the head expression
28972898
is an [lvalue or an rvalue](#lvalues-rvalues-and-temporaries).
@@ -2904,11 +2905,11 @@ variables in the arm's block, and control enters the block.
29042905

29052906
When the head expression is an lvalue, the match does not allocate a
29062907
temporary location (however, a by-value binding may copy or move from
2907-
the lvalue). When possible, it is preferable to match on lvalues, as the
2908+
the lvalue). When possible, it is preferable to match on lvalues, as the
29082909
lifetime of these matches inherits the lifetime of the lvalue, rather
29092910
than being restricted to the inside of the match.
29102911

2911-
An example of an `match` expression:
2912+
An example of a `match` expression:
29122913

29132914
~~~~
29142915
# fn process_pair(a: int, b: int) { }
@@ -2938,28 +2939,31 @@ Patterns that bind variables
29382939
default to binding to a copy or move of the matched value
29392940
(depending on the matched value's type).
29402941
This can be changed to bind to a reference by
2941-
using the ```ref``` keyword,
2942-
or to a mutable reference using ```ref mut```.
2942+
using the `ref` keyword,
2943+
or to a mutable reference using `ref mut`.
29432944

2944-
Patterns can also dereference pointers by using the ``&``,
2945-
``~`` or ``@`` symbols, as appropriate. For example, these two matches
2946-
on ``x: &int`` are equivalent:
2945+
Patterns can also dereference pointers by using the `&`,
2946+
`~` or `@` symbols, as appropriate. For example, these two matches
2947+
on `x: &int` are equivalent:
29472948

29482949
~~~~
2949-
match *x { 0 => "zero", _ => "some" }
2950-
match x { &0 => "zero", _ => "some" }
2950+
# let x = &3;
2951+
let y = match *x { 0 => "zero", _ => "some" };
2952+
let z = match x { &0 => "zero", _ => "some" };
2953+
2954+
assert_eq!(y, z);
29512955
~~~~
29522956

2953-
A pattern that's just an identifier,
2954-
like `Nil` in the previous answer,
2955-
could either refer to an enum variant that's in scope,
2956-
or bind a new variable.
2957-
The compiler resolves this ambiguity by forbidding variable bindings that occur in ```match``` patterns from shadowing names of variants that are in scope.
2958-
For example, wherever ```List``` is in scope,
2959-
a ```match``` pattern would not be able to bind ```Nil``` as a new name.
2960-
The compiler interprets a variable pattern `x` as a binding _only_ if there is no variant named `x` in scope.
2961-
A convention you can use to avoid conflicts is simply to name variants with upper-case letters,
2962-
and local variables with lower-case letters.
2957+
A pattern that's just an identifier, like `Nil` in the previous answer,
2958+
could either refer to an enum variant that's in scope, or bind a new variable.
2959+
The compiler resolves this ambiguity by forbidding variable bindings that occur
2960+
in `match` patterns from shadowing names of variants that are in scope.
2961+
For example, wherever `List` is in scope,
2962+
a `match` pattern would not be able to bind `Nil` as a new name.
2963+
The compiler interprets a variable pattern `x` as a binding _only_ if there is
2964+
no variant named `x` in scope.
2965+
A convention you can use to avoid conflicts is simply to name variants with
2966+
upper-case letters, and local variables with lower-case letters.
29632967

29642968
Multiple match patterns may be joined with the `|` operator.
29652969
A range of values may be specified with `..`.

0 commit comments

Comments
 (0)