Doc more control flow behaviour for return keyword

This commit is contained in:
Lynnesbian 2025-04-10 11:11:09 +10:00
parent a576362620
commit e2caab1822
No known key found for this signature in database
GPG Key ID: F0A184B5213D9F90

View File

@ -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")]