@@ -8,12 +8,15 @@ use rustc_errors::{ErrorGuaranteed, StashKey};
88use rustc_hir as hir;
99use rustc_hir:: intravisit:: { self , Visitor } ;
1010use rustc_infer:: infer:: error_reporting:: TypeAnnotationNeeded :: E0282 ;
11+ use rustc_middle:: traits:: ObligationCause ;
1112use rustc_middle:: ty:: adjustment:: { Adjust , Adjustment , PointerCoercion } ;
1213use rustc_middle:: ty:: fold:: { TypeFoldable , TypeFolder } ;
1314use rustc_middle:: ty:: visit:: TypeVisitableExt ;
1415use rustc_middle:: ty:: { self , Ty , TyCtxt } ;
1516use rustc_span:: symbol:: sym;
1617use rustc_span:: Span ;
18+ use rustc_trait_selection:: solve;
19+ use rustc_trait_selection:: traits:: error_reporting:: TypeErrCtxtExt ;
1720
1821use std:: mem;
1922
@@ -778,14 +781,21 @@ impl<'cx, 'tcx> TypeFolder<TyCtxt<'tcx>> for Resolver<'cx, 'tcx> {
778781 fn fold_ty ( & mut self , t : Ty < ' tcx > ) -> Ty < ' tcx > {
779782 let tcx = self . fcx . tcx ;
780783 match self . fcx . fully_resolve ( t) {
781- Ok ( t ) if self . fcx . next_trait_solver ( ) => {
782- // We must normalize erasing regions here, since later lints
784+ Ok ( ty ) if self . fcx . next_trait_solver ( ) => {
785+ // We must deeply normalize here, since later lints
783786 // expect that types that show up in the typeck are fully
784787 // normalized.
785- if let Ok ( t) = tcx. try_normalize_erasing_regions ( self . fcx . param_env , t) {
786- t
787- } else {
788- tcx. fold_regions ( t, |_, _| tcx. lifetimes . re_erased )
788+
789+ // FIXME(-Ztrait-solver=next): This is probably not
790+ // very performant.
791+ let body_id = tcx. hir ( ) . body_owner_def_id ( self . body . id ( ) ) ;
792+ let cause = ObligationCause :: misc ( self . span . to_span ( tcx) , body_id) ;
793+ match solve:: deeply_normalize ( self . fcx . at ( & cause, self . fcx . param_env ) , ty) {
794+ Ok ( ty) => tcx. fold_regions ( ty, |_, _| tcx. lifetimes . re_erased ) ,
795+ Err ( errors) => {
796+ let guar = self . fcx . err_ctxt ( ) . report_fulfillment_errors ( errors) ;
797+ Ty :: new_error ( tcx, guar)
798+ }
789799 }
790800 }
791801 Ok ( t) => {
0 commit comments