Skip to content

Commit f97a235

Browse files
Stabilize async closures
1 parent ab42fb1 commit f97a235

File tree

171 files changed

+271
-497
lines changed

Some content is hidden

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

171 files changed

+271
-497
lines changed

Diff for: compiler/rustc_ast_passes/src/feature_gate.rs

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

Diff for: 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

Diff for: 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.

Diff for: compiler/rustc_feature/src/unstable.rs

-2
Original file line numberDiff line numberDiff line change
@@ -381,8 +381,6 @@ declare_features! (
381381
(unstable, associated_const_equality, "1.58.0", Some(92827)),
382382
/// Allows associated type defaults.
383383
(unstable, associated_type_defaults, "1.2.0", Some(29661)),
384-
/// Allows `async || body` closures.
385-
(unstable, async_closure, "1.37.0", Some(62290)),
386384
/// Allows `#[track_caller]` on async functions.
387385
(unstable, async_fn_track_caller, "1.73.0", Some(110011)),
388386
/// Allows `for await` loops.

Diff for: compiler/rustc_hir_typeck/src/upvar.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1826,7 +1826,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
18261826
/// captured by move.
18271827
///
18281828
/// ```rust
1829-
/// #![feature(async_closure)]
18301829
/// let x = &1i32; // Let's call this lifetime `'1`.
18311830
/// let c = async move || {
18321831
/// println!("{:?}", *x);
@@ -1841,7 +1840,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
18411840
/// child capture with the lifetime of the parent coroutine-closure's env.
18421841
///
18431842
/// ```rust
1844-
/// #![feature(async_closure)]
18451843
/// let mut x = 1i32;
18461844
/// let c = async || {
18471845
/// x = 1;

Diff for: 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!(

Diff for: 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 || {

Diff for: compiler/rustc_parse/src/parser/expr.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -2362,10 +2362,7 @@ impl<'a> Parser<'a> {
23622362
};
23632363

23642364
match coroutine_kind {
2365-
Some(CoroutineKind::Async { span, .. }) => {
2366-
// Feature-gate `async ||` closures.
2367-
self.psess.gated_spans.gate(sym::async_closure, span);
2368-
}
2365+
Some(CoroutineKind::Async { .. }) => {}
23692366
Some(CoroutineKind::Gen { span, .. }) | Some(CoroutineKind::AsyncGen { span, .. }) => {
23702367
// Feature-gate `gen ||` and `async gen ||` closures.
23712368
// FIXME(gen_blocks): This perhaps should be a different gate.

Diff for: library/alloc/src/boxed.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -1982,7 +1982,8 @@ impl<Args: Tuple, F: Fn<Args> + ?Sized, A: Allocator> Fn<Args> for Box<F, A> {
19821982
}
19831983
}
19841984

1985-
#[unstable(feature = "async_fn_traits", issue = "none")]
1985+
#[cfg_attr(bootstrap, unstable(feature = "async_closure", issue = "62290"))]
1986+
#[cfg_attr(not(bootstrap), stable(feature = "async_closure", since = "CURRENT_RUSTC_VERSION"))]
19861987
impl<Args: Tuple, F: AsyncFnOnce<Args> + ?Sized, A: Allocator> AsyncFnOnce<Args> for Box<F, A> {
19871988
type Output = F::Output;
19881989
type CallOnceFuture = F::CallOnceFuture;
@@ -1992,7 +1993,8 @@ impl<Args: Tuple, F: AsyncFnOnce<Args> + ?Sized, A: Allocator> AsyncFnOnce<Args>
19921993
}
19931994
}
19941995

1995-
#[unstable(feature = "async_fn_traits", issue = "none")]
1996+
#[cfg_attr(bootstrap, unstable(feature = "async_closure", issue = "62290"))]
1997+
#[cfg_attr(not(bootstrap), stable(feature = "async_closure", since = "CURRENT_RUSTC_VERSION"))]
19961998
impl<Args: Tuple, F: AsyncFnMut<Args> + ?Sized, A: Allocator> AsyncFnMut<Args> for Box<F, A> {
19971999
type CallRefFuture<'a>
19982000
= F::CallRefFuture<'a>
@@ -2004,7 +2006,8 @@ impl<Args: Tuple, F: AsyncFnMut<Args> + ?Sized, A: Allocator> AsyncFnMut<Args> f
20042006
}
20052007
}
20062008

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

Diff for: 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(not(no_global_oom_handling), feature(const_alloc_error))]
9596
#![cfg_attr(not(no_global_oom_handling), feature(const_btree_len))]
9697
#![cfg_attr(test, feature(str_as_str))]
@@ -101,7 +102,6 @@
101102
#![feature(array_windows)]
102103
#![feature(ascii_char)]
103104
#![feature(assert_matches)]
104-
#![feature(async_closure)]
105105
#![feature(async_fn_traits)]
106106
#![feature(async_iterator)]
107107
#![feature(box_uninit_write)]

Diff for: 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>,

Diff for: 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

Diff for: 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

Diff for: 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

Diff for: 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
| _______________________-

Diff for: 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() {

Diff for: src/tools/clippy/tests/ui/redundant_closure_call_fixable.fixed

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

Diff for: src/tools/clippy/tests/ui/redundant_closure_call_fixable.rs

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

0 commit comments

Comments
 (0)