Skip to content

Commit c179a15

Browse files
authored
Rollup merge of rust-lang#132612 - compiler-errors:async-trait-bounds, r=lcnr
Gate async fn trait bound modifier on `async_trait_bounds` This PR moves `async Fn()` trait bounds into a new feature gate: `feature(async_trait_bounds)`. The general vibe is that we will most likely stabilize the `feature(async_closure)` *without* the `async Fn()` trait bound modifier, so we need to gate that separately. We're trying to work on the general vision of `async` trait bound modifier general in: rust-lang/rfcs#3710, however that RFC still needs more time for consensus to converge, and we've decided that the value that users get from calling the bound `async Fn()` is *not really* worth blocking landing async closures in general.
2 parents 8575f8f + 59e3e89 commit c179a15

File tree

64 files changed

+147
-106
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+147
-106
lines changed

compiler/rustc_ast_passes/src/feature_gate.rs

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

+2
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,8 @@ declare_features! (
394394
(unstable, async_fn_track_caller, "1.73.0", Some(110011)),
395395
/// Allows `for await` loops.
396396
(unstable, async_for_loop, "1.77.0", Some(118898)),
397+
/// Allows `async` trait bound modifier.
398+
(unstable, async_trait_bounds, "CURRENT_RUSTC_VERSION", Some(62290)),
397399
/// Allows using C-variadics.
398400
(unstable, c_variadic, "1.34.0", Some(44930)),
399401
/// Allows the use of `#[cfg(<true/false>)]`.

compiler/rustc_parse/src/parser/ty.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -940,7 +940,7 @@ impl<'a> Parser<'a> {
940940
let asyncness = if self.token.uninterpolated_span().at_least_rust_2018()
941941
&& self.eat_keyword(kw::Async)
942942
{
943-
self.psess.gated_spans.gate(sym::async_closure, self.prev_token.span);
943+
self.psess.gated_spans.gate(sym::async_trait_bounds, self.prev_token.span);
944944
BoundAsyncness::Async(self.prev_token.span)
945945
} else if self.may_recover()
946946
&& self.token.uninterpolated_span().is_rust_2015()
@@ -951,7 +951,7 @@ impl<'a> Parser<'a> {
951951
span: self.prev_token.span,
952952
help: HelpUseLatestEdition::new(),
953953
});
954-
self.psess.gated_spans.gate(sym::async_closure, self.prev_token.span);
954+
self.psess.gated_spans.gate(sym::async_trait_bounds, self.prev_token.span);
955955
BoundAsyncness::Async(self.prev_token.span)
956956
} else {
957957
BoundAsyncness::Normal

compiler/rustc_span/src/symbol.rs

+1
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,7 @@ symbols! {
468468
async_for_loop,
469469
async_iterator,
470470
async_iterator_poll_next,
471+
async_trait_bounds,
471472
atomic,
472473
atomic_mod,
473474
atomics,

compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
794794
closure_def_id,
795795
found_kind,
796796
expected_kind,
797-
"async ",
797+
"Async",
798798
);
799799
self.note_obligation_cause(&mut err, &obligation);
800800
self.point_at_returns_when_relevant(&mut err, &obligation);

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/codegen/async-closure-debug.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
#![feature(async_closure)]
1111

12-
fn async_closure_test(upvar: &str) -> impl async Fn() + '_ {
12+
fn async_closure_test(upvar: &str) -> impl AsyncFn() + '_ {
1313
async move || {
1414
let hello = String::from("hello");
1515
println!("{hello}, {upvar}");

tests/coverage/async_closure.cov-map

+4-4
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.coverage

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
LL| |//@ aux-build: executor.rs
55
LL| |extern crate executor;
66
LL| |
7-
LL| 1|async fn call_once(f: impl async FnOnce()) {
7+
LL| 1|async fn call_once(f: impl AsyncFnOnce()) {
88
LL| 1| f().await;
99
LL| 1|}
1010
LL| |

tests/coverage/async_closure.rs

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

+2-2
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-closures/async-fn-mut-for-async-fn.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ fn main() {
1010
block_on::block_on(async {
1111
let x = async || {};
1212

13-
async fn needs_async_fn_mut(mut x: impl async FnMut()) {
13+
async fn needs_async_fn_mut(mut x: impl AsyncFnMut()) {
1414
x().await;
1515
}
1616
needs_async_fn_mut(x).await;

tests/ui/async-await/async-closures/async-fn-once-for-async-fn.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ extern crate block_on;
88

99
fn main() {
1010
block_on::block_on(async {
11-
async fn needs_async_fn_once(x: impl async FnOnce()) {
11+
async fn needs_async_fn_once(x: impl AsyncFnOnce()) {
1212
x().await;
1313
}
1414

tests/ui/async-await/async-closures/auxiliary/foreign.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
#![feature(async_closure)]
44

5-
pub fn closure() -> impl async Fn() {
5+
pub fn closure() -> impl AsyncFn() {
66
async || { /* Don't really need to do anything here. */ }
77
}

tests/ui/async-await/async-closures/body-check-on-non-fnmut.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ extern crate block_on;
1111

1212
async fn empty() {}
1313

14-
pub async fn call_once<F: async FnOnce()>(f: F) {
14+
pub async fn call_once<F: AsyncFnOnce()>(f: F) {
1515
f().await;
1616
}
1717

tests/ui/async-await/async-closures/box-deref-in-debuginfo.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ impl Trait for (i32,) {
1616
}
1717
}
1818

19-
async fn call_once(f: impl async FnOnce()) {
19+
async fn call_once(f: impl AsyncFnOnce()) {
2020
f().await;
2121
}
2222

tests/ui/async-await/async-closures/brand.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ struct S;
1313
struct B<'b>(PhantomData<&'b mut &'b mut ()>);
1414

1515
impl S {
16-
async fn q<F: async Fn(B<'_>)>(self, f: F) {
16+
async fn q<F: AsyncFn(B<'_>)>(self, f: F) {
1717
f(B(PhantomData)).await;
1818
}
1919
}

tests/ui/async-await/async-closures/captures.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ fn main() {
1313
block_on::block_on(async_main());
1414
}
1515

16-
async fn call<T>(f: &impl async Fn() -> T) -> T {
16+
async fn call<T>(f: &impl AsyncFn() -> T) -> T {
1717
f().await
1818
}
1919

20-
async fn call_once<T>(f: impl async FnOnce() -> T) -> T {
20+
async fn call_once<T>(f: impl AsyncFnOnce() -> T) -> T {
2121
f().await
2222
}
2323

@@ -80,7 +80,7 @@ async fn async_main() {
8080
call_once(c).await;
8181
}
8282

83-
fn force_fnonce<T>(f: impl async FnOnce() -> T) -> impl async FnOnce() -> T {
83+
fn force_fnonce<T>(f: impl AsyncFnOnce() -> T) -> impl AsyncFnOnce() -> T {
8484
f
8585
}
8686

tests/ui/async-await/async-closures/clone-closure.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
extern crate block_on;
99

10-
async fn for_each(f: impl async FnOnce(&str) + Clone) {
10+
async fn for_each(f: impl AsyncFnOnce(&str) + Clone) {
1111
f.clone()("world").await;
1212
f.clone()("world2").await;
1313
}

tests/ui/async-await/async-closures/constrained-but-no-upvars-yet.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66

77
#![feature(async_closure)]
88

9-
fn constrain<T: async FnOnce()>(t: T) -> T {
9+
fn constrain<T: AsyncFnOnce()>(t: T) -> T {
1010
t
1111
}
1212

1313
fn call_once<T>(f: impl FnOnce() -> T) -> T {
1414
f()
1515
}
1616

17-
async fn async_call_once<T>(f: impl async FnOnce() -> T) -> T {
17+
async fn async_call_once<T>(f: impl AsyncFnOnce() -> T) -> T {
1818
f().await
1919
}
2020

tests/ui/async-await/async-closures/debuginfo-by-move-body.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
extern crate block_on;
99

10-
async fn call_once(f: impl async FnOnce()) {
10+
async fn call_once(f: impl AsyncFnOnce()) {
1111
f().await;
1212
}
1313

tests/ui/async-await/async-closures/drop.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ impl Drop for DropMe {
1616
}
1717
}
1818

19-
async fn call_once(f: impl async FnOnce()) {
19+
async fn call_once(f: impl AsyncFnOnce()) {
2020
println!("before call");
2121
let fut = Box::pin(f());
2222
println!("after call");

tests/ui/async-await/async-closures/fn-exception-target-features.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use std::future::Future;
1010
#[target_feature(enable = "sse2")]
1111
fn target_feature() -> Pin<Box<dyn Future<Output = ()> + 'static>> { todo!() }
1212

13-
fn test(f: impl async Fn()) {}
13+
fn test(f: impl AsyncFn()) {}
1414

1515
fn main() {
1616
test(target_feature); //~ ERROR the trait bound

tests/ui/async-await/async-closures/fn-exception-target-features.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ LL | test(target_feature);
99
note: required by a bound in `test`
1010
--> $DIR/fn-exception-target-features.rs:13:17
1111
|
12-
LL | fn test(f: impl async Fn()) {}
13-
| ^^^^^^^^^^ required by this bound in `test`
12+
LL | fn test(f: impl AsyncFn()) {}
13+
| ^^^^^^^^^ required by this bound in `test`
1414

1515
error: aborting due to 1 previous error
1616

tests/ui/async-await/async-closures/fn-exception.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ unsafe extern "C" {
1313
pub safe fn abi() -> Pin<Box<dyn Future<Output = ()> + 'static>>;
1414
}
1515

16-
fn test(f: impl async Fn()) {}
16+
fn test(f: impl AsyncFn()) {}
1717

1818
fn main() {
1919
test(unsafety); //~ ERROR the trait bound

tests/ui/async-await/async-closures/fn-exception.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ LL | test(unsafety);
99
note: required by a bound in `test`
1010
--> $DIR/fn-exception.rs:16:17
1111
|
12-
LL | fn test(f: impl async Fn()) {}
13-
| ^^^^^^^^^^ required by this bound in `test`
12+
LL | fn test(f: impl AsyncFn()) {}
13+
| ^^^^^^^^^ required by this bound in `test`
1414

1515
error[E0277]: the trait bound `extern "C" fn() -> Pin<Box<(dyn Future<Output = ()> + 'static)>> {abi}: AsyncFn()` is not satisfied
1616
--> $DIR/fn-exception.rs:20:10
@@ -23,8 +23,8 @@ LL | test(abi);
2323
note: required by a bound in `test`
2424
--> $DIR/fn-exception.rs:16:17
2525
|
26-
LL | fn test(f: impl async Fn()) {}
27-
| ^^^^^^^^^^ required by this bound in `test`
26+
LL | fn test(f: impl AsyncFn()) {}
27+
| ^^^^^^^^^ required by this bound in `test`
2828

2929
error: aborting due to 2 previous errors
3030

tests/ui/async-await/async-closures/force-move-due-to-inferred-kind.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
extern crate block_on;
88

9-
fn force_fnonce<T: async FnOnce()>(t: T) -> T { t }
9+
fn force_fnonce<T: AsyncFnOnce()>(t: T) -> T { t }
1010

1111
fn main() {
1212
block_on::block_on(async {

tests/ui/async-await/async-closures/foreign.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ extern crate foreign;
1212

1313
struct NoCopy;
1414

15-
async fn call_once(f: impl async FnOnce()) {
15+
async fn call_once(f: impl AsyncFnOnce()) {
1616
f().await;
1717
}
1818

tests/ui/async-await/async-closures/implements-fnmut.rs

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

4-
// Demonstrates that an async closure may implement `FnMut` (not just `async FnMut`!)
4+
// Demonstrates that an async closure may implement `FnMut` (not just `AsyncFnMut`!)
55
// if it has no self-borrows. In this case, `&Ty` is not borrowed from the closure env,
66
// since it's fine to reborrow it with its original lifetime. See the doc comment on
77
// `should_reborrow_from_env_of_parent_coroutine_closure` for more detail for when we

tests/ui/async-await/async-closures/inline-body.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pub fn block_on<T>(fut: impl Future<Output = T>) -> T {
2424
}
2525
}
2626

27-
async fn call_once<T>(f: impl async FnOnce() -> T) -> T {
27+
async fn call_once<T>(f: impl AsyncFnOnce() -> T) -> T {
2828
f().await
2929
}
3030

tests/ui/async-await/async-closures/mangle.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ use std::future::Future;
1313
use std::pin::pin;
1414
use std::task::*;
1515

16-
async fn call_mut(f: &mut impl async FnMut()) {
16+
async fn call_mut(f: &mut impl AsyncFnMut()) {
1717
f().await;
1818
}
1919

20-
async fn call_once(f: impl async FnOnce()) {
20+
async fn call_once(f: impl AsyncFnOnce()) {
2121
f().await;
2222
}
2323

tests/ui/async-await/async-closures/moro-example.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ impl<'scope, 'env: 'scope> Scope<'scope, 'env> {
2222

2323
fn scope_with_closure<'env, B>(_body: B) -> BoxFuture<'env, ()>
2424
where
25-
for<'scope> B: async FnOnce(&'scope Scope<'scope, 'env>),
25+
for<'scope> B: AsyncFnOnce(&'scope Scope<'scope, 'env>),
2626
{
2727
todo!()
2828
}

tests/ui/async-await/async-closures/move-is-async-fn.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ fn main() {
1919
is_static(&c);
2020

2121
// Check that `<{async fn} as AsyncFnOnce>::CallOnceFuture` owns its captures.
22-
fn call_once<F: async FnOnce()>(f: F) -> F::CallOnceFuture { f() }
22+
fn call_once<F: AsyncFnOnce()>(f: F) -> F::CallOnceFuture { f() }
2323
is_static(&call_once(c));
2424
});
2525
}

tests/ui/async-await/async-closures/mut-ref-reborrow.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
extern crate block_on;
1111

12-
async fn call_once(f: impl async FnOnce()) { f().await; }
12+
async fn call_once(f: impl AsyncFnOnce()) { f().await; }
1313

1414
pub async fn async_closure(x: &mut i32) {
1515
let c = async move || {

tests/ui/async-await/async-closures/no-borrow-from-env.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
fn outlives<'a>(_: impl Sized + 'a) {}
77

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

0 commit comments

Comments
 (0)