Skip to content

Commit 966f279

Browse files
Structurally normalize async fn return type in deduce_future_output_from_obligations
1 parent eea2614 commit 966f279

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

Diff for: compiler/rustc_hir_typeck/src/closure.rs

+10-6
Original file line numberDiff line numberDiff line change
@@ -688,8 +688,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
688688
span_bug!(self.tcx.def_span(expr_def_id), "async fn generator outside of a fn")
689689
});
690690

691+
let closure_span = self.tcx.def_span(expr_def_id);
691692
let ret_ty = ret_coercion.borrow().expected_ty();
692-
let ret_ty = self.inh.infcx.shallow_resolve(ret_ty);
693+
let ret_ty = self.try_structurally_resolve_type(closure_span, ret_ty);
693694

694695
let get_future_output = |predicate: ty::Predicate<'tcx>, span| {
695696
// Search for a pending obligation like
@@ -711,8 +712,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
711712
}
712713
};
713714

714-
let span = self.tcx.def_span(expr_def_id);
715-
716715
let output_ty = match *ret_ty.kind() {
717716
ty::Infer(ty::TyVar(ret_vid)) => {
718717
self.obligations_for_self_ty(ret_vid).find_map(|obligation| {
@@ -726,17 +725,22 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
726725
.find_map(|(p, s)| get_future_output(p.as_predicate(), s))?,
727726
ty::Error(_) => return None,
728727
_ => span_bug!(
729-
span,
728+
closure_span,
730729
"async fn generator return type not an inference variable: {ret_ty}"
731730
),
732731
};
733732

734-
let output_ty = self.normalize(span, output_ty);
733+
let output_ty = self.normalize(closure_span, output_ty);
735734

736735
// async fn that have opaque types in their return type need to redo the conversion to inference variables
737736
// as they fetch the still opaque version from the signature.
738737
let InferOk { value: output_ty, obligations } = self
739-
.replace_opaque_types_with_inference_vars(output_ty, body_def_id, span, self.param_env);
738+
.replace_opaque_types_with_inference_vars(
739+
output_ty,
740+
body_def_id,
741+
closure_span,
742+
self.param_env,
743+
);
740744
self.register_predicates(obligations);
741745

742746
Some(output_ty)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// compile-flags: -Ztrait-solver=next
2+
// check-pass
3+
// edition:2021
4+
5+
#![feature(async_fn_in_trait)]
6+
7+
trait Foo {
8+
async fn bar() {}
9+
}
10+
11+
fn main() {}

0 commit comments

Comments
 (0)