Skip to content

Commit 62900d4

Browse files
Gate async fn trait bound modifier on async_trait_bounds
1 parent 07243a4 commit 62900d4

25 files changed

+86
-47
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
@@ -388,6 +388,8 @@ declare_features! (
388388
(unstable, async_fn_track_caller, "1.73.0", Some(110011)),
389389
/// Allows `for await` loops.
390390
(unstable, async_for_loop, "1.77.0", Some(118898)),
391+
/// Allows `async` trait bound modifier.
392+
(unstable, async_trait_bounds, "CURRENT_RUSTC_VERSION", Some(62290)),
391393
/// Allows using C-variadics.
392394
(unstable, c_variadic, "1.34.0", Some(44930)),
393395
/// 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.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

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0038]: the trait `AsyncFnMut` cannot be made into an object
22
--> $DIR/dyn-pos.rs:5:16
33
|
4-
LL | fn foo(x: &dyn async Fn()) {}
5-
| ^^^^^^^^^^ `AsyncFnMut` cannot be made into an object
4+
LL | fn foo(x: &dyn AsyncFn()) {}
5+
| ^^^^^^^^^ `AsyncFnMut` cannot be made into an object
66
|
77
note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
88
--> $SRC_DIR/core/src/ops/async_function.rs:LL:COL
@@ -16,8 +16,8 @@ note: for a trait to be "dyn-compatible" it needs to allow building a vtable to
1616
error[E0038]: the trait `AsyncFnMut` cannot be made into an object
1717
--> $DIR/dyn-pos.rs:5:16
1818
|
19-
LL | fn foo(x: &dyn async Fn()) {}
20-
| ^^^^^^^^^^ `AsyncFnMut` cannot be made into an object
19+
LL | fn foo(x: &dyn AsyncFn()) {}
20+
| ^^^^^^^^^ `AsyncFnMut` cannot be made into an object
2121
|
2222
note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
2323
--> $SRC_DIR/core/src/ops/async_function.rs:LL:COL
@@ -32,8 +32,8 @@ note: for a trait to be "dyn-compatible" it needs to allow building a vtable to
3232
error[E0038]: the trait `AsyncFnMut` cannot be made into an object
3333
--> $DIR/dyn-pos.rs:5:16
3434
|
35-
LL | fn foo(x: &dyn async Fn()) {}
36-
| ^^^^^^^^^^ `AsyncFnMut` cannot be made into an object
35+
LL | fn foo(x: &dyn AsyncFn()) {}
36+
| ^^^^^^^^^ `AsyncFnMut` cannot be made into an object
3737
|
3838
note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
3939
--> $SRC_DIR/core/src/ops/async_function.rs:LL:COL
@@ -48,8 +48,8 @@ note: for a trait to be "dyn-compatible" it needs to allow building a vtable to
4848
error[E0038]: the trait `AsyncFn` cannot be made into an object
4949
--> $DIR/dyn-pos.rs:5:12
5050
|
51-
LL | fn foo(x: &dyn async Fn()) {}
52-
| ^^^^^^^^^^^^^^ `AsyncFn` cannot be made into an object
51+
LL | fn foo(x: &dyn AsyncFn()) {}
52+
| ^^^^^^^^^^^^^ `AsyncFn` cannot be made into an object
5353
|
5454
note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
5555
--> $SRC_DIR/core/src/ops/async_function.rs:LL:COL

0 commit comments

Comments
 (0)