Skip to content

Commit 17b4333

Browse files
select AsyncFn traits during overloaded call op
1 parent fde86e5 commit 17b4333

File tree

5 files changed

+25
-1
lines changed

5 files changed

+25
-1
lines changed

compiler/rustc_hir/src/lang_items.rs

+4
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,10 @@ language_item_table! {
208208
FnMut, sym::fn_mut, fn_mut_trait, Target::Trait, GenericRequirement::Exact(1);
209209
FnOnce, sym::fn_once, fn_once_trait, Target::Trait, GenericRequirement::Exact(1);
210210

211+
AsyncFn, sym::async_fn, async_fn_trait, Target::Trait, GenericRequirement::Exact(1);
212+
AsyncFnMut, sym::async_fn_mut, async_fn_mut_trait, Target::Trait, GenericRequirement::Exact(1);
213+
AsyncFnOnce, sym::async_fn_once, async_fn_once_trait, Target::Trait, GenericRequirement::Exact(1);
214+
211215
FnOnceOutput, sym::fn_once_output, fn_once_output, Target::AssocTy, GenericRequirement::None;
212216

213217
Iterator, sym::iterator, iterator_trait, Target::Trait, GenericRequirement::Exact(0);

compiler/rustc_hir_typeck/src/callee.rs

+11
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
220220
(self.tcx.lang_items().fn_trait(), Ident::with_dummy_span(sym::call), true),
221221
(self.tcx.lang_items().fn_mut_trait(), Ident::with_dummy_span(sym::call_mut), true),
222222
(self.tcx.lang_items().fn_once_trait(), Ident::with_dummy_span(sym::call_once), false),
223+
(self.tcx.lang_items().async_fn_trait(), Ident::with_dummy_span(sym::async_call), true),
224+
(
225+
self.tcx.lang_items().async_fn_mut_trait(),
226+
Ident::with_dummy_span(sym::async_call_mut),
227+
true,
228+
),
229+
(
230+
self.tcx.lang_items().async_fn_once_trait(),
231+
Ident::with_dummy_span(sym::async_call_once),
232+
false,
233+
),
223234
] {
224235
let Some(trait_def_id) = opt_trait_def_id else { continue };
225236

compiler/rustc_span/src/symbol.rs

+6
Original file line numberDiff line numberDiff line change
@@ -423,8 +423,14 @@ symbols! {
423423
assume,
424424
assume_init,
425425
async_await,
426+
async_call,
427+
async_call_mut,
428+
async_call_once,
426429
async_closure,
430+
async_fn,
427431
async_fn_in_trait,
432+
async_fn_mut,
433+
async_fn_once,
428434
async_fn_track_caller,
429435
async_for_loop,
430436
async_iterator,

library/core/src/ops/async_function.rs

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use crate::marker::Tuple;
88
#[rustc_paren_sugar]
99
#[fundamental]
1010
#[must_use = "async closures are lazy and do nothing unless called"]
11+
#[cfg_attr(not(bootstrap), lang = "async_fn")]
1112
pub trait AsyncFn<Args: Tuple>: AsyncFnMut<Args> {
1213
/// Future returned by [`AsyncFn::async_call`].
1314
#[unstable(feature = "async_fn_traits", issue = "none")]
@@ -27,6 +28,7 @@ pub trait AsyncFn<Args: Tuple>: AsyncFnMut<Args> {
2728
#[rustc_paren_sugar]
2829
#[fundamental]
2930
#[must_use = "async closures are lazy and do nothing unless called"]
31+
#[cfg_attr(not(bootstrap), lang = "async_fn_mut")]
3032
pub trait AsyncFnMut<Args: Tuple>: AsyncFnOnce<Args> {
3133
/// Future returned by [`AsyncFnMut::async_call_mut`].
3234
#[unstable(feature = "async_fn_traits", issue = "none")]
@@ -46,6 +48,7 @@ pub trait AsyncFnMut<Args: Tuple>: AsyncFnOnce<Args> {
4648
#[rustc_paren_sugar]
4749
#[fundamental]
4850
#[must_use = "async closures are lazy and do nothing unless called"]
51+
#[cfg_attr(not(bootstrap), lang = "async_fn_once")]
4952
pub trait AsyncFnOnce<Args: Tuple> {
5053
/// Future returned by [`AsyncFnOnce::async_call_once`].
5154
#[unstable(feature = "async_fn_traits", issue = "none")]

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use std::ops::AsyncFn;
88
async fn foo() {}
99

1010
async fn call_asyncly(f: impl AsyncFn(i32) -> i32) -> i32 {
11-
f.async_call((1i32,)).await
11+
f(1).await
1212
}
1313

1414
fn main() {

0 commit comments

Comments
 (0)