-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support {async closure}: Fn
in new solver
#121656
Support {async closure}: Fn
in new solver
#121656
Conversation
Some changes occurred to the core trait solver cc @rust-lang/initiative-trait-system-refactor |
|
||
fn main() { | ||
block_on::block_on(async { | ||
async fn call_once<F: Future>(x: impl Fn(&'static str) -> F) -> F::Output { | ||
async fn call_once<F: Future>(x: impl FnOnce(&'static str) -> F) -> F::Output { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even though this test was called once.rs
, it was actually testing this behavior. Let's... fix that... by copying this into a properly named test, and changing this to actually test FnOnce
.
let async_fn_kind_trait_def_id = | ||
tcx.require_lang_item(LangItem::AsyncFnKindHelper, None); | ||
let upvars_projection_def_id = tcx | ||
.associated_items(async_fn_kind_trait_def_id) | ||
.filter_by_name_unhygienic(sym::Upvars) | ||
.next() | ||
.unwrap() | ||
.def_id; | ||
let tupled_upvars_ty = Ty::new_projection( | ||
tcx, | ||
upvars_projection_def_id, | ||
[ | ||
ty::GenericArg::from(kind_ty), | ||
Ty::from_closure_kind(tcx, goal_kind).into(), | ||
// No captures by ref, so this doesn't matter. | ||
tcx.lifetimes.re_static.into(), | ||
sig.tupled_inputs_ty.into(), | ||
args.tupled_upvars_ty().into(), | ||
args.coroutine_captures_by_ref_ty().into(), | ||
], | ||
); | ||
sig.to_coroutine( | ||
tcx, | ||
args.parent_args(), | ||
Ty::from_closure_kind(tcx, goal_kind), | ||
tcx.coroutine_for_closure(def_id), | ||
tupled_upvars_ty, | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
modulo the nested
push, which can be done after, this piece of code is an exact duplicate of the logic in extract_tupled_inputs_and_output_from_async_callable
. Turn it into a separate helper function and invoke it at both sites.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pulled it out into two helpers
102b458
to
6c6b7e2
Compare
@bors r+ rollup |
Closing in favor of the other PR, which I've squashed these changes together |
When async closures capture nothing except for their input args, they can implement
Fn
/FnMut
. Implement support for that in the new trait solver, which for some reason I forgot to implement in #120712.r? oli-obk