mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 16:24:46 +00:00
select AsyncFn traits during overloaded call op
This commit is contained in:
parent
fde86e586d
commit
17b433351d
@ -208,6 +208,10 @@ language_item_table! {
|
||||
FnMut, sym::fn_mut, fn_mut_trait, Target::Trait, GenericRequirement::Exact(1);
|
||||
FnOnce, sym::fn_once, fn_once_trait, Target::Trait, GenericRequirement::Exact(1);
|
||||
|
||||
AsyncFn, sym::async_fn, async_fn_trait, Target::Trait, GenericRequirement::Exact(1);
|
||||
AsyncFnMut, sym::async_fn_mut, async_fn_mut_trait, Target::Trait, GenericRequirement::Exact(1);
|
||||
AsyncFnOnce, sym::async_fn_once, async_fn_once_trait, Target::Trait, GenericRequirement::Exact(1);
|
||||
|
||||
FnOnceOutput, sym::fn_once_output, fn_once_output, Target::AssocTy, GenericRequirement::None;
|
||||
|
||||
Iterator, sym::iterator, iterator_trait, Target::Trait, GenericRequirement::Exact(0);
|
||||
|
@ -220,6 +220,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
(self.tcx.lang_items().fn_trait(), Ident::with_dummy_span(sym::call), true),
|
||||
(self.tcx.lang_items().fn_mut_trait(), Ident::with_dummy_span(sym::call_mut), true),
|
||||
(self.tcx.lang_items().fn_once_trait(), Ident::with_dummy_span(sym::call_once), false),
|
||||
(self.tcx.lang_items().async_fn_trait(), Ident::with_dummy_span(sym::async_call), true),
|
||||
(
|
||||
self.tcx.lang_items().async_fn_mut_trait(),
|
||||
Ident::with_dummy_span(sym::async_call_mut),
|
||||
true,
|
||||
),
|
||||
(
|
||||
self.tcx.lang_items().async_fn_once_trait(),
|
||||
Ident::with_dummy_span(sym::async_call_once),
|
||||
false,
|
||||
),
|
||||
] {
|
||||
let Some(trait_def_id) = opt_trait_def_id else { continue };
|
||||
|
||||
|
@ -423,8 +423,14 @@ symbols! {
|
||||
assume,
|
||||
assume_init,
|
||||
async_await,
|
||||
async_call,
|
||||
async_call_mut,
|
||||
async_call_once,
|
||||
async_closure,
|
||||
async_fn,
|
||||
async_fn_in_trait,
|
||||
async_fn_mut,
|
||||
async_fn_once,
|
||||
async_fn_track_caller,
|
||||
async_for_loop,
|
||||
async_iterator,
|
||||
|
@ -8,6 +8,7 @@ use crate::marker::Tuple;
|
||||
#[rustc_paren_sugar]
|
||||
#[fundamental]
|
||||
#[must_use = "async closures are lazy and do nothing unless called"]
|
||||
#[cfg_attr(not(bootstrap), lang = "async_fn")]
|
||||
pub trait AsyncFn<Args: Tuple>: AsyncFnMut<Args> {
|
||||
/// Future returned by [`AsyncFn::async_call`].
|
||||
#[unstable(feature = "async_fn_traits", issue = "none")]
|
||||
@ -27,6 +28,7 @@ pub trait AsyncFn<Args: Tuple>: AsyncFnMut<Args> {
|
||||
#[rustc_paren_sugar]
|
||||
#[fundamental]
|
||||
#[must_use = "async closures are lazy and do nothing unless called"]
|
||||
#[cfg_attr(not(bootstrap), lang = "async_fn_mut")]
|
||||
pub trait AsyncFnMut<Args: Tuple>: AsyncFnOnce<Args> {
|
||||
/// Future returned by [`AsyncFnMut::async_call_mut`].
|
||||
#[unstable(feature = "async_fn_traits", issue = "none")]
|
||||
@ -46,6 +48,7 @@ pub trait AsyncFnMut<Args: Tuple>: AsyncFnOnce<Args> {
|
||||
#[rustc_paren_sugar]
|
||||
#[fundamental]
|
||||
#[must_use = "async closures are lazy and do nothing unless called"]
|
||||
#[cfg_attr(not(bootstrap), lang = "async_fn_once")]
|
||||
pub trait AsyncFnOnce<Args: Tuple> {
|
||||
/// Future returned by [`AsyncFnOnce::async_call_once`].
|
||||
#[unstable(feature = "async_fn_traits", issue = "none")]
|
||||
|
@ -8,7 +8,7 @@ use std::ops::AsyncFn;
|
||||
async fn foo() {}
|
||||
|
||||
async fn call_asyncly(f: impl AsyncFn(i32) -> i32) -> i32 {
|
||||
f.async_call((1i32,)).await
|
||||
f(1).await
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
Loading…
Reference in New Issue
Block a user