1
Fork 0

Auto merge of #114914 - compiler-errors:deduce-tait-in-future-output, r=lcnr

Normalize return type of `deduce_future_output_from_obligations`

Fixes #114909
Also confirmed to fix #114727 manually

Now that we have weak/lazy type aliases, we need to normalize those in future signatures to ensure that `replace_opaque_types_with_inference_vars` actually sees TAITs behind them. This isn't needed in the new solver, but added a test to make sure it doesn't regress there either.

r? types cc `@oli-obk` (who's gone, worst case can delay this PR until he's back)
This commit is contained in:
bors 2023-08-20 06:24:44 +00:00
commit 39e0749329
2 changed files with 25 additions and 7 deletions

View file

@ -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)