From c75e6e0f6c55d11ef06767cb42f617ae5e5b3870 Mon Sep 17 00:00:00 2001 From: Ali MJ Al-Nasrawy Date: Thu, 15 Jun 2023 12:49:49 +0000 Subject: [PATCH] normalize closure output before relation --- .../src/type_check/input_output.rs | 16 +----- .../issue-112604-closure-output-normalize.rs | 49 +++++++++++++++++++ 2 files changed, 50 insertions(+), 15 deletions(-) create mode 100644 tests/ui/nll/issue-112604-closure-output-normalize.rs diff --git a/compiler/rustc_borrowck/src/type_check/input_output.rs b/compiler/rustc_borrowck/src/type_check/input_output.rs index a06d4bcc6c7ae..eec886b7be48f 100644 --- a/compiler/rustc_borrowck/src/type_check/input_output.rs +++ b/compiler/rustc_borrowck/src/type_check/input_output.rs @@ -124,21 +124,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { // Return types are a bit more complex. They may contain opaque `impl Trait` types. let mir_output_ty = body.local_decls[RETURN_PLACE].ty; let output_span = body.local_decls[RETURN_PLACE].source_info.span; - if let Err(terr) = self.eq_types( - normalized_output_ty, - mir_output_ty, - Locations::All(output_span), - ConstraintCategory::BoringNoLocation, - ) { - span_mirbug!( - self, - Location::START, - "equate_inputs_and_outputs: `{:?}=={:?}` failed with `{:?}`", - normalized_output_ty, - mir_output_ty, - terr - ); - }; + self.equate_normalized_input_or_output(normalized_output_ty, mir_output_ty, output_span); } #[instrument(skip(self), level = "debug")] diff --git a/tests/ui/nll/issue-112604-closure-output-normalize.rs b/tests/ui/nll/issue-112604-closure-output-normalize.rs new file mode 100644 index 0000000000000..e4c954eeb33d2 --- /dev/null +++ b/tests/ui/nll/issue-112604-closure-output-normalize.rs @@ -0,0 +1,49 @@ +//check-pass + +use higher_kinded_types::*; +mod higher_kinded_types { + pub(crate) trait HKT { + type Of<'lt>; + } + + pub(crate) trait WithLifetime<'lt> { + type T; + } + + impl WithLifetime<'any>> HKT for T { + type Of<'lt> = >::T; + } +} + +trait Trait { + type Gat<'lt>; +} + +impl Trait for () { + type Gat<'lt> = (); +} + +/// Same as `Trait`, but using HKTs rather than GATs +trait HTrait { + type Hat: ?Sized + HKT; +} + +impl HTrait for T { + type Hat = dyn for<'lt> WithLifetime<'lt, T = T::Gat<'lt>>; +} + +impl Trait for Box> { + type Gat<'lt> = Hat::Of<'lt>; +} + +fn existential() -> impl for<'a> Trait = ()> {} + +fn dyn_hoops( + _: T, +) -> Box WithLifetime<'a, T = T::Gat<'a>>>> { + loop {} +} + +fn main() { + let _ = || -> _ { dyn_hoops(existential()) }; +}