Skip to content

Commit 39e0749

Browse files
committed
Auto merge of rust-lang#114914 - compiler-errors:deduce-tait-in-future-output, r=lcnr
Normalize return type of `deduce_future_output_from_obligations` Fixes rust-lang#114909 Also confirmed to fix rust-lang#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)
2 parents 484cb4e + 2cc71ba commit 39e0749

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

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

+6-7
Original file line numberDiff line numberDiff line change
@@ -711,6 +711,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
711711
}
712712
};
713713

714+
let span = self.tcx.def_span(expr_def_id);
715+
714716
let output_ty = match *ret_ty.kind() {
715717
ty::Infer(ty::TyVar(ret_vid)) => {
716718
self.obligations_for_self_ty(ret_vid).find_map(|obligation| {
@@ -724,20 +726,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
724726
.find_map(|(p, s)| get_future_output(p.as_predicate(), s))?,
725727
ty::Error(_) => return None,
726728
_ => span_bug!(
727-
self.tcx.def_span(expr_def_id),
729+
span,
728730
"async fn generator return type not an inference variable: {ret_ty}"
729731
),
730732
};
731733

734+
let output_ty = self.normalize(span, output_ty);
735+
732736
// async fn that have opaque types in their return type need to redo the conversion to inference variables
733737
// as they fetch the still opaque version from the signature.
734738
let InferOk { value: output_ty, obligations } = self
735-
.replace_opaque_types_with_inference_vars(
736-
output_ty,
737-
body_def_id,
738-
self.tcx.def_span(expr_def_id),
739-
self.param_env,
740-
);
739+
.replace_opaque_types_with_inference_vars(output_ty, body_def_id, span, self.param_env);
741740
self.register_predicates(obligations);
742741

743742
Some(output_ty)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// edition:2021
2+
// revisions: current next
3+
//[next] compile-flags: -Ztrait-solver=next
4+
// check-pass
5+
6+
#![feature(type_alias_impl_trait)]
7+
8+
struct Foo;
9+
10+
impl Trait for Foo {}
11+
pub trait Trait {}
12+
13+
pub type TAIT<T> = impl Trait;
14+
15+
async fn foo<T>() -> TAIT<T> {
16+
Foo
17+
}
18+
19+
fn main() {}

0 commit comments

Comments
 (0)