-
Notifications
You must be signed in to change notification settings - Fork 12.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
An async closure may implement FnMut/Fn if it has no self-borrows
- Loading branch information
1 parent
685a80f
commit 2e97dae
Showing
4 changed files
with
70 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
//@ check-pass | ||
//@ edition: 2021 | ||
|
||
// Demonstrates that an async closure may implement `FnMut` (not just `async FnMut`!) | ||
// if it has no self-borrows. In this case, `&Ty` is not borrowed from the closure env, | ||
// since it's fine to reborrow it with its original lifetime. See the doc comment on | ||
// `should_reborrow_from_env_of_parent_coroutine_closure` for more detail for when we | ||
// must borrow from the closure env. | ||
|
||
#![feature(async_closure)] | ||
|
||
fn main() {} | ||
|
||
fn needs_fn_mut<T>(x: impl FnMut() -> T) {} | ||
|
||
fn hello(x: &Ty) { | ||
needs_fn_mut(async || { x.hello(); }); | ||
} | ||
|
||
struct Ty; | ||
impl Ty { | ||
fn hello(&self) {} | ||
} |