Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions compiler/rustc_hir_typeck/src/closure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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| {
Expand All @@ -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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you move the normalize call into the ty::Alias branch? for infer vars the obligation should already be normalized

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's the alias that corresponds to the impl Future. The type we want to normalize here is the Output of that future, which depends on what we extract out of get_future_output.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait, wait, I think I understand here.

Copy link
Member Author

@compiler-errors compiler-errors Aug 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, we still may have unnormalized obligations for infer vars as well. The obligations returned from replace_opaque_with_infer and handle_opaque_ty are not normalized.


// 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)
Expand Down
19 changes: 19 additions & 0 deletions tests/ui/async-await/normalize-output-in-signature-deduction.rs
Original file line number Diff line number Diff line change
@@ -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<T> = impl Trait;

async fn foo<T>() -> TAIT<T> {
Foo
}

fn main() {}