about summary refs log tree commit diff
path: root/src/doc
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2015-07-07 02:26:31 +0000
committerbors <bors@rust-lang.org>2015-07-07 02:26:31 +0000
commit26f0cd5de7f71a0db0bb3857ce49a11cd0f7d876 (patch)
treeaa443527389593fd7edbf0591548d35844e72c51 /src/doc
parent6d71ce536439a9160100259c95c9c252a4061b86 (diff)
parent04a85c538a11dbc1c1670db23409f3034ffcbc1d (diff)
Auto merge of #26844 - steveklabnik:rollup, r=steveklabnik
- Successful merges: #26599, #26761, #26807, #26809, #26825, #26827, #26828, #26832, #26834, #26835
- Failed merges: #26796
Diffstat (limited to 'src/doc')
-rw-r--r--src/doc/reference.md6
-rw-r--r--src/doc/trpl/ffi.md17
-rw-r--r--src/doc/trpl/patterns.md32
3 files changed, 38 insertions, 17 deletions
diff --git a/src/doc/reference.md b/src/doc/reference.md
index bdd4ba026d6..060f954274a 100644
--- a/src/doc/reference.md
+++ b/src/doc/reference.md
@@ -2515,9 +2515,8 @@ Here are some examples:
 #### Moved and copied types
 
 When a [local variable](#variables) is used as an
-[rvalue](#lvalues,-rvalues-and-temporaries) the variable will either be moved
-or copied, depending on its type. All values whose type implements `Copy` are
-copied, all others are moved.
+[rvalue](#lvalues,-rvalues-and-temporaries), the variable will be copied
+if its type implements `Copy`. All others are moved.
 
 ### Literal expressions
 
@@ -2882,7 +2881,6 @@ operand.
 ```
 # let mut x = 0;
 # let y = 0;
-
 x = y;
 ```
 
diff --git a/src/doc/trpl/ffi.md b/src/doc/trpl/ffi.md
index 442a1f062ef..cbedf863714 100644
--- a/src/doc/trpl/ffi.md
+++ b/src/doc/trpl/ffi.md
@@ -533,19 +533,10 @@ attribute turns off Rust's name mangling, so that it is easier to link to.
 
 # FFI and panics
 
-It’s important to be mindful of `panic!`s when working with FFI. This code,
-when called from C, will `abort`:
-
-```rust
-#[no_mangle]
-pub extern fn oh_no() -> ! {
-    panic!("Oops!");
-}
-# fn main() {}
-```
-
-If you’re writing code that may panic, you should run it in another thread,
-so that the panic doesn’t bubble up to C:
+It’s important to be mindful of `panic!`s when working with FFI. A `panic!`
+across an FFI boundary is undefined behavior. If you’re writing code that may
+panic, you should run it in another thread, so that the panic doesn’t bubble up
+to C:
 
 ```rust
 use std::thread;
diff --git a/src/doc/trpl/patterns.md b/src/doc/trpl/patterns.md
index 7a1f8bf21bf..9603eec7aca 100644
--- a/src/doc/trpl/patterns.md
+++ b/src/doc/trpl/patterns.md
@@ -282,6 +282,38 @@ This ‘destructuring’ behavior works on any compound data type, like
 [tuples]: primitive-types.html#tuples
 [enums]: enums.html
 
+# Ignoring bindings
+
+You can use `_` in a pattern to disregard the value. For example, here’s a
+`match` against a `Result<T, E>`:
+
+```rust
+# let some_value: Result<i32, &'static str> = Err("There was an error");
+match some_value {
+    Ok(value) => println!("got a value: {}", value),
+    Err(_) => println!("an error occurred"),
+}
+```
+
+In the first arm, we bind the value inside the `Ok` variant to `value`. But
+in the `Err` arm, we use `_` to disregard the specific error, and just print
+a general error message.
+
+`_` is valid in any pattern that creates a binding. This can be useful to
+ignore parts of a larger structure:
+
+```rust
+fn coordinate() -> (i32, i32, i32) {
+    // generate and return some sort of triple tuple
+# (1, 2, 3)
+}
+
+let (x, _, z) = coordinate();
+```
+
+Here, we bind the first and last element of the tuple to `x` and `z`, but
+ignore the middle element.
+
 # Mix and Match
 
 Whew! That’s a lot of different ways to match things, and they can all be