Skip to content

Commit ccffe18

Browse files
authored
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
2 parents 3370ac0 + 1cd8dff commit ccffe18

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

library/std/src/keyword_docs.rs

+18-2
Original file line numberDiff line numberDiff line change
@@ -943,8 +943,7 @@ mod mod_keyword {}
943943
/// Capture a [closure]'s environment by value.
944944
///
945945
/// `move` converts any variables captured by reference or mutable reference
946-
/// to owned by value variables. The three [`Fn` trait]'s mirror the ways to capture
947-
/// variables, when `move` is used, the closures is represented by the `FnOnce` trait.
946+
/// to owned by value variables.
948947
///
949948
/// ```rust
950949
/// let capture = "hello";
@@ -953,6 +952,23 @@ mod mod_keyword {}
953952
/// };
954953
/// ```
955954
///
955+
/// Note: `move` closures may still implement [`Fn`] or [`FnMut`], even though
956+
/// they capture variables by `move`. This is because the traits implemented by
957+
/// a closure type are determined by *what* the closure does with captured
958+
/// values, not *how* it captures them:
959+
///
960+
/// ```rust
961+
/// fn create_fn() -> impl Fn() {
962+
/// let text = "Fn".to_owned();
963+
///
964+
/// move || println!("This is a: {}", text)
965+
/// }
966+
///
967+
/// let fn_plain = create_fn();
968+
///
969+
/// fn_plain();
970+
/// ```
971+
///
956972
/// `move` is often used when [threads] are involved.
957973
///
958974
/// ```rust

0 commit comments

Comments
 (0)