1
Fork 0

Stabilize async closures

This commit is contained in:
Michael Goulet 2024-11-06 17:53:59 +00:00
parent d4025ee454
commit c605c84be8
184 changed files with 311 additions and 553 deletions

View file

@ -511,11 +511,6 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session, features: &Features) {
"you can write `if matches!(<expr>, <pattern>)` instead of `if let <pattern> = <expr>`"
);
gate_all!(let_chains, "`let` expressions in this position are unstable");
gate_all!(
async_closure,
"async closures are unstable",
"to use an async block, remove the `||`: `async {`"
);
gate_all!(
async_trait_bounds,
"`async` trait bounds are unstable",

View file

@ -5,8 +5,6 @@
Erroneous code example:
```edition2018
#![feature(async_closure)]
fn main() {
let add_one = async |num: u8| {
num + 1
@ -18,8 +16,6 @@ fn main() {
version, you can use successfully by using move:
```edition2018
#![feature(async_closure)]
fn main() {
let add_one = async move |num: u8| { // ok!
num + 1

View file

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

View file

@ -388,8 +388,6 @@ declare_features! (
(unstable, associated_const_equality, "1.58.0", Some(92827)),
/// Allows associated type defaults.
(unstable, associated_type_defaults, "1.2.0", Some(29661)),
/// Allows `async || body` closures.
(unstable, async_closure, "1.37.0", Some(62290)),
/// Allows async functions to be called from `dyn Trait`.
(incomplete, async_fn_in_dyn_trait, "CURRENT_RUSTC_VERSION", Some(133119)),
/// Allows `#[track_caller]` on async functions.

View file

@ -1840,7 +1840,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
/// captured by move.
///
/// ```rust
/// #![feature(async_closure)]
/// let x = &1i32; // Let's call this lifetime `'1`.
/// let c = async move || {
/// println!("{:?}", *x);
@ -1855,7 +1854,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
/// child capture with the lifetime of the parent coroutine-closure's env.
///
/// ```rust
/// #![feature(async_closure)]
/// let mut x = 1i32;
/// let c = async || {
/// x = 1;

View file

@ -12,7 +12,6 @@ declare_lint! {
/// ### Example
///
/// ```rust
/// #![feature(async_closure)]
/// #![warn(closure_returning_async_block)]
/// let c = |x: &str| async {};
/// ```
@ -40,8 +39,6 @@ declare_lint! {
/// But it does work with async closures:
///
/// ```rust
/// #![feature(async_closure)]
///
/// async fn callback(x: &str) {}
///
/// let captured_str = String::new();
@ -52,7 +49,6 @@ declare_lint! {
pub CLOSURE_RETURNING_ASYNC_BLOCK,
Allow,
"closure that returns `async {}` could be rewritten as an async closure",
@feature_gate = async_closure;
}
declare_lint_pass!(

View file

@ -3,8 +3,6 @@
//!
//! Consider an async closure like:
//! ```rust
//! #![feature(async_closure)]
//!
//! let x = vec![1, 2, 3];
//!
//! let closure = async move || {

View file

@ -2366,10 +2366,7 @@ impl<'a> Parser<'a> {
};
match coroutine_kind {
Some(CoroutineKind::Async { span, .. }) => {
// Feature-gate `async ||` closures.
self.psess.gated_spans.gate(sym::async_closure, span);
}
Some(CoroutineKind::Async { .. }) => {}
Some(CoroutineKind::Gen { span, .. }) | Some(CoroutineKind::AsyncGen { span, .. }) => {
// Feature-gate `gen ||` and `async gen ||` closures.
// FIXME(gen_blocks): This perhaps should be a different gate.