Skip to content

Commit 3f7e7c2

Browse files
authored
Rollup merge of #63209 - Centril:stabilize-async-await, r=cramertj
Stabilize `async_await` in Rust 1.39.0 Here we stabilize: - free and inherent `async fn`s, - the `<expr>.await` expression form, - and the `async move? { ... }` block form. Closes #62149. Closes #50547. All the blockers are now closed. <details> - [x] FCP in #62149 - [x] #61949; PR in #62849. - [x] #62517; PR in #63376. - [x] #63225; PR in #63501 - [x] #63388; PR in #63499 - [x] #63500; PR in #63501 - [x] #62121 (comment) - [x] Some tests for control flow (PR #63387): - `?` - `return` in `async` blocks - `break` - [x] #61775 (comment), i.e. tests for #60944 with `async fn`s instead). PR in #63383 </details> r? @cramertj
2 parents 4593f40 + 21476e7 commit 3f7e7c2

File tree

181 files changed

+271
-605
lines changed

Some content is hidden

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

181 files changed

+271
-605
lines changed

src/librustc/error_codes.rs

-2
Original file line numberDiff line numberDiff line change
@@ -2088,7 +2088,6 @@ generator can be constructed.
20882088
Erroneous code example:
20892089
20902090
```edition2018,compile-fail,E0698
2091-
#![feature(async_await)]
20922091
async fn bar<T>() -> () {}
20932092
20942093
async fn foo() {
@@ -2101,7 +2100,6 @@ To fix this you must bind `T` to a concrete type such as `String`
21012100
so that a generator can then be constructed:
21022101
21032102
```edition2018
2104-
#![feature(async_await)]
21052103
async fn bar<T>() -> () {}
21062104
21072105
async fn foo() {

src/librustc_typeck/check/mod.rs

-2
Original file line numberDiff line numberDiff line change
@@ -4197,8 +4197,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
41974197
/// A possible error is to forget to add `.await` when using futures:
41984198
///
41994199
/// ```
4200-
/// #![feature(async_await)]
4201-
///
42024200
/// async fn make_u32() -> u32 {
42034201
/// 22
42044202
/// }

src/librustc_typeck/error_codes.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -4751,7 +4751,6 @@ E0733: r##"
47514751
Recursion in an `async fn` requires boxing. For example, this will not compile:
47524752
47534753
```edition2018,compile_fail,E0733
4754-
#![feature(async_await)]
47554754
async fn foo(n: usize) {
47564755
if n > 0 {
47574756
foo(n - 1).await;
@@ -4763,12 +4762,11 @@ To achieve async recursion, the `async fn` needs to be desugared
47634762
such that the `Future` is explicit in the return type:
47644763
47654764
```edition2018,compile_fail,E0720
4766-
# #![feature(async_await)]
47674765
use std::future::Future;
4768-
fn foo_desugered(n: usize) -> impl Future<Output = ()> {
4766+
fn foo_desugared(n: usize) -> impl Future<Output = ()> {
47694767
async move {
47704768
if n > 0 {
4771-
foo_desugered(n - 1).await;
4769+
foo_desugared(n - 1).await;
47724770
}
47734771
}
47744772
}
@@ -4777,7 +4775,6 @@ fn foo_desugered(n: usize) -> impl Future<Output = ()> {
47774775
Finally, the future is wrapped in a pinned box:
47784776
47794777
```edition2018
4780-
# #![feature(async_await)]
47814778
use std::future::Future;
47824779
use std::pin::Pin;
47834780
fn foo_recursive(n: usize) -> Pin<Box<dyn Future<Output = ()>>> {

src/libstd/keyword_docs.rs

-2
Original file line numberDiff line numberDiff line change
@@ -984,7 +984,6 @@ mod where_keyword { }
984984

985985
// 2018 Edition keywords
986986

987-
#[unstable(feature = "async_await", issue = "50547")]
988987
#[doc(keyword = "async")]
989988
//
990989
/// Return a [`Future`] instead of blocking the current thread.
@@ -995,7 +994,6 @@ mod where_keyword { }
995994
/// [not yet complete]: https://github.com/rust-lang/rust/issues/34601
996995
mod async_keyword { }
997996

998-
#[unstable(feature = "async_await", issue = "50547")]
999997
#[doc(keyword = "await")]
1000998
//
1001999
/// Suspend execution until the result of a [`Future`] is ready.

src/libsyntax/feature_gate.rs

+2-17
Original file line numberDiff line numberDiff line change
@@ -461,9 +461,6 @@ declare_features! (
461461
// Allows using `#[doc(keyword = "...")]`.
462462
(active, doc_keyword, "1.28.0", Some(51315), None),
463463

464-
// Allows async and await syntax.
465-
(active, async_await, "1.28.0", Some(50547), None),
466-
467464
// Allows reinterpretation of the bits of a value of one type as another type during const eval.
468465
(active, const_transmute, "1.29.0", Some(53605), None),
469466

@@ -857,6 +854,8 @@ declare_features! (
857854
(accepted, repr_align_enum, "1.37.0", Some(57996), None),
858855
// Allows `const _: TYPE = VALUE`.
859856
(accepted, underscore_const_names, "1.37.0", Some(54912), None),
857+
// Allows free and inherent `async fn`s, `async` blocks, and `<expr>.await` expressions.
858+
(accepted, async_await, "1.38.0", Some(50547), None),
860859

861860
// -------------------------------------------------------------------------
862861
// feature-group-end: accepted features
@@ -2100,12 +2099,6 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
21002099
"labels on blocks are unstable");
21012100
}
21022101
}
2103-
ast::ExprKind::Async(..) => {
2104-
gate_feature_post!(&self, async_await, e.span, "async blocks are unstable");
2105-
}
2106-
ast::ExprKind::Await(_) => {
2107-
gate_feature_post!(&self, async_await, e.span, "async/await is unstable");
2108-
}
21092102
_ => {}
21102103
}
21112104
visit::walk_expr(self, e)
@@ -2154,11 +2147,6 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
21542147
span: Span,
21552148
_node_id: NodeId) {
21562149
if let Some(header) = fn_kind.header() {
2157-
// Check for const fn and async fn declarations.
2158-
if header.asyncness.node.is_async() {
2159-
gate_feature_post!(&self, async_await, span, "async fn is unstable");
2160-
}
2161-
21622150
// Stability of const fn methods are covered in
21632151
// `visit_trait_item` and `visit_impl_item` below; this is
21642152
// because default methods don't pass through this point.
@@ -2198,9 +2186,6 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
21982186
if block.is_none() {
21992187
self.check_abi(sig.header.abi, ti.span);
22002188
}
2201-
if sig.header.asyncness.node.is_async() {
2202-
gate_feature_post!(&self, async_await, ti.span, "async fn is unstable");
2203-
}
22042189
if sig.decl.c_variadic {
22052190
gate_feature_post!(&self, c_variadic, ti.span,
22062191
"C-variadic functions are unstable");

src/test/rustdoc/async-fn.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
// edition:2018
22

3-
#![feature(async_await)]
4-
53
// @has async_fn/fn.foo.html '//pre[@class="rust fn"]' 'pub async fn foo() -> Option<Foo>'
64
pub async fn foo() -> Option<Foo> {
75
None

src/test/rustdoc/async-move-doctest.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
// compile-flags:--test
22
// edition:2018
33

4-
// prior to setting the default edition for the doctest pre-parser, this doctest would fail due to
5-
// a fatal parsing error
4+
// Prior to setting the default edition for the doctest pre-parser,
5+
// this doctest would fail due to a fatal parsing error.
66
// see https://github.com/rust-lang/rust/issues/59313
77

88
//! ```
9-
//! #![feature(async_await)]
10-
//!
119
//! fn foo() {
1210
//! drop(async move {});
1311
//! }

src/test/rustdoc/edition-flag.rs

-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
// compile-flags:--test -Z unstable-options
22
// edition:2018
33

4-
#![feature(async_await)]
5-
64
/// ```rust
7-
/// #![feature(async_await)]
85
/// fn main() {
96
/// let _ = async { };
107
/// }

src/test/ui/async-await/argument-patterns.rs

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

44
#![allow(unused_variables)]
55
#![deny(unused_mut)]
6-
#![feature(async_await)]
76

87
type A = Vec<u32>;
98

src/test/ui/async-await/async-await.rs

-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
// edition:2018
44
// aux-build:arc_wake.rs
55

6-
#![feature(async_await)]
7-
86
extern crate arc_wake;
97

108
use std::pin::Pin;

src/test/ui/async-await/async-block-control-flow-static-semantics.rs

-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
// edition:2018
77
// ignore-tidy-linelength
88

9-
#![feature(async_await)]
10-
119
fn main() {}
1210

1311
use core::future::Future;

src/test/ui/async-await/async-block-control-flow-static-semantics.stderr

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
error[E0267]: `break` inside of an async block
2-
--> $DIR/async-block-control-flow-static-semantics.rs:35:9
2+
--> $DIR/async-block-control-flow-static-semantics.rs:33:9
33
|
44
LL | break 0u8;
55
| ^^^^^^^^^ cannot break inside of an async block
66

77
error[E0267]: `break` inside of an async block
8-
--> $DIR/async-block-control-flow-static-semantics.rs:42:13
8+
--> $DIR/async-block-control-flow-static-semantics.rs:40:13
99
|
1010
LL | break 0u8;
1111
| ^^^^^^^^^ cannot break inside of an async block
1212

1313
error[E0308]: mismatched types
14-
--> $DIR/async-block-control-flow-static-semantics.rs:15:43
14+
--> $DIR/async-block-control-flow-static-semantics.rs:13:43
1515
|
1616
LL | fn return_targets_async_block_not_fn() -> u8 {
1717
| --------------------------------- ^^ expected u8, found ()
@@ -22,7 +22,7 @@ LL | fn return_targets_async_block_not_fn() -> u8 {
2222
found type `()`
2323

2424
error[E0271]: type mismatch resolving `<impl std::future::Future as std::future::Future>::Output == ()`
25-
--> $DIR/async-block-control-flow-static-semantics.rs:20:39
25+
--> $DIR/async-block-control-flow-static-semantics.rs:18:39
2626
|
2727
LL | let _: &dyn Future<Output = ()> = &block;
2828
| ^^^^^^ expected u8, found ()
@@ -32,7 +32,7 @@ LL | let _: &dyn Future<Output = ()> = &block;
3232
= note: required for the cast to the object type `dyn std::future::Future<Output = ()>`
3333

3434
error[E0271]: type mismatch resolving `<impl std::future::Future as std::future::Future>::Output == ()`
35-
--> $DIR/async-block-control-flow-static-semantics.rs:29:39
35+
--> $DIR/async-block-control-flow-static-semantics.rs:27:39
3636
|
3737
LL | let _: &dyn Future<Output = ()> = &block;
3838
| ^^^^^^ expected u8, found ()
@@ -42,7 +42,7 @@ LL | let _: &dyn Future<Output = ()> = &block;
4242
= note: required for the cast to the object type `dyn std::future::Future<Output = ()>`
4343

4444
error[E0271]: type mismatch resolving `<impl std::future::Future as std::future::Future>::Output == u8`
45-
--> $DIR/async-block-control-flow-static-semantics.rs:24:55
45+
--> $DIR/async-block-control-flow-static-semantics.rs:22:55
4646
|
4747
LL | async fn return_targets_async_block_not_async_fn() -> u8 {
4848
| ^^ expected (), found u8
@@ -52,7 +52,7 @@ LL | async fn return_targets_async_block_not_async_fn() -> u8 {
5252
= note: the return type of a function must have a statically known size
5353

5454
error[E0308]: mismatched types
55-
--> $DIR/async-block-control-flow-static-semantics.rs:50:44
55+
--> $DIR/async-block-control-flow-static-semantics.rs:48:44
5656
|
5757
LL | fn rethrow_targets_async_block_not_fn() -> Result<u8, MyErr> {
5858
| ---------------------------------- ^^^^^^^^^^^^^^^^^ expected enum `std::result::Result`, found ()
@@ -63,7 +63,7 @@ LL | fn rethrow_targets_async_block_not_fn() -> Result<u8, MyErr> {
6363
found type `()`
6464

6565
error[E0308]: mismatched types
66-
--> $DIR/async-block-control-flow-static-semantics.rs:59:50
66+
--> $DIR/async-block-control-flow-static-semantics.rs:57:50
6767
|
6868
LL | fn rethrow_targets_async_block_not_async_fn() -> Result<u8, MyErr> {
6969
| ---------------------------------------- ^^^^^^^^^^^^^^^^^ expected enum `std::result::Result`, found ()

src/test/ui/async-await/async-closure-matches-expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// build-pass
22
// edition:2018
33

4-
#![feature(async_await, async_closure)]
4+
#![feature(async_closure)]
55

66
macro_rules! match_expr {
77
($x:expr) => {}

src/test/ui/async-await/async-closure.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// edition:2018
44
// aux-build:arc_wake.rs
55

6-
#![feature(async_await, async_closure)]
6+
#![feature(async_closure)]
77

88
extern crate arc_wake;
99

src/test/ui/async-await/async-error-span.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// edition:2018
2-
#![feature(async_await)]
32

4-
// Regression test for issue #62382
3+
// Regression test for issue #62382.
54

65
use std::future::Future;
76

src/test/ui/async-await/async-error-span.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
error[E0698]: type inside `async` object must be known in this context
2-
--> $DIR/async-error-span.rs:13:9
2+
--> $DIR/async-error-span.rs:12:9
33
|
44
LL | let a;
55
| ^ cannot infer type
66
|
77
note: the type is part of the `async` object because of this `await`
8-
--> $DIR/async-error-span.rs:14:5
8+
--> $DIR/async-error-span.rs:13:5
99
|
1010
LL | get_future().await;
1111
| ^^^^^^^^^^^^^^^^^^

src/test/ui/async-await/async-fn-elided-impl-lifetime-parameter.rs

-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
// check-pass
77
// edition:2018
88

9-
#![feature(async_await)]
10-
119
struct Foo<'a>(&'a u8);
1210

1311
impl Foo<'_> {

src/test/ui/async-await/async-fn-nonsend.rs

-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// edition:2018
33
// compile-flags: --crate-type lib
44

5-
#![feature(async_await)]
6-
75
use std::{
86
cell::RefCell,
97
fmt::Debug,

0 commit comments

Comments
 (0)