Structurally normalize async fn return type in deduce_future_output_from_obligations
This commit is contained in:
parent
eea26141ec
commit
966f27977a
@ -688,8 +688,9 @@ fn deduce_future_output_from_obligations(
|
||||
span_bug!(self.tcx.def_span(expr_def_id), "async fn generator outside of a fn")
|
||||
});
|
||||
|
||||
let closure_span = self.tcx.def_span(expr_def_id);
|
||||
let ret_ty = ret_coercion.borrow().expected_ty();
|
||||
let ret_ty = self.inh.infcx.shallow_resolve(ret_ty);
|
||||
let ret_ty = self.try_structurally_resolve_type(closure_span, ret_ty);
|
||||
|
||||
let get_future_output = |predicate: ty::Predicate<'tcx>, span| {
|
||||
// Search for a pending obligation like
|
||||
@ -711,8 +712,6 @@ fn deduce_future_output_from_obligations(
|
||||
}
|
||||
};
|
||||
|
||||
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| {
|
||||
@ -726,17 +725,22 @@ fn deduce_future_output_from_obligations(
|
||||
.find_map(|(p, s)| get_future_output(p.as_predicate(), s))?,
|
||||
ty::Error(_) => return None,
|
||||
_ => span_bug!(
|
||||
span,
|
||||
closure_span,
|
||||
"async fn generator return type not an inference variable: {ret_ty}"
|
||||
),
|
||||
};
|
||||
|
||||
let output_ty = self.normalize(span, output_ty);
|
||||
let output_ty = self.normalize(closure_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, span, self.param_env);
|
||||
.replace_opaque_types_with_inference_vars(
|
||||
output_ty,
|
||||
body_def_id,
|
||||
closure_span,
|
||||
self.param_env,
|
||||
);
|
||||
self.register_predicates(obligations);
|
||||
|
||||
Some(output_ty)
|
||||
|
@ -0,0 +1,11 @@
|
||||
// compile-flags: -Ztrait-solver=next
|
||||
// check-pass
|
||||
// edition:2021
|
||||
|
||||
#![feature(async_fn_in_trait)]
|
||||
|
||||
trait Foo {
|
||||
async fn bar() {}
|
||||
}
|
||||
|
||||
fn main() {}
|
Loading…
Reference in New Issue
Block a user