Skip to content

Commit 585ead8

Browse files
Gate async fn trait bound modifier on async_trait_bounds
1 parent b493b00 commit 585ead8

23 files changed

+83
-44
lines changed

compiler/rustc_ast_passes/src/feature_gate.rs

+5
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

+2
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

+2-2
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

+1
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

+1-1
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

+1-1
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

+1-1
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

+8-8
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

+2-2
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

+6-6
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

tests/ui/async-await/async-fn/mbe-async-trait-bound-theoretical-regression.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ macro_rules! demo {
1313
}
1414

1515
demo! { impl async Trait }
16-
//~^ ERROR async closures are unstable
16+
//~^ ERROR `async` trait bounds are unstable
1717

1818
demo! { dyn async Trait }
19-
//~^ ERROR async closures are unstable
19+
//~^ ERROR `async` trait bounds are unstable
2020

2121
fn main() {}

tests/ui/async-await/async-fn/mbe-async-trait-bound-theoretical-regression.stderr

+6-6
Original file line numberDiff line numberDiff line change
@@ -20,27 +20,27 @@ LL | demo! { dyn async Trait }
2020
|
2121
= note: this error originates in the macro `demo` (in Nightly builds, run with -Z macro-backtrace for more info)
2222

23-
error[E0658]: async closures are unstable
23+
error[E0658]: `async` trait bounds are unstable
2424
--> $DIR/mbe-async-trait-bound-theoretical-regression.rs:15:14
2525
|
2626
LL | demo! { impl async Trait }
2727
| ^^^^^
2828
|
2929
= note: see issue #62290 <https://github.com/rust-lang/rust/issues/62290> for more information
30-
= help: add `#![feature(async_closure)]` to the crate attributes to enable
30+
= help: add `#![feature(async_trait_bounds)]` to the crate attributes to enable
3131
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
32-
= help: to use an async block, remove the `||`: `async {`
32+
= help: use the desugared name of the async trait, such as `AsyncFn`
3333

34-
error[E0658]: async closures are unstable
34+
error[E0658]: `async` trait bounds are unstable
3535
--> $DIR/mbe-async-trait-bound-theoretical-regression.rs:18:13
3636
|
3737
LL | demo! { dyn async Trait }
3838
| ^^^^^
3939
|
4040
= note: see issue #62290 <https://github.com/rust-lang/rust/issues/62290> for more information
41-
= help: add `#![feature(async_closure)]` to the crate attributes to enable
41+
= help: add `#![feature(async_trait_bounds)]` to the crate attributes to enable
4242
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
43-
= help: to use an async block, remove the `||`: `async {`
43+
= help: use the desugared name of the async trait, such as `AsyncFn`
4444

4545
error: aborting due to 4 previous errors
4646

tests/ui/async-await/async-fn/not-a-trait.rs

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

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

55
struct S;
66

tests/ui/async-await/async-fn/sugar.rs

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

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

66
async fn foo() {}
77

tests/ui/async-await/async-fn/trait-bounds-in-macro.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ macro_rules! x {
66

77
x! {
88
async fn foo() -> impl async Fn() { }
9-
//~^ ERROR async closures are unstable
9+
//~^ ERROR `async` trait bounds are unstable
1010
}
1111

1212
fn main() {}

tests/ui/async-await/async-fn/trait-bounds-in-macro.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
error[E0658]: async closures are unstable
1+
error[E0658]: `async` trait bounds are unstable
22
--> $DIR/trait-bounds-in-macro.rs:8:28
33
|
44
LL | async fn foo() -> impl async Fn() { }
55
| ^^^^^
66
|
77
= note: see issue #62290 <https://github.com/rust-lang/rust/issues/62290> for more information
8-
= help: add `#![feature(async_closure)]` to the crate attributes to enable
8+
= help: add `#![feature(async_trait_bounds)]` to the crate attributes to enable
99
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
10-
= help: to use an async block, remove the `||`: `async {`
10+
= help: use the desugared name of the async trait, such as `AsyncFn`
1111

1212
error: aborting due to 1 previous error
1313

tests/ui/async-await/async-fn/wrong-trait.rs

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

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

55
trait Foo {}
66

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
//@ edition: 2021
2+
3+
fn test(_: impl async Fn()) {}
4+
//~^ ERROR `async` trait bounds are unstable
5+
//~| ERROR use of unstable library feature `async_closure`
6+
7+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
error[E0658]: `async` trait bounds are unstable
2+
--> $DIR/feature-gate-async-trait-bounds.rs:3:17
3+
|
4+
LL | fn test(_: impl async Fn()) {}
5+
| ^^^^^
6+
|
7+
= note: see issue #62290 <https://github.com/rust-lang/rust/issues/62290> for more information
8+
= help: add `#![feature(async_trait_bounds)]` to the crate attributes to enable
9+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
10+
= help: use the desugared name of the async trait, such as `AsyncFn`
11+
12+
error[E0658]: use of unstable library feature `async_closure`
13+
--> $DIR/feature-gate-async-trait-bounds.rs:3:23
14+
|
15+
LL | fn test(_: impl async Fn()) {}
16+
| ^^^^
17+
|
18+
= note: see issue #62290 <https://github.com/rust-lang/rust/issues/62290> for more information
19+
= help: add `#![feature(async_closure)]` to the crate attributes to enable
20+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
21+
22+
error: aborting due to 2 previous errors
23+
24+
For more information about this error, try `rustc --explain E0658`.

tests/ui/impl-trait/precise-capturing/bound-modifiers.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ fn polarity() -> impl Sized + ?use<> {}
77
fn asyncness() -> impl Sized + async use<> {}
88
//~^ ERROR expected identifier, found keyword `use`
99
//~| ERROR cannot find trait `r#use` in this scope
10-
//~| ERROR async closures are unstable
10+
//~| ERROR `async` trait bounds are unstable
1111

1212
fn constness() -> impl Sized + const use<> {}
1313
//~^ ERROR expected identifier, found keyword `use`

tests/ui/impl-trait/precise-capturing/bound-modifiers.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,16 @@ error[E0405]: cannot find trait `r#use` in this scope
4646
LL | fn binder() -> impl Sized + for<'a> use<> {}
4747
| ^^^ not found in this scope
4848

49-
error[E0658]: async closures are unstable
49+
error[E0658]: `async` trait bounds are unstable
5050
--> $DIR/bound-modifiers.rs:7:32
5151
|
5252
LL | fn asyncness() -> impl Sized + async use<> {}
5353
| ^^^^^
5454
|
5555
= note: see issue #62290 <https://github.com/rust-lang/rust/issues/62290> for more information
56-
= help: add `#![feature(async_closure)]` to the crate attributes to enable
56+
= help: add `#![feature(async_trait_bounds)]` to the crate attributes to enable
5757
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
58-
= help: to use an async block, remove the `||`: `async {`
58+
= help: use the desugared name of the async trait, such as `AsyncFn`
5959

6060
error[E0658]: const trait impls are experimental
6161
--> $DIR/bound-modifiers.rs:12:32

tests/ui/parser/bad-recover-kw-after-impl.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ macro_rules! impl_primitive {
1212

1313
impl_primitive!(impl async);
1414
//~^ ERROR expected identifier, found `<eof>`
15-
//~| ERROR async closures are unstable
15+
//~| ERROR `async` trait bounds are unstable
1616

1717
fn main() {}

tests/ui/parser/bad-recover-kw-after-impl.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@ LL | ($ty:ty) => {
77
LL | impl_primitive!(impl async);
88
| ^^^^^ expected identifier
99

10-
error[E0658]: async closures are unstable
10+
error[E0658]: `async` trait bounds are unstable
1111
--> $DIR/bad-recover-kw-after-impl.rs:13:22
1212
|
1313
LL | impl_primitive!(impl async);
1414
| ^^^^^
1515
|
1616
= note: see issue #62290 <https://github.com/rust-lang/rust/issues/62290> for more information
17-
= help: add `#![feature(async_closure)]` to the crate attributes to enable
17+
= help: add `#![feature(async_trait_bounds)]` to the crate attributes to enable
1818
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
19-
= help: to use an async block, remove the `||`: `async {`
19+
= help: use the desugared name of the async trait, such as `AsyncFn`
2020

2121
error: aborting due to 2 previous errors
2222

0 commit comments

Comments
 (0)