Skip to content

Commit e2caab1

Browse files
committed
Doc more control flow behaviour for return keyword
1 parent a576362 commit e2caab1

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

library/std/src/keyword_docs.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1195,6 +1195,28 @@ mod ref_keyword {}
11951195
/// Ok(())
11961196
/// }
11971197
/// ```
1198+
///
1199+
/// Within [closures] and [`async`] blocks, `return` returns a value from within the closure or
1200+
/// `async` block, not from the parent function:
1201+
///
1202+
/// ```rust
1203+
/// fn foo() -> i32 {
1204+
/// let closure = || {
1205+
/// return 5;
1206+
/// };
1207+
///
1208+
/// let future = async {
1209+
/// return 10;
1210+
/// };
1211+
///
1212+
/// return 15;
1213+
/// }
1214+
///
1215+
/// assert_eq!(foo(), 15);
1216+
/// ```
1217+
///
1218+
/// [closures]: ../book/ch13-01-closures.html
1219+
/// [`async`]: ../std/keyword.async.html
11981220
mod return_keyword {}
11991221

12001222
#[doc(keyword = "self")]

0 commit comments

Comments
 (0)