Skip to content

Commit f4f0faf

Browse files
committed
Auto merge of rust-lang#132706 - compiler-errors:async-closures, r=oli-obk
Stabilize async closures (RFC 3668) # Async Closures Stabilization Report This report proposes the stabilization of `#![feature(async_closure)]` ([RFC 3668](https://rust-lang.github.io/rfcs/3668-async-closures.html)). This is a long-awaited feature that increases the expressiveness of the Rust language and fills a pressing gap in the async ecosystem. ## Stabilization summary * You can write async closures like `async || {}` which return futures that can borrow from their captures and can be higher-ranked in their argument lifetimes. * You can express trait bounds for these async closures using the `AsyncFn` family of traits, analogous to the `Fn` family. ```rust async fn takes_an_async_fn(f: impl AsyncFn(&str)) { futures::join(f("hello"), f("world")).await; } takes_an_async_fn(async |s| { other_fn(s).await }).await; ``` ## Motivation Without this feature, users hit two major obstacles when writing async code that uses closures and `Fn` trait bounds: - The inability to express higher-ranked async function signatures. - That closures cannot return futures that borrow from the closure captures. That is, for the first, we cannot write: ```rust // We cannot express higher-ranked async function signatures. async fn f<Fut>(_: impl for<'a> Fn(&'a u8) -> Fut) where Fut: Future<Output = ()>, { todo!() } async fn main() { async fn g(_: &u8) { todo!() } f(g).await; //~^ ERROR mismatched types //~| ERROR one type is more general than the other } ``` And for the second, we cannot write: ```rust // Closures cannot return futures that borrow closure captures. async fn f<Fut: Future<Output = ()>>(_: impl FnMut() -> Fut) { todo!() } async fn main() { let mut xs = vec![]; f(|| async { async fn g() -> u8 { todo!() } xs.push(g().await); }); //~^ ERROR captured variable cannot escape `FnMut` closure body } ``` Async closures provide a first-class solution to these problems. For further background, please refer to the [motivation section](https://rust-lang.github.io/rfcs/3668-async-closures.html#motivation) of the RFC. ## Major design decisions since RFC The RFC had left open the question of whether we would spell the bounds syntax for async closures... ```rust // ...as this... fn f() -> impl AsyncFn() -> u8 { todo!() } // ...or as this: fn f() -> impl async Fn() -> u8 { todo!() } ``` We've decided to spell this as `AsyncFn{,Mut,Once}`. The `Fn` family of traits is special in many ways. We had originally argued that, due to this specialness, that perhaps the `async Fn` syntax could be adopted without having to decide whether a general `async Trait` mechanism would ever be adopted. However, concerns have been raised that we may not want to use `async Fn` syntax unless we would pursue more general trait modifiers. Since there remain substantial open questions on those -- and we don't want to rush any design work there -- it makes sense to ship this needed feature using the `AsyncFn`-style bounds syntax. Since we would, in no case, be shipping a generalized trait modifier system anytime soon, we'll be continuing to see `AsyncFoo` traits appear across the ecosystem regardless. If we were to ever later ship some general mechanism, we could at that time manage the migration from `AsyncFn` to `async Fn`, just as we'd be enabling and managing the migration of many other traits. Note that, as specified in RFC 3668, the details of the `AsyncFn*` traits are not exposed and they can only be named via the "parentheses sugar". That is, we can write `T: AsyncFn() -> u8` but not `T: AsyncFn<Output = u8>`. Unlike the `Fn` traits, we cannot project to the `Output` associated type of the `AsyncFn` traits. That is, while we can write... ```rust fn f<F: Fn() -> u8>(_: F::Output) {} ``` ...we cannot write: ```rust fn f<F: AsyncFn() -> u8>(_: F::Output) {} //~^ ERROR ``` The choice of `AsyncFn{,Mut,Once}` bounds syntax obviates, for our purposes here, another question decided after that RFC, which was how to order bound modifiers such as `for<'a> async Fn()`. Other than answering the open question in the RFC on syntax, nothing has changed about the design of this feature between RFC 3668 and this stabilization. ## What is stabilized For those interested in the technical details, please see [the dev guide section](https://rustc-dev-guide.rust-lang.org/coroutine-closures.html) I authored. #### Async closures Other than in how they solve the problems described above, async closures act similarly to closures that return async blocks, and can have parts of their signatures specified: ```rust // They can have arguments annotated with types: let _ = async |_: u8| { todo!() }; // They can have their return types annotated: let _ = async || -> u8 { todo!() }; // They can be higher-ranked: let _ = async |_: &str| { todo!() }; // They can capture values by move: let x = String::from("hello, world"); let _ = async move || do_something(&x).await }; ``` When called, they return an anonymous future type corresponding to the (not-yet-executed) body of the closure. These can be awaited like any other future. What distinguishes async closures is that, unlike closures that return async blocks, the futures returned from the async closure can capture state from the async closure. For example: ```rust let vec: Vec<String> = vec![]; let closure = async || { vec.push(ready(String::from("")).await); }; ``` The async closure captures `vec` with some `&'closure mut Vec<String>` which lives until the closure is dropped. Every call to `closure()` returns a future which reborrows that mutable reference `&'call mut Vec<String>` which lives until the future is dropped (e.g. it is `await`ed). As another example: ```rust let string: String = "Hello, world".into(); let closure = async move || { ready(&string).await; }; ``` The closure is marked with `move`, which means it takes ownership of the string by *value*. The future that is returned by calling `closure()` returns a future which borrows a reference `&'call String` which lives until the future is dropped (e.g. it is `await`ed). #### Async fn trait family To support the lending capability of async closures, and to provide a first-class way to express higher-ranked async closures, we introduce the `AsyncFn*` family of traits. See the [corresponding section](https://rust-lang.github.io/rfcs/3668-async-closures.html#asyncfn) of the RFC. We stabilize naming `AsyncFn*` via the "parenthesized sugar" syntax that normal `Fn*` traits can be named. The `AsyncFn*` trait can be used anywhere a `Fn*` trait bound is allowed, such as: ```rust /// In return-position impl trait: fn closure() -> impl AsyncFn() { async || {} } /// In trait bounds: trait Foo<F>: Sized where F: AsyncFn() { fn new(f: F) -> Self; } /// in GATs: trait Gat { type AsyncHasher<T>: AsyncFn(T) -> i32; } ``` Other than using them in trait bounds, the definitions of these traits are not directly observable, but certain aspects of their behavior can be indirectly observed such as the fact that: * `AsyncFn::async_call` and `AsyncFnMut::async_call_mut` return a future which is *lending*, and therefore borrows the `&self` lifetime of the callee. ```rust fn by_ref_call(c: impl AsyncFn()) { let fut = c(); drop(c); // ^ Cannot drop `c` since it is borrowed by `fut`. } ``` * `AsyncFnOnce::async_call_once` returns a future that takes ownership of the callee. ```rust fn by_ref_call(c: impl AsyncFnOnce()) { let fut = c(); let _ = c(); // ^ Cannot call `c` since calling it takes ownership the callee. } ``` * All currently-stable callable types (i.e., closures, function items, function pointers, and `dyn Fn*` trait objects) automatically implement `AsyncFn*() -> T` if they implement `Fn*() -> Fut` for some output type `Fut`, and `Fut` implements `Future<Output = T>`. * This is to make sure that `AsyncFn*()` trait bounds have maximum compatibility with existing callable types which return futures, such as async function items and closures which return boxed futures. * For now, this only works currently for *concrete* callable types -- for example, a argument-position impl trait like `impl Fn() -> impl Future<Output = ()>` does not implement `AsyncFn()`, due to the fact that a `AsyncFn`-if-`Fn` blanket impl does not exist in reality. This may be relaxed in the future. Users can work around this by wrapping their type in an async closure and calling it. I expect this to not matter much in practice, as users are encouraged to write `AsyncFn` bounds directly. ```rust fn is_async_fn(_: impl AsyncFn(&str)) {} async fn async_fn_item(s: &str) { todo!() } is_async_fn(s); // ^^^ This works. fn generic(f: impl Fn() -> impl Future<Output = ()>) { is_async_fn(f); // ^^^ This does not work (yet). } ``` #### The by-move future When async closures are called with `AsyncFn`/`AsyncFnMut`, they return a coroutine that borrows from the closure. However, when they are called via `AsyncFnOnce`, we consume that closure, and cannot return a coroutine that borrows from data that is now dropped. To work around around this limitation, we synthesize a separate future type for calling the async closure via `AsyncFnOnce`. This future executes identically to the by-ref future returned from calling the async closure, except for the fact that it has a different set of captures, since we must *move* the captures from the parent async into the child future. #### Interactions between async closures and the `Fn*` family of traits Async closures always implement `FnOnce`, since they always can be called once. They may also implement `Fn` or `FnMut` if their body is compatible with the calling mode (i.e. if they do not mutate their captures, or they do not capture their captures, respectively) and if the future returned by the async closure is not *lending*. ```rust let id = String::new(); let mapped: Vec</* impl Future */> = [/* elements */] .into_iter() // `Iterator::map` takes an `impl FnMut` .map(async |element| { do_something(&id, element).await; }) .collect(); ``` See [the dev guide](https://rustc-dev-guide.rust-lang.org/coroutine-closures.html#follow-up-when-do-async-closures-implement-the-regular-fn-traits) for a detailed explanation for the situations where this may not be possible due to the lending nature of async closures. #### Other notable features of async closures shared with synchronous closures * Async closures are `Copy` and/or `Clone` if their captures are `Copy`/`Clone`. * Async closures do closure signature inference: If an async closure is passed to a function with a `AsyncFn` or `Fn` trait bound, we can eagerly infer the argument types of the closure. More details are provided in [the dev guide](https://rustc-dev-guide.rust-lang.org/coroutine-closures.html#closure-signature-inference). #### Lints This PR also stabilizes the `CLOSURE_RETURNING_ASYNC_BLOCK` lint as an `allow` lint. This lints on "old-style" async closures: ```rust #![warn(closure_returning_async_block)] let c = |x: &str| async {}; ``` We should encourage users to use `async || {}` where possible. This lint remains `allow` and may be refined in the future because it has a few false positives (namely, see: "Where do we expect rewriting `|| async {}` into `async || {}` to fail?") An alternative that could be made at the time of stabilization is to put this lint behind another gate, so we can decide to stabilize it later. ## What isn't stabilized (aka, potential future work) #### `async Fn*()` bound syntax We decided to stabilize async closures without the `async Fn*()` bound modifier syntax. The general direction of this syntax and how it fits is still being considered by T-lang (e.g. in [RFC 3710](rust-lang/rfcs#3710)). #### Naming the futures returned by async closures This stabilization PR does not provide a way of naming the futures returned by calling `AsyncFn*`. Exposing a stable way to refer to these futures is important for building async-closure-aware combinators, and will be an important future step. #### Return type notation-style bounds for async closures The RFC described an RTN-like syntax for putting bounds on the future returned by an async closure: ```rust async fn foo(x: F) -> Result<()> where F: AsyncFn(&str) -> Result<()>, // The future from calling `F` is `Send` and `'static`. F(..): Send + 'static, {} ``` This stabilization PR does not stabilize that syntax yet, which remains unimplemented (though will be soon). #### `dyn AsyncFn*()` `AsyncFn*` are not dyn-compatible yet. This will likely be implemented in the future along with the dyn-compatibility of async fn in trait, since the same issue (dealing with the future returned by a call) applies there. ## Tests Tests exist for this feature in [`tests/ui/async-await/async-closures`](https://github.com/rust-lang/rust/tree/5b542866400ad4a294f468cfa7e059d95c27a079/tests/ui/async-await/async-closures). <details> <summary>A selected set of tests:</summary> * Lending behavior of async closures * `tests/ui/async-await/async-closures/mutate.rs` * `tests/ui/async-await/async-closures/captures.rs` * `tests/ui/async-await/async-closures/precise-captures.rs` * `tests/ui/async-await/async-closures/no-borrow-from-env.rs` * Async closures may be higher-ranked * `tests/ui/async-await/async-closures/higher-ranked.rs` * `tests/ui/async-await/async-closures/higher-ranked-return.rs` * Async closures may implement `Fn*` traits * `tests/ui/async-await/async-closures/is-fn.rs` * `tests/ui/async-await/async-closures/implements-fnmut.rs` * Async closures may be cloned * `tests/ui/async-await/async-closures/clone-closure.rs` * Ownership of the upvars when `AsyncFnOnce` is called * `tests/ui/async-await/async-closures/drop.rs` * `tests/ui/async-await/async-closures/move-is-async-fn.rs` * `tests/ui/async-await/async-closures/force-move-due-to-inferred-kind.rs` * `tests/ui/async-await/async-closures/force-move-due-to-actually-fnonce.rs` * Closure signature inference * `tests/ui/async-await/async-closures/signature-deduction.rs` * `tests/ui/async-await/async-closures/sig-from-bare-fn.rs` * `tests/ui/async-await/async-closures/signature-inference-from-two-part-bound.rs` </details> ## Remaining bugs and open issues * rust-lang#120694 tracks moving onto more general `LendingFn*` traits. No action needed, since it's not observable. * rust-lang#124020 - Polymorphization ICE. Polymorphization needs to be heavily reworked. No action needed. * rust-lang#127227 - Tracking reworking the way that rustdoc re-sugars bounds. * The part relevant to to `AsyncFn` is fixed by rust-lang#132697. ## Where do we expect rewriting `|| async {}` into `async || {}` to fail? * Fn pointer coercions * Currently, it is not possible to coerce an async closure to an fn pointer like regular closures can be. This functionality may be implemented in the future. ```rust let x: fn() -> _ = async || {}; ``` * Argument capture * Like async functions, async closures always capture their input arguments. This is in contrast to something like `|t: T| async {}`, which doesn't capture `t` unless it is used in the async block. This may affect the `Send`-ness of the future or affect its outlives. ```rust fn needs_send_future(_: impl Fn(NotSendArg) -> Fut) where Fut: Future<Output = ()>, {} needs_send_future(async |_| {}); ``` ## History #### Important feature history - rust-lang#51580 - rust-lang#62292 - rust-lang#120361 - rust-lang#120712 - rust-lang#121857 - rust-lang#123660 - rust-lang#125259 - rust-lang#128506 - rust-lang#127482 ## Acknowledgements Thanks to `@oli-obk` for reviewing the bulk of the work for this feature. Thanks to `@nikomatsakis` for his design blog posts which generated interest for this feature, `@traviscross` for feedback and additions to this stabilization report. All errors are my own. r? `@ghost`
2 parents 915e7eb + 5a1a5e8 commit f4f0faf

File tree

185 files changed

+314
-555
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

185 files changed

+314
-555
lines changed

compiler/rustc_ast_passes/src/feature_gate.rs

-5
Original file line numberDiff line numberDiff line change
@@ -511,11 +511,6 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session, features: &Features) {
511511
"you can write `if matches!(<expr>, <pattern>)` instead of `if let <pattern> = <expr>`"
512512
);
513513
gate_all!(let_chains, "`let` expressions in this position are unstable");
514-
gate_all!(
515-
async_closure,
516-
"async closures are unstable",
517-
"to use an async block, remove the `||`: `async {`"
518-
);
519514
gate_all!(
520515
async_trait_bounds,
521516
"`async` trait bounds are unstable",

compiler/rustc_error_codes/src/error_codes/E0708.md

-4
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
Erroneous code example:
66

77
```edition2018
8-
#![feature(async_closure)]
9-
108
fn main() {
119
let add_one = async |num: u8| {
1210
num + 1
@@ -18,8 +16,6 @@ fn main() {
1816
version, you can use successfully by using move:
1917

2018
```edition2018
21-
#![feature(async_closure)]
22-
2319
fn main() {
2420
let add_one = async move |num: u8| { // ok!
2521
num + 1

compiler/rustc_feature/src/accepted.rs

+2
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ declare_features! (
7272
(accepted, associated_types, "1.0.0", None),
7373
/// Allows free and inherent `async fn`s, `async` blocks, and `<expr>.await` expressions.
7474
(accepted, async_await, "1.39.0", Some(50547)),
75+
/// Allows `async || body` closures.
76+
(accepted, async_closure, "CURRENT_RUSTC_VERSION", Some(62290)),
7577
/// Allows async functions to be declared, implemented, and used in traits.
7678
(accepted, async_fn_in_trait, "1.75.0", Some(91611)),
7779
/// Allows all literals in attribute lists and values of key-value pairs.

compiler/rustc_feature/src/unstable.rs

-2
Original file line numberDiff line numberDiff line change
@@ -388,8 +388,6 @@ declare_features! (
388388
(unstable, associated_const_equality, "1.58.0", Some(92827)),
389389
/// Allows associated type defaults.
390390
(unstable, associated_type_defaults, "1.2.0", Some(29661)),
391-
/// Allows `async || body` closures.
392-
(unstable, async_closure, "1.37.0", Some(62290)),
393391
/// Allows async functions to be called from `dyn Trait`.
394392
(incomplete, async_fn_in_dyn_trait, "CURRENT_RUSTC_VERSION", Some(133119)),
395393
/// Allows `#[track_caller]` on async functions.

compiler/rustc_hir_typeck/src/upvar.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1840,7 +1840,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
18401840
/// captured by move.
18411841
///
18421842
/// ```rust
1843-
/// #![feature(async_closure)]
18441843
/// let x = &1i32; // Let's call this lifetime `'1`.
18451844
/// let c = async move || {
18461845
/// println!("{:?}", *x);
@@ -1855,7 +1854,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
18551854
/// child capture with the lifetime of the parent coroutine-closure's env.
18561855
///
18571856
/// ```rust
1858-
/// #![feature(async_closure)]
18591857
/// let mut x = 1i32;
18601858
/// let c = async || {
18611859
/// x = 1;

compiler/rustc_lint/src/async_closures.rs

-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ declare_lint! {
1212
/// ### Example
1313
///
1414
/// ```rust
15-
/// #![feature(async_closure)]
1615
/// #![warn(closure_returning_async_block)]
1716
/// let c = |x: &str| async {};
1817
/// ```
@@ -40,8 +39,6 @@ declare_lint! {
4039
/// But it does work with async closures:
4140
///
4241
/// ```rust
43-
/// #![feature(async_closure)]
44-
///
4542
/// async fn callback(x: &str) {}
4643
///
4744
/// let captured_str = String::new();
@@ -52,7 +49,6 @@ declare_lint! {
5249
pub CLOSURE_RETURNING_ASYNC_BLOCK,
5350
Allow,
5451
"closure that returns `async {}` could be rewritten as an async closure",
55-
@feature_gate = async_closure;
5652
}
5753

5854
declare_lint_pass!(

compiler/rustc_mir_transform/src/coroutine/by_move_body.rs

-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
//!
44
//! Consider an async closure like:
55
//! ```rust
6-
//! #![feature(async_closure)]
7-
//!
86
//! let x = vec![1, 2, 3];
97
//!
108
//! let closure = async move || {

compiler/rustc_parse/src/parser/expr.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -2366,10 +2366,7 @@ impl<'a> Parser<'a> {
23662366
};
23672367

23682368
match coroutine_kind {
2369-
Some(CoroutineKind::Async { span, .. }) => {
2370-
// Feature-gate `async ||` closures.
2371-
self.psess.gated_spans.gate(sym::async_closure, span);
2372-
}
2369+
Some(CoroutineKind::Async { .. }) => {}
23732370
Some(CoroutineKind::Gen { span, .. }) | Some(CoroutineKind::AsyncGen { span, .. }) => {
23742371
// Feature-gate `gen ||` and `async gen ||` closures.
23752372
// FIXME(gen_blocks): This perhaps should be a different gate.

library/alloc/src/boxed.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -1985,7 +1985,8 @@ impl<Args: Tuple, F: Fn<Args> + ?Sized, A: Allocator> Fn<Args> for Box<F, A> {
19851985
}
19861986
}
19871987

1988-
#[unstable(feature = "async_fn_traits", issue = "none")]
1988+
#[cfg_attr(bootstrap, unstable(feature = "async_closure", issue = "62290"))]
1989+
#[cfg_attr(not(bootstrap), stable(feature = "async_closure", since = "CURRENT_RUSTC_VERSION"))]
19891990
impl<Args: Tuple, F: AsyncFnOnce<Args> + ?Sized, A: Allocator> AsyncFnOnce<Args> for Box<F, A> {
19901991
type Output = F::Output;
19911992
type CallOnceFuture = F::CallOnceFuture;
@@ -1995,7 +1996,8 @@ impl<Args: Tuple, F: AsyncFnOnce<Args> + ?Sized, A: Allocator> AsyncFnOnce<Args>
19951996
}
19961997
}
19971998

1998-
#[unstable(feature = "async_fn_traits", issue = "none")]
1999+
#[cfg_attr(bootstrap, unstable(feature = "async_closure", issue = "62290"))]
2000+
#[cfg_attr(not(bootstrap), stable(feature = "async_closure", since = "CURRENT_RUSTC_VERSION"))]
19992001
impl<Args: Tuple, F: AsyncFnMut<Args> + ?Sized, A: Allocator> AsyncFnMut<Args> for Box<F, A> {
20002002
type CallRefFuture<'a>
20012003
= F::CallRefFuture<'a>
@@ -2007,7 +2009,8 @@ impl<Args: Tuple, F: AsyncFnMut<Args> + ?Sized, A: Allocator> AsyncFnMut<Args> f
20072009
}
20082010
}
20092011

2010-
#[unstable(feature = "async_fn_traits", issue = "none")]
2012+
#[cfg_attr(bootstrap, unstable(feature = "async_closure", issue = "62290"))]
2013+
#[cfg_attr(not(bootstrap), stable(feature = "async_closure", since = "CURRENT_RUSTC_VERSION"))]
20112014
impl<Args: Tuple, F: AsyncFn<Args> + ?Sized, A: Allocator> AsyncFn<Args> for Box<F, A> {
20122015
extern "rust-call" fn async_call(&self, args: Args) -> Self::CallRefFuture<'_> {
20132016
F::async_call(self, args)

library/alloc/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@
9191
//
9292
// Library features:
9393
// tidy-alphabetical-start
94+
#![cfg_attr(bootstrap, feature(async_closure))]
9495
#![cfg_attr(test, feature(str_as_str))]
9596
#![feature(alloc_layout_extra)]
9697
#![feature(allocator_api)]
@@ -99,7 +100,6 @@
99100
#![feature(array_windows)]
100101
#![feature(ascii_char)]
101102
#![feature(assert_matches)]
102-
#![feature(async_closure)]
103103
#![feature(async_fn_traits)]
104104
#![feature(async_iterator)]
105105
#![feature(box_uninit_write)]

library/core/src/ops/async_function.rs

+16-8
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ use crate::marker::Tuple;
44
/// An async-aware version of the [`Fn`](crate::ops::Fn) trait.
55
///
66
/// All `async fn` and functions returning futures implement this trait.
7-
#[unstable(feature = "async_closure", issue = "62290")]
7+
#[cfg_attr(bootstrap, unstable(feature = "async_closure", issue = "62290"))]
8+
#[cfg_attr(not(bootstrap), stable(feature = "async_closure", since = "CURRENT_RUSTC_VERSION"))]
89
#[rustc_paren_sugar]
910
#[fundamental]
1011
#[must_use = "async closures are lazy and do nothing unless called"]
@@ -18,7 +19,8 @@ pub trait AsyncFn<Args: Tuple>: AsyncFnMut<Args> {
1819
/// An async-aware version of the [`FnMut`](crate::ops::FnMut) trait.
1920
///
2021
/// All `async fn` and functions returning futures implement this trait.
21-
#[unstable(feature = "async_closure", issue = "62290")]
22+
#[cfg_attr(bootstrap, unstable(feature = "async_closure", issue = "62290"))]
23+
#[cfg_attr(not(bootstrap), stable(feature = "async_closure", since = "CURRENT_RUSTC_VERSION"))]
2224
#[rustc_paren_sugar]
2325
#[fundamental]
2426
#[must_use = "async closures are lazy and do nothing unless called"]
@@ -39,7 +41,8 @@ pub trait AsyncFnMut<Args: Tuple>: AsyncFnOnce<Args> {
3941
/// An async-aware version of the [`FnOnce`](crate::ops::FnOnce) trait.
4042
///
4143
/// All `async fn` and functions returning futures implement this trait.
42-
#[unstable(feature = "async_closure", issue = "62290")]
44+
#[cfg_attr(bootstrap, unstable(feature = "async_closure", issue = "62290"))]
45+
#[cfg_attr(not(bootstrap), stable(feature = "async_closure", since = "CURRENT_RUSTC_VERSION"))]
4346
#[rustc_paren_sugar]
4447
#[fundamental]
4548
#[must_use = "async closures are lazy and do nothing unless called"]
@@ -64,7 +67,8 @@ mod impls {
6467
use super::{AsyncFn, AsyncFnMut, AsyncFnOnce};
6568
use crate::marker::Tuple;
6669

67-
#[unstable(feature = "async_fn_traits", issue = "none")]
70+
#[cfg_attr(bootstrap, unstable(feature = "async_closure", issue = "62290"))]
71+
#[cfg_attr(not(bootstrap), stable(feature = "async_closure", since = "CURRENT_RUSTC_VERSION"))]
6872
impl<A: Tuple, F: ?Sized> AsyncFn<A> for &F
6973
where
7074
F: AsyncFn<A>,
@@ -74,7 +78,8 @@ mod impls {
7478
}
7579
}
7680

77-
#[unstable(feature = "async_fn_traits", issue = "none")]
81+
#[cfg_attr(bootstrap, unstable(feature = "async_closure", issue = "62290"))]
82+
#[cfg_attr(not(bootstrap), stable(feature = "async_closure", since = "CURRENT_RUSTC_VERSION"))]
7883
impl<A: Tuple, F: ?Sized> AsyncFnMut<A> for &F
7984
where
8085
F: AsyncFn<A>,
@@ -89,7 +94,8 @@ mod impls {
8994
}
9095
}
9196

92-
#[unstable(feature = "async_fn_traits", issue = "none")]
97+
#[cfg_attr(bootstrap, unstable(feature = "async_closure", issue = "62290"))]
98+
#[cfg_attr(not(bootstrap), stable(feature = "async_closure", since = "CURRENT_RUSTC_VERSION"))]
9399
impl<'a, A: Tuple, F: ?Sized> AsyncFnOnce<A> for &'a F
94100
where
95101
F: AsyncFn<A>,
@@ -102,7 +108,8 @@ mod impls {
102108
}
103109
}
104110

105-
#[unstable(feature = "async_fn_traits", issue = "none")]
111+
#[cfg_attr(bootstrap, unstable(feature = "async_closure", issue = "62290"))]
112+
#[cfg_attr(not(bootstrap), stable(feature = "async_closure", since = "CURRENT_RUSTC_VERSION"))]
106113
impl<A: Tuple, F: ?Sized> AsyncFnMut<A> for &mut F
107114
where
108115
F: AsyncFnMut<A>,
@@ -117,7 +124,8 @@ mod impls {
117124
}
118125
}
119126

120-
#[unstable(feature = "async_fn_traits", issue = "none")]
127+
#[cfg_attr(bootstrap, unstable(feature = "async_closure", issue = "62290"))]
128+
#[cfg_attr(not(bootstrap), stable(feature = "async_closure", since = "CURRENT_RUSTC_VERSION"))]
121129
impl<'a, A: Tuple, F: ?Sized> AsyncFnOnce<A> for &'a mut F
122130
where
123131
F: AsyncFnMut<A>,

library/std/src/prelude/common.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ pub use crate::marker::{Send, Sized, Sync, Unpin};
1212
#[stable(feature = "rust1", since = "1.0.0")]
1313
#[doc(no_inline)]
1414
pub use crate::ops::{Drop, Fn, FnMut, FnOnce};
15-
#[unstable(feature = "async_closure", issue = "62290")]
15+
#[cfg_attr(bootstrap, unstable(feature = "async_closure", issue = "62290"))]
16+
#[cfg_attr(not(bootstrap), stable(feature = "async_closure", since = "CURRENT_RUSTC_VERSION"))]
1617
#[doc(no_inline)]
1718
pub use crate::ops::{AsyncFn, AsyncFnMut, AsyncFnOnce};
1819

library/std/src/prelude/mod.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@
3333
//!
3434
//! * <code>[std::marker]::{[Copy], [Send], [Sized], [Sync], [Unpin]}</code>,
3535
//! marker traits that indicate fundamental properties of types.
36-
//! * <code>[std::ops]::{[Drop], [Fn], [FnMut], [FnOnce]}</code>, various
37-
//! operations for both destructors and overloading `()`.
36+
//! * <code>[std::ops]::{[Fn], [FnMut], [FnOnce]}</code>, and their analogous
37+
//! async traits, <code>[std::ops]::{[AsyncFn], [AsyncFnMut], [AsyncFnOnce]}</code>.
38+
//! * <code>[std::ops]::[Drop]</code>, for implementing destructors.
3839
//! * <code>[std::mem]::[drop]</code>, a convenience function for explicitly
3940
//! dropping a value.
4041
//! * <code>[std::mem]::{[size_of], [size_of_val]}</code>, to get the size of

src/tools/clippy/tests/ui/async_yields_async.fixed

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#![feature(async_closure)]
21
#![warn(clippy::async_yields_async)]
32
#![allow(clippy::redundant_async_block)]
43

src/tools/clippy/tests/ui/async_yields_async.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#![feature(async_closure)]
21
#![warn(clippy::async_yields_async)]
32
#![allow(clippy::redundant_async_block)]
43

src/tools/clippy/tests/ui/async_yields_async.stderr

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: an async construct yields a type which is itself awaitable
2-
--> tests/ui/async_yields_async.rs:38:9
2+
--> tests/ui/async_yields_async.rs:37:9
33
|
44
LL | let _h = async {
55
| _____________________-
@@ -20,7 +20,7 @@ LL + }.await
2020
|
2121

2222
error: an async construct yields a type which is itself awaitable
23-
--> tests/ui/async_yields_async.rs:43:9
23+
--> tests/ui/async_yields_async.rs:42:9
2424
|
2525
LL | let _i = async {
2626
| ____________________-
@@ -33,7 +33,7 @@ LL | | };
3333
| |_____- outer async construct
3434

3535
error: an async construct yields a type which is itself awaitable
36-
--> tests/ui/async_yields_async.rs:49:9
36+
--> tests/ui/async_yields_async.rs:48:9
3737
|
3838
LL | let _j = async || {
3939
| ________________________-
@@ -52,7 +52,7 @@ LL + }.await
5252
|
5353

5454
error: an async construct yields a type which is itself awaitable
55-
--> tests/ui/async_yields_async.rs:54:9
55+
--> tests/ui/async_yields_async.rs:53:9
5656
|
5757
LL | let _k = async || {
5858
| _______________________-
@@ -65,7 +65,7 @@ LL | | };
6565
| |_____- outer async construct
6666

6767
error: an async construct yields a type which is itself awaitable
68-
--> tests/ui/async_yields_async.rs:56:23
68+
--> tests/ui/async_yields_async.rs:55:23
6969
|
7070
LL | let _l = async || CustomFutureType;
7171
| ^^^^^^^^^^^^^^^^
@@ -75,7 +75,7 @@ LL | let _l = async || CustomFutureType;
7575
| help: consider awaiting this value: `CustomFutureType.await`
7676

7777
error: an async construct yields a type which is itself awaitable
78-
--> tests/ui/async_yields_async.rs:62:9
78+
--> tests/ui/async_yields_async.rs:61:9
7979
|
8080
LL | let _m = async || {
8181
| _______________________-

src/tools/clippy/tests/ui/author/blocks.rs

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
#![allow(redundant_semicolons, clippy::no_effect)]
44
#![feature(stmt_expr_attributes)]
5-
#![feature(async_closure)]
65

76
#[rustfmt::skip]
87
fn main() {

src/tools/clippy/tests/ui/infinite_loops.rs

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
#![allow(clippy::never_loop)]
55
#![warn(clippy::infinite_loop)]
6-
#![feature(async_closure)]
76

87
extern crate proc_macros;
98
use proc_macros::{external, with_span};

0 commit comments

Comments
 (0)