Skip to content

Commit 773cd53

Browse files
Gate async fn trait bound modifier on async_trait_bounds
1 parent 05dd979 commit 773cd53

23 files changed

+83
-44
lines changed

compiler/rustc_ast_passes/src/feature_gate.rs

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

compiler/rustc_feature/src/unstable.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,8 @@ declare_features! (
387387
(unstable, async_fn_track_caller, "1.73.0", Some(110011)),
388388
/// Allows `for await` loops.
389389
(unstable, async_for_loop, "1.77.0", Some(118898)),
390+
/// Allows `async` trait bound modifier.
391+
(unstable, async_trait_bounds, "CURRENT_RUSTC_VERSION", Some(62290)),
390392
/// Allows using C-variadics.
391393
(unstable, c_variadic, "1.34.0", Some(44930)),
392394
/// 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/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

tests/ui/async-await/async-fn/edition-2015.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
fn foo(x: impl async Fn()) -> impl async Fn() { x }
22
//~^ ERROR `async` trait bounds are only allowed in Rust 2018 or later
33
//~| ERROR `async` trait bounds are only allowed in Rust 2018 or later
4-
//~| ERROR async closures are unstable
5-
//~| ERROR async closures are unstable
4+
//~| ERROR `async` trait bounds are unstable
5+
//~| ERROR `async` trait bounds are unstable
66
//~| ERROR use of unstable library feature `async_closure`
77
//~| ERROR use of unstable library feature `async_closure`
88

tests/ui/async-await/async-fn/edition-2015.stderr

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,27 @@ LL | fn foo(x: impl async Fn()) -> impl async Fn() { x }
1616
= help: pass `--edition 2021` to `rustc`
1717
= note: for more on editions, read https://doc.rust-lang.org/edition-guide
1818

19-
error[E0658]: async closures are unstable
19+
error[E0658]: `async` trait bounds are unstable
2020
--> $DIR/edition-2015.rs:1:16
2121
|
2222
LL | fn foo(x: impl async Fn()) -> impl async Fn() { x }
2323
| ^^^^^
2424
|
2525
= note: see issue #62290 <https://github.com/rust-lang/rust/issues/62290> for more information
26-
= help: add `#![feature(async_closure)]` to the crate attributes to enable
26+
= help: add `#![feature(async_trait_bounds)]` to the crate attributes to enable
2727
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
28-
= help: to use an async block, remove the `||`: `async {`
28+
= help: use the desugared name of the async trait, such as `AsyncFn`
2929

30-
error[E0658]: async closures are unstable
30+
error[E0658]: `async` trait bounds are unstable
3131
--> $DIR/edition-2015.rs:1:36
3232
|
3333
LL | fn foo(x: impl async Fn()) -> impl async Fn() { x }
3434
| ^^^^^
3535
|
3636
= note: see issue #62290 <https://github.com/rust-lang/rust/issues/62290> for more information
37-
= help: add `#![feature(async_closure)]` to the crate attributes to enable
37+
= help: add `#![feature(async_trait_bounds)]` to the crate attributes to enable
3838
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
39-
= help: to use an async block, remove the `||`: `async {`
39+
= help: use the desugared name of the async trait, such as `AsyncFn`
4040

4141
error[E0658]: use of unstable library feature `async_closure`
4242
--> $DIR/edition-2015.rs:1:42

0 commit comments

Comments
 (0)