about summary refs log tree commit diff
path: root/library/std/src/keyword_docs.rs
diff options
context:
space:
mode:
authorLynnesbian <lynne@bune.city>2025-04-10 11:11:09 +1000
committerLynnesbian <lynne@bune.city>2025-04-10 11:11:09 +1000
commite2caab1822d858de4525ae615002094ab6e06734 (patch)
tree5157be18a5ceed65955d1a772061fe4e9f006999 /library/std/src/keyword_docs.rs
parenta576362620a5e0691054a48fcdc7ba5038c042c5 (diff)
downloadrust-e2caab1822d858de4525ae615002094ab6e06734.tar.gz
rust-e2caab1822d858de4525ae615002094ab6e06734.zip
Doc more control flow behaviour for return keyword
Diffstat (limited to 'library/std/src/keyword_docs.rs')
-rw-r--r--library/std/src/keyword_docs.rs22
1 files changed, 22 insertions, 0 deletions
diff --git a/library/std/src/keyword_docs.rs b/library/std/src/keyword_docs.rs
index 93306296847..b8eb0fd104c 100644
--- a/library/std/src/keyword_docs.rs
+++ b/library/std/src/keyword_docs.rs
@@ -1195,6 +1195,28 @@ mod ref_keyword {}
 ///     Ok(())
 /// }
 /// ```
+///
+/// Within [closures] and [`async`] blocks, `return` returns a value from within the closure or
+/// `async` block, not from the parent function:
+///
+/// ```rust
+/// fn foo() -> i32 {
+///     let closure = || {
+///         return 5;
+///     };
+///
+///     let future = async {
+///         return 10;
+///     };
+///
+///     return 15;
+/// }
+///
+/// assert_eq!(foo(), 15);
+/// ```
+///
+/// [closures]: ../book/ch13-01-closures.html
+/// [`async`]: ../std/keyword.async.html
 mod return_keyword {}
 
 #[doc(keyword = "self")]