Skip to content

Commit 4c0016a

Browse files
Don't emit higher-ranked Future obligations when confirm async Fn goals
1 parent 118730b commit 4c0016a

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

compiler/rustc_trait_selection/src/traits/select/confirmation.rs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -923,14 +923,22 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
923923
[self_ty, Ty::new_tup(tcx, sig.inputs())],
924924
)
925925
});
926+
926927
// We must additionally check that the return type impls `Future`.
928+
929+
// FIXME(async_closures): Investigate this before stabilization.
930+
// We instantiate this binder eagerly because the `confirm_future_candidate`
931+
// method doesn't support higher-ranked futures, which the `AsyncFn`
932+
// traits expressly allow the user to write. To fix this correctly,
933+
// we'd need to instantiate trait bounds before we get to selection,
934+
// like the new trait solver does.
927935
let future_trait_def_id = tcx.require_lang_item(LangItem::Future, None);
936+
let placeholder_output_ty = self.infcx.enter_forall_and_leak_universe(sig.output());
928937
nested.push(obligation.with(
929938
tcx,
930-
sig.map_bound(|sig| {
931-
ty::TraitRef::new(tcx, future_trait_def_id, [sig.output()])
932-
}),
939+
ty::TraitRef::new(tcx, future_trait_def_id, [placeholder_output_ty]),
933940
));
941+
934942
(trait_ref, Ty::from_closure_kind(tcx, ty::ClosureKind::Fn))
935943
}
936944
ty::Closure(_, args) => {
@@ -943,14 +951,16 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
943951
[self_ty, sig.inputs()[0]],
944952
)
945953
});
954+
946955
// We must additionally check that the return type impls `Future`.
956+
// See FIXME in last branch for why we instantiate the binder eagerly.
947957
let future_trait_def_id = tcx.require_lang_item(LangItem::Future, None);
958+
let placeholder_output_ty = self.infcx.enter_forall_and_leak_universe(sig.output());
948959
nested.push(obligation.with(
949960
tcx,
950-
sig.map_bound(|sig| {
951-
ty::TraitRef::new(tcx, future_trait_def_id, [sig.output()])
952-
}),
961+
ty::TraitRef::new(tcx, future_trait_def_id, [placeholder_output_ty]),
953962
));
963+
954964
(trait_ref, args.kind_ty())
955965
}
956966
_ => bug!("expected callable type for AsyncFn candidate"),

0 commit comments

Comments
 (0)