Support {async closure}: Fn in new solver#121656
Closed
compiler-errors wants to merge 2 commits intorust-lang:masterfrom
Closed
Support {async closure}: Fn in new solver#121656compiler-errors wants to merge 2 commits intorust-lang:masterfrom
{async closure}: Fn in new solver#121656compiler-errors wants to merge 2 commits intorust-lang:masterfrom
Conversation
Collaborator
|
Some changes occurred to the core trait solver cc @rust-lang/initiative-trait-system-refactor |
compiler-errors
commented
Feb 27, 2024
| 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 { |
Contributor
Author
There was a problem hiding this comment.
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.
oli-obk
reviewed
Feb 27, 2024
Comment on lines
325
to
331
| 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, | ||
| ) |
Contributor
There was a problem hiding this comment.
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.
Contributor
Author
There was a problem hiding this comment.
pulled it out into two helpers
102b458 to
6c6b7e2
Compare
Contributor
|
@bors r+ rollup |
Collaborator
Contributor
Author
|
Closing in favor of the other PR, which I've squashed these changes together |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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