@@ -803,7 +803,7 @@ impl<'cx, 'tcx> Resolver<'cx, 'tcx> {
803
803
// We must deeply normalize in the new solver, since later lints
804
804
// expect that types that show up in the typeck are fully
805
805
// normalized.
806
- let value = if self . should_normalize {
806
+ let mut value = if self . should_normalize {
807
807
let body_id = tcx. hir ( ) . body_owner_def_id ( self . body . id ( ) ) ;
808
808
let cause = ObligationCause :: misc ( self . span . to_span ( tcx) , body_id) ;
809
809
let at = self . fcx . at ( & cause, self . fcx . param_env ) ;
@@ -818,12 +818,27 @@ impl<'cx, 'tcx> Resolver<'cx, 'tcx> {
818
818
value
819
819
} ;
820
820
821
+ // Bail if there are any non-region infer.
821
822
if value. has_non_region_infer ( ) {
822
823
let guar = self . report_error ( value) ;
823
- new_err ( tcx, guar)
824
- } else {
825
- tcx. fold_regions ( value, |_, _| tcx. lifetimes . re_erased )
824
+ value = new_err ( tcx, guar) ;
825
+ }
826
+
827
+ // Erase the regions from the ty, since it's not really meaningful what
828
+ // these region values are; there's not a trivial correspondence between
829
+ // regions in the HIR and MIR, so when we turn the body into MIR, there's
830
+ // no reason to keep regions around. They will be repopulated during MIR
831
+ // borrowck, and specifically region constraints will be populated during
832
+ // MIR typeck which is run on the new body.
833
+ value = tcx. fold_regions ( value, |_, _| tcx. lifetimes . re_erased ) ;
834
+
835
+ // Normalize consts in writeback, because GCE doesn't normalize eagerly.
836
+ if tcx. features ( ) . generic_const_exprs {
837
+ value =
838
+ value. fold_with ( & mut EagerlyNormalizeConsts { tcx, param_env : self . fcx . param_env } ) ;
826
839
}
840
+
841
+ value
827
842
}
828
843
}
829
844
@@ -858,3 +873,17 @@ impl<'cx, 'tcx> TypeFolder<TyCtxt<'tcx>> for Resolver<'cx, 'tcx> {
858
873
predicate
859
874
}
860
875
}
876
+
877
+ struct EagerlyNormalizeConsts < ' tcx > {
878
+ tcx : TyCtxt < ' tcx > ,
879
+ param_env : ty:: ParamEnv < ' tcx > ,
880
+ }
881
+ impl < ' tcx > TypeFolder < TyCtxt < ' tcx > > for EagerlyNormalizeConsts < ' tcx > {
882
+ fn cx ( & self ) -> TyCtxt < ' tcx > {
883
+ self . tcx
884
+ }
885
+
886
+ fn fold_const ( & mut self , ct : ty:: Const < ' tcx > ) -> ty:: Const < ' tcx > {
887
+ self . tcx . try_normalize_erasing_regions ( self . param_env , ct) . unwrap_or ( ct)
888
+ }
889
+ }
0 commit comments