Skip to content

Commit f37e69e

Browse files
committed
Rollup merge of #30502 - Luke-Nukem:master, r=steveklabnik
Rewrite of a paragraph in in the `match` section. The colon `:` should be used only when the sentence preceeding it is a complete sentence. If this is not the case, then a `;` should be used; this denotes that the following fragment is a part of the previous fragment. I got a new bike; it has two wheels. (Similar to I got a new bike, it has two wheels) The ice cream truck has great flavours; blueberry, blackberry, berryberry. Writing a complete sentence: - with a list under it - You can join two sentences with it: Much like this. r? @steveklabnik
2 parents d1f854a + 1522350 commit f37e69e

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

src/doc/book/documentation.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ hello.rs:4 }
7373
```
7474

7575
This [unfortunate error](https://github.com/rust-lang/rust/issues/22547) is
76-
correct: documentation comments apply to the thing after them, and there's
76+
correct; documentation comments apply to the thing after them, and there's
7777
nothing after that last comment.
7878

7979
[rc-new]: https://doc.rust-lang.org/nightly/std/rc/struct.Rc.html#method.new
@@ -385,7 +385,7 @@ error handling. Lets say you want the following,
385385

386386
```rust,ignore
387387
/// use std::io;
388-
/// let mut input = String::new();
388+
/// let mut input = String::new();
389389
/// try!(io::stdin().read_line(&mut input));
390390
```
391391

@@ -398,7 +398,7 @@ don't return anything so this will give a mismatched types error.
398398
/// ```
399399
/// use std::io;
400400
/// # fn foo() -> io::Result<()> {
401-
/// let mut input = String::new();
401+
/// let mut input = String::new();
402402
/// try!(io::stdin().read_line(&mut input));
403403
/// # Ok(())
404404
/// # }

src/doc/book/match.md

+13-13
Original file line numberDiff line numberDiff line change
@@ -23,26 +23,24 @@ match x {
2323
`match` takes an expression and then branches based on its value. Each ‘arm’ of
2424
the branch is of the form `val => expression`. When the value matches, that arm’s
2525
expression will be evaluated. It’s called `match` because of the term ‘pattern
26-
matching’, which `match` is an implementation of. There’s an [entire section on
26+
matching’, which `match` is an implementation of. There’s a [separate section on
2727
patterns][patterns] that covers all the patterns that are possible here.
2828

2929
[patterns]: patterns.html
3030

31-
So what’s the big advantage? Well, there are a few. First of all, `match`
32-
enforces ‘exhaustiveness checking’. Do you see that last arm, the one with the
33-
underscore (`_`)? If we remove that arm, Rust will give us an error:
31+
One of the many advantages of `match` is it enforces ‘exhaustiveness checking’.
32+
For example if we remove the last arm with the underscore `_`, the compiler will
33+
give us an error:
3434

3535
```text
3636
error: non-exhaustive patterns: `_` not covered
3737
```
3838

39-
In other words, Rust is trying to tell us we forgot a value. Because `x` is an
40-
integer, Rust knows that it can have a number of different values – for
41-
example, `6`. Without the `_`, however, there is no arm that could match, and
42-
so Rust refuses to compile the code. `_` acts like a ‘catch-all arm’. If none
43-
of the other arms match, the arm with `_` will, and since we have this
44-
catch-all arm, we now have an arm for every possible value of `x`, and so our
45-
program will compile successfully.
39+
Rust is telling us that we forgot a value. The compiler infers from `x` that it
40+
can have any positive 32bit value; for example 1 to 2,147,483,647. The `_` acts
41+
as a 'catch-all', and will catch all possible values that *aren't* specified in
42+
an arm of `match`. As you can see with the previous example, we provide `match`
43+
arms for integers 1-5, if `x` is 6 or any other value, then it is caught by `_`.
4644

4745
`match` is also an expression, which means we can use it on the right-hand
4846
side of a `let` binding or directly where an expression is used:
@@ -60,7 +58,8 @@ let number = match x {
6058
};
6159
```
6260

63-
Sometimes it’s a nice way of converting something from one type to another.
61+
Sometimes it’s a nice way of converting something from one type to another; in
62+
this example the integers are converted to `String`.
6463

6564
# Matching on enums
6665

@@ -91,7 +90,8 @@ fn process_message(msg: Message) {
9190

9291
Again, the Rust compiler checks exhaustiveness, so it demands that you
9392
have a match arm for every variant of the enum. If you leave one off, it
94-
will give you a compile-time error unless you use `_`.
93+
will give you a compile-time error unless you use `_` or provide all possible
94+
arms.
9595

9696
Unlike the previous uses of `match`, you can’t use the normal `if`
9797
statement to do this. You can use the [`if let`][if-let] statement,

0 commit comments

Comments
 (0)