Skip to content

Commit

Permalink
Rollup merge of #75162 - poliorcetics:move-documentation-fix, r=jyn514
Browse files Browse the repository at this point in the history
Fix the documentation for move about Fn traits implementations

Fixes #74997.

This uses the note from the [reference](https://doc.rust-lang.org/reference/types/closure.html#call-traits-and-coercions) but I can also just put a link to it or do both.

@rusbot modify labels: C-bug T-doc T-libs
  • Loading branch information
JohnTitor authored Aug 8, 2020
2 parents 3370ac0 + 1cd8dff commit ccffe18
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions library/std/src/keyword_docs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -943,8 +943,7 @@ mod mod_keyword {}
/// Capture a [closure]'s environment by value.
///
/// `move` converts any variables captured by reference or mutable reference
/// to owned by value variables. The three [`Fn` trait]'s mirror the ways to capture
/// variables, when `move` is used, the closures is represented by the `FnOnce` trait.
/// to owned by value variables.
///
/// ```rust
/// let capture = "hello";
Expand All @@ -953,6 +952,23 @@ mod mod_keyword {}
/// };
/// ```
///
/// Note: `move` closures may still implement [`Fn`] or [`FnMut`], even though
/// they capture variables by `move`. This is because the traits implemented by
/// a closure type are determined by *what* the closure does with captured
/// values, not *how* it captures them:
///
/// ```rust
/// fn create_fn() -> impl Fn() {
/// let text = "Fn".to_owned();
///
/// move || println!("This is a: {}", text)
/// }
///
/// let fn_plain = create_fn();
///
/// fn_plain();
/// ```
///
/// `move` is often used when [threads] are involved.
///
/// ```rust
Expand Down

0 comments on commit ccffe18

Please sign in to comment.