Skip to content

Commit e2368f5

Browse files
Gate async fn trait bound modifier on async_trait_bounds
1 parent 9525e59 commit e2368f5

26 files changed

+90
-51
lines changed

compiler/rustc_ast_passes/src/feature_gate.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,11 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session, features: &Features) {
516516
"async closures are unstable",
517517
"to use an async block, remove the `||`: `async {`"
518518
);
519+
gate_all!(
520+
async_trait_bounds,
521+
"`async` trait bounds are unstable",
522+
"use the desugared name of the async trait, such as `AsyncFn`"
523+
);
519524
gate_all!(async_for_loop, "`for await` loops are experimental");
520525
gate_all!(
521526
closure_lifetime_binder,

compiler/rustc_feature/src/unstable.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,8 @@ declare_features! (
390390
(unstable, async_fn_track_caller, "1.73.0", Some(110011)),
391391
/// Allows `for await` loops.
392392
(unstable, async_for_loop, "1.77.0", Some(118898)),
393+
/// Allows `async` trait bound modifier.
394+
(unstable, async_trait_bounds, "CURRENT_RUSTC_VERSION", Some(62290)),
393395
/// Allows using C-variadics.
394396
(unstable, c_variadic, "1.34.0", Some(44930)),
395397
/// Allows the use of `#[cfg(<true/false>)]`.

compiler/rustc_parse/src/parser/ty.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -943,7 +943,7 @@ impl<'a> Parser<'a> {
943943
let asyncness = if self.token.uninterpolated_span().at_least_rust_2018()
944944
&& self.eat_keyword(kw::Async)
945945
{
946-
self.psess.gated_spans.gate(sym::async_closure, self.prev_token.span);
946+
self.psess.gated_spans.gate(sym::async_trait_bounds, self.prev_token.span);
947947
BoundAsyncness::Async(self.prev_token.span)
948948
} else if self.may_recover()
949949
&& self.token.uninterpolated_span().is_rust_2015()
@@ -954,7 +954,7 @@ impl<'a> Parser<'a> {
954954
span: self.prev_token.span,
955955
help: HelpUseLatestEdition::new(),
956956
});
957-
self.psess.gated_spans.gate(sym::async_closure, self.prev_token.span);
957+
self.psess.gated_spans.gate(sym::async_trait_bounds, self.prev_token.span);
958958
BoundAsyncness::Async(self.prev_token.span)
959959
} else {
960960
BoundAsyncness::Normal

compiler/rustc_span/src/symbol.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,7 @@ symbols! {
464464
async_for_loop,
465465
async_iterator,
466466
async_iterator_poll_next,
467+
async_trait_bounds,
467468
atomic,
468469
atomic_mod,
469470
atomics,

src/tools/miri/tests/pass/async-closure-captures.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Same as rustc's `tests/ui/async-await/async-closures/captures.rs`, keep in sync
22

3-
#![feature(async_closure, noop_waker)]
3+
#![feature(async_closure, noop_waker, async_trait_bounds)]
44

55
use std::future::Future;
66
use std::pin::pin;

src/tools/miri/tests/pass/async-closure-drop.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![feature(async_closure, noop_waker, async_fn_traits)]
1+
#![feature(async_closure, noop_waker, async_trait_bounds)]
22

33
use std::future::Future;
44
use std::pin::pin;

tests/coverage/async_closure.cov-map

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
Function name: async_closure::call_once::<async_closure::main::{closure#0}>
2-
Raw bytes (9): 0x[01, 01, 00, 01, 01, 07, 01, 00, 2c]
2+
Raw bytes (9): 0x[01, 01, 00, 01, 01, 07, 01, 00, 2b]
33
Number of files: 1
44
- file 0 => global file 1
55
Number of expressions: 0
66
Number of file 0 mappings: 1
7-
- Code(Counter(0)) at (prev + 7, 1) to (start + 0, 44)
7+
- Code(Counter(0)) at (prev + 7, 1) to (start + 0, 43)
88
Highest counter ID seen: c0
99

1010
Function name: async_closure::call_once::<async_closure::main::{closure#0}>::{closure#0}
11-
Raw bytes (14): 0x[01, 01, 00, 02, 01, 07, 2c, 01, 0e, 05, 02, 01, 00, 02]
11+
Raw bytes (14): 0x[01, 01, 00, 02, 01, 07, 2b, 01, 0e, 05, 02, 01, 00, 02]
1212
Number of files: 1
1313
- file 0 => global file 1
1414
Number of expressions: 0
1515
Number of file 0 mappings: 2
16-
- Code(Counter(0)) at (prev + 7, 44) to (start + 1, 14)
16+
- Code(Counter(0)) at (prev + 7, 43) to (start + 1, 14)
1717
- Code(Counter(1)) at (prev + 2, 1) to (start + 0, 2)
1818
Highest counter ID seen: c1
1919

tests/coverage/async_closure.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//@ aux-build: executor.rs
55
extern crate executor;
66

7-
async fn call_once(f: impl async FnOnce()) {
7+
async fn call_once(f: impl AsyncFnOnce()) {
88
f().await;
99
}
1010

tests/crashes/124020.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//@ known-bug: #124020
22
//@ compile-flags: -Zpolymorphize=on --edition=2018 --crate-type=lib
33

4-
#![feature(async_closure, noop_waker, async_fn_traits)]
4+
#![feature(async_closure, noop_waker, async_trait_bounds)]
55

66
use std::future::Future;
77
use std::pin::pin;
@@ -19,7 +19,7 @@ pub fn block_on<T>(fut: impl Future<Output = T>) -> T {
1919
}
2020
}
2121

22-
async fn call_once(f: impl async FnOnce(DropMe)) {
22+
async fn call_once(f: impl AsyncFnOnce(DropMe)) {
2323
f(DropMe("world")).await;
2424
}
2525

tests/ui/async-await/async-fn/dyn-pos.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#![feature(async_closure)]
44

5-
fn foo(x: &dyn async Fn()) {}
5+
fn foo(x: &dyn AsyncFn()) {}
66
//~^ ERROR the trait `AsyncFn` cannot be made into an object
77
//~| ERROR the trait `AsyncFnMut` cannot be made into an object
88
//~| ERROR the trait `AsyncFnMut` cannot be made into an object

0 commit comments

Comments
 (0)