Skip to content

Commit 35c37d0

Browse files
authored
Unrolled build for rust-lang#116436
Rollup merge of rust-lang#116436 - compiler-errors:structurally-normalize-for-closure, r=lcnr Structurally normalize for closure Fixes some signature deduction problems in the new trait solver (and in the case of async, an ICE). r? lcnr
2 parents c1691db + dfbb1bf commit 35c37d0

File tree

3 files changed

+36
-7
lines changed

3 files changed

+36
-7
lines changed

compiler/rustc_hir_typeck/src/closure.rs

+13-7
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
5656
// closure sooner rather than later, so first examine the expected
5757
// type, and see if can glean a closure kind from there.
5858
let (expected_sig, expected_kind) = match expected.to_option(self) {
59-
Some(ty) => self.deduce_closure_signature(ty),
59+
Some(ty) => {
60+
self.deduce_closure_signature(self.try_structurally_resolve_type(expr_span, ty))
61+
}
6062
None => (None, None),
6163
};
6264
let body = self.tcx.hir().body(closure.body);
@@ -688,8 +690,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
688690
span_bug!(self.tcx.def_span(expr_def_id), "async fn generator outside of a fn")
689691
});
690692

693+
let closure_span = self.tcx.def_span(expr_def_id);
691694
let ret_ty = ret_coercion.borrow().expected_ty();
692-
let ret_ty = self.inh.infcx.shallow_resolve(ret_ty);
695+
let ret_ty = self.try_structurally_resolve_type(closure_span, ret_ty);
693696

694697
let get_future_output = |predicate: ty::Predicate<'tcx>, span| {
695698
// Search for a pending obligation like
@@ -711,8 +714,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
711714
}
712715
};
713716

714-
let span = self.tcx.def_span(expr_def_id);
715-
716717
let output_ty = match *ret_ty.kind() {
717718
ty::Infer(ty::TyVar(ret_vid)) => {
718719
self.obligations_for_self_ty(ret_vid).find_map(|obligation| {
@@ -726,17 +727,22 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
726727
.find_map(|(p, s)| get_future_output(p.as_predicate(), s))?,
727728
ty::Error(_) => return None,
728729
_ => span_bug!(
729-
span,
730+
closure_span,
730731
"async fn generator return type not an inference variable: {ret_ty}"
731732
),
732733
};
733734

734-
let output_ty = self.normalize(span, output_ty);
735+
let output_ty = self.normalize(closure_span, output_ty);
735736

736737
// async fn that have opaque types in their return type need to redo the conversion to inference variables
737738
// as they fetch the still opaque version from the signature.
738739
let InferOk { value: output_ty, obligations } = self
739-
.replace_opaque_types_with_inference_vars(output_ty, body_def_id, span, self.param_env);
740+
.replace_opaque_types_with_inference_vars(
741+
output_ty,
742+
body_def_id,
743+
closure_span,
744+
self.param_env,
745+
);
740746
self.register_predicates(obligations);
741747

742748
Some(output_ty)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// compile-flags: -Ztrait-solver=next
2+
// check-pass
3+
4+
#![feature(return_position_impl_trait_in_trait)]
5+
6+
trait Foo {
7+
fn test() -> impl Fn(u32) -> u32 {
8+
|x| x.count_ones()
9+
}
10+
}
11+
12+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// compile-flags: -Ztrait-solver=next
2+
// check-pass
3+
// edition:2021
4+
5+
#![feature(async_fn_in_trait)]
6+
7+
trait Foo {
8+
async fn bar() {}
9+
}
10+
11+
fn main() {}

0 commit comments

Comments
 (0)