From 2cc71ba8813e3a651048c18d14411467517c7ddb Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Wed, 16 Aug 2023 14:28:00 -0700 Subject: [PATCH] Normalize return type of deduce_future_output_from_obligations --- compiler/rustc_hir_typeck/src/closure.rs | 13 ++++++------- ...normalize-output-in-signature-deduction.rs | 19 +++++++++++++++++++ 2 files changed, 25 insertions(+), 7 deletions(-) create mode 100644 tests/ui/async-await/normalize-output-in-signature-deduction.rs diff --git a/compiler/rustc_hir_typeck/src/closure.rs b/compiler/rustc_hir_typeck/src/closure.rs index 3e67afb1c3d9b..b19fb6da6defd 100644 --- a/compiler/rustc_hir_typeck/src/closure.rs +++ b/compiler/rustc_hir_typeck/src/closure.rs @@ -711,6 +711,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } }; + let span = self.tcx.def_span(expr_def_id); + let output_ty = match *ret_ty.kind() { ty::Infer(ty::TyVar(ret_vid)) => { self.obligations_for_self_ty(ret_vid).find_map(|obligation| { @@ -724,20 +726,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { .find_map(|(p, s)| get_future_output(p.as_predicate(), s))?, ty::Error(_) => return None, _ => span_bug!( - self.tcx.def_span(expr_def_id), + span, "async fn generator return type not an inference variable: {ret_ty}" ), }; + let output_ty = self.normalize(span, output_ty); + // async fn that have opaque types in their return type need to redo the conversion to inference variables // as they fetch the still opaque version from the signature. let InferOk { value: output_ty, obligations } = self - .replace_opaque_types_with_inference_vars( - output_ty, - body_def_id, - self.tcx.def_span(expr_def_id), - self.param_env, - ); + .replace_opaque_types_with_inference_vars(output_ty, body_def_id, span, self.param_env); self.register_predicates(obligations); Some(output_ty) diff --git a/tests/ui/async-await/normalize-output-in-signature-deduction.rs b/tests/ui/async-await/normalize-output-in-signature-deduction.rs new file mode 100644 index 0000000000000..960065a83a45d --- /dev/null +++ b/tests/ui/async-await/normalize-output-in-signature-deduction.rs @@ -0,0 +1,19 @@ +// edition:2021 +// revisions: current next +//[next] compile-flags: -Ztrait-solver=next +// check-pass + +#![feature(type_alias_impl_trait)] + +struct Foo; + +impl Trait for Foo {} +pub trait Trait {} + +pub type TAIT = impl Trait; + +async fn foo() -> TAIT { + Foo +} + +fn main() {}