Merge pull request #20971 from ShoyuVanilla/async-fn-sig

fix: Fix panicking while resolving callable sigs for `AsyncFnMut`
This commit is contained in:
Chayim Refael Friedman 2025-11-04 16:44:01 +00:00 committed by GitHub
commit 5ffe3f45ce
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 32 additions and 1 deletions

View File

@ -674,10 +674,13 @@ impl<'db> InferenceTable<'db> {
let args = [ty, arg_ty];
let trait_ref = TraitRef::new(self.interner(), fn_trait.into(), args);
let proj_args = self
.infer_ctxt
.fill_rest_fresh_args(output_assoc_type.into(), args.into_iter().map(Into::into));
let projection = Ty::new_alias(
self.interner(),
rustc_type_ir::AliasTyKind::Projection,
AliasTy::new(self.interner(), output_assoc_type.into(), args),
AliasTy::new(self.interner(), output_assoc_type.into(), proj_args),
);
let pred = Predicate::upcast_from(trait_ref, self.interner());

View File

@ -524,3 +524,31 @@ fn g(it: *const (dyn Trait)) {
"#,
);
}
#[test]
fn regression_20951() {
check_infer(
r#"
//- minicore: async_fn
trait DoesSomething {
fn do_something(&self) -> impl Future<Output = usize>;
}
impl<F> DoesSomething for F
where
F: AsyncFn() -> usize,
{
fn do_something(&self) -> impl Future<Output = usize> {
self()
}
}
"#,
expect![[r#"
43..47 'self': &'? Self
168..172 'self': &'? F
205..227 '{ ... }': <F as AsyncFnMut<()>>::CallRefFuture<'<erased>>
215..219 'self': &'? F
215..221 'self()': <F as AsyncFnMut<()>>::CallRefFuture<'<erased>>
"#]],
);
}