Skip to content

Commit c7c9e25

Browse files
committed
fix: Fix panicking while resolving callable sigs for AsyncFnMut
1 parent 51af7a3 commit c7c9e25

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

crates/hir-ty/src/infer/unify.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -674,10 +674,13 @@ impl<'db> InferenceTable<'db> {
674674
let args = [ty, arg_ty];
675675
let trait_ref = TraitRef::new(self.interner(), fn_trait.into(), args);
676676

677+
let proj_args = self
678+
.infer_ctxt
679+
.fill_rest_fresh_args(output_assoc_type.into(), args.into_iter().map(Into::into));
677680
let projection = Ty::new_alias(
678681
self.interner(),
679682
rustc_type_ir::AliasTyKind::Projection,
680-
AliasTy::new(self.interner(), output_assoc_type.into(), args),
683+
AliasTy::new(self.interner(), output_assoc_type.into(), proj_args),
681684
);
682685

683686
let pred = Predicate::upcast_from(trait_ref, self.interner());

crates/hir-ty/src/tests/regression/new_solver.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,3 +524,31 @@ fn g(it: *const (dyn Trait)) {
524524
"#,
525525
);
526526
}
527+
528+
#[test]
529+
fn regression_20951() {
530+
check_infer(
531+
r#"
532+
//- minicore: async_fn
533+
trait DoesSomething {
534+
fn do_something(&self) -> impl Future<Output = usize>;
535+
}
536+
537+
impl<F> DoesSomething for F
538+
where
539+
F: AsyncFn() -> usize,
540+
{
541+
fn do_something(&self) -> impl Future<Output = usize> {
542+
self()
543+
}
544+
}
545+
"#,
546+
expect![[r#"
547+
43..47 'self': &'? Self
548+
168..172 'self': &'? F
549+
205..227 '{ ... }': <F as AsyncFnMut<()>>::CallRefFuture<'<erased>>
550+
215..219 'self': &'? F
551+
215..221 'self()': <F as AsyncFnMut<()>>::CallRefFuture<'<erased>>
552+
"#]],
553+
);
554+
}

0 commit comments

Comments
 (0)