diff options
| author | Yuki Okushi <huyuumi.dev@gmail.com> | 2020-08-09 06:41:20 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-08-09 06:41:20 +0900 |
| commit | ccffe18c3ebbb7abbaf267b2a98648a73946bff9 (patch) | |
| tree | 81a3c2cde579c61b19d5b4fadb5b01470641e33b | |
| parent | 3370ac00428be662c0d4d6fea4817212486f474e (diff) | |
| parent | 1cd8dffdae5826931c59329c168ee956800ee6df (diff) | |
| download | rust-ccffe18c3ebbb7abbaf267b2a98648a73946bff9.tar.gz rust-ccffe18c3ebbb7abbaf267b2a98648a73946bff9.zip | |
Rollup merge of #75162 - poliorcetics:move-documentation-fix, r=jyn514
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
| -rw-r--r-- | library/std/src/keyword_docs.rs | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/library/std/src/keyword_docs.rs b/library/std/src/keyword_docs.rs index c98008688ab..ff343625a19 100644 --- a/library/std/src/keyword_docs.rs +++ b/library/std/src/keyword_docs.rs @@ -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"; @@ -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 |
