diff options
| author | Michael Goulet <michael@errs.io> | 2025-05-21 18:07:29 +0000 |
|---|---|---|
| committer | Michael Goulet <michael@errs.io> | 2025-05-21 20:02:29 +0000 |
| commit | e0f80558716372902b2eda1e43ab2e169bfb3669 (patch) | |
| tree | b034686bdb7f560b53ca1e59b299e159c41702e9 | |
| parent | ca912d794d42336ddd54389480b56bfc2bc6685f (diff) | |
| download | rust-e0f80558716372902b2eda1e43ab2e169bfb3669.tar.gz rust-e0f80558716372902b2eda1e43ab2e169bfb3669.zip | |
Fix FnOnce impl for AsyncFn/AsyncFnMut closures in new solver
| -rw-r--r-- | compiler/rustc_next_trait_solver/src/solve/assembly/structural_traits.rs | 2 | ||||
| -rw-r--r-- | tests/ui/async-await/async-closures/async-fn-mut-impl-fn-once.rs | 15 |
2 files changed, 16 insertions, 1 deletions
diff --git a/compiler/rustc_next_trait_solver/src/solve/assembly/structural_traits.rs b/compiler/rustc_next_trait_solver/src/solve/assembly/structural_traits.rs index 2a2b462a36c..26ad72bea80 100644 --- a/compiler/rustc_next_trait_solver/src/solve/assembly/structural_traits.rs +++ b/compiler/rustc_next_trait_solver/src/solve/assembly/structural_traits.rs @@ -327,7 +327,7 @@ pub(in crate::solve) fn extract_tupled_inputs_and_output_from_callable<I: Intern // always be called once. It additionally implements `Fn`/`FnMut` // only if it has no upvars referencing the closure-env lifetime, // and if the closure kind permits it. - if closure_kind != ty::ClosureKind::FnOnce && args.has_self_borrows() { + if goal_kind != ty::ClosureKind::FnOnce && args.has_self_borrows() { return Err(NoSolution); } diff --git a/tests/ui/async-await/async-closures/async-fn-mut-impl-fn-once.rs b/tests/ui/async-await/async-closures/async-fn-mut-impl-fn-once.rs new file mode 100644 index 00000000000..59d034953d7 --- /dev/null +++ b/tests/ui/async-await/async-closures/async-fn-mut-impl-fn-once.rs @@ -0,0 +1,15 @@ +//@ edition:2021 +//@ check-pass +//@ revisions: current next +//@ ignore-compare-mode-next-solver (explicit revisions) +//@[next] compile-flags: -Znext-solver + +fn call_once<F>(_: impl FnOnce() -> F) {} + +fn main() { + let mut i = 0; + let c = async || { + i += 1; + }; + call_once(c); +} |
