@@ -344,7 +344,7 @@ impl<'cx, 'tcx> Visitor<'tcx> for WritebackCx<'cx, 'tcx> {
344344 fn visit_local ( & mut self , l : & ' tcx hir:: LetStmt < ' tcx > ) {
345345 intravisit:: walk_local ( self , l) ;
346346 let var_ty = self . fcx . local_ty ( l. span , l. hir_id ) ;
347- let var_ty = self . resolve ( var_ty, & l. span ) ;
347+ let var_ty = self . resolve ( var_ty, & l. span , true ) ;
348348 self . write_ty_to_typeck_results ( l. hir_id , var_ty) ;
349349 }
350350
@@ -353,7 +353,7 @@ impl<'cx, 'tcx> Visitor<'tcx> for WritebackCx<'cx, 'tcx> {
353353 // If there are type checking errors, Type privacy pass will stop,
354354 // so we may not get the type from hid_id, see #104513
355355 if let Some ( ty) = self . fcx . node_ty_opt ( hir_ty. hir_id ) {
356- let ty = self . resolve ( ty, & hir_ty. span ) ;
356+ let ty = self . resolve ( ty, & hir_ty. span , true ) ;
357357 self . write_ty_to_typeck_results ( hir_ty. hir_id , ty) ;
358358 }
359359 }
@@ -370,7 +370,7 @@ impl<'cx, 'tcx> Visitor<'tcx> for WritebackCx<'cx, 'tcx> {
370370 // the typeck results as there is not yet any part of the compiler that
371371 // needs this information.
372372 if let Some ( ty) = self . fcx . node_ty_opt ( inf_id) {
373- let ty = self . resolve ( ty, & inf_span) ;
373+ let ty = self . resolve ( ty, & inf_span, true ) ;
374374 self . write_ty_to_typeck_results ( inf_id, ty) ;
375375 }
376376 }
@@ -387,7 +387,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
387387 . into_iter ( )
388388 . map ( |( & closure_def_id, data) | {
389389 let closure_hir_id = self . tcx ( ) . local_def_id_to_hir_id ( closure_def_id) ;
390- let data = self . resolve ( * data, & closure_hir_id) ;
390+ let data = self . resolve ( * data, & closure_hir_id, true ) ;
391391 ( closure_def_id, data)
392392 } )
393393 . collect ( ) ;
@@ -413,7 +413,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
413413 captured_place. info . path_expr_id . unwrap_or_else ( || {
414414 self . tcx ( ) . local_def_id_to_hir_id ( closure_def_id)
415415 } ) ;
416- self . resolve ( captured_place. clone ( ) , & locatable)
416+ self . resolve ( captured_place. clone ( ) , & locatable, true )
417417 } )
418418 . collect ( ) ;
419419 ( * var_hir_id, min_list_wb)
@@ -438,7 +438,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
438438 . iter ( )
439439 . map ( |( place, cause, hir_id) | {
440440 let locatable = self . tcx ( ) . local_def_id_to_hir_id ( closure_def_id) ;
441- let resolved_fake_read = self . resolve ( place. clone ( ) , & locatable) ;
441+ let resolved_fake_read = self . resolve ( place. clone ( ) , & locatable, true ) ;
442442 ( resolved_fake_read, * cause, * hir_id)
443443 } )
444444 . collect ( ) ;
@@ -460,7 +460,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
460460 for ( local_id, origin) in fcx_closure_kind_origins {
461461 let hir_id = HirId { owner : common_hir_owner, local_id } ;
462462 let place_span = origin. 0 ;
463- let place = self . resolve ( origin. 1 . clone ( ) , & place_span) ;
463+ let place = self . resolve ( origin. 1 . clone ( ) , & place_span, true ) ;
464464 self . typeck_results . closure_kind_origins_mut ( ) . insert ( hir_id, ( place_span, place) ) ;
465465 }
466466 }
@@ -548,7 +548,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
548548 let fcx_typeck_results = self . fcx . typeck_results . borrow ( ) ;
549549 assert_eq ! ( fcx_typeck_results. hir_owner, self . typeck_results. hir_owner) ;
550550 for ( predicate, cause) in & fcx_typeck_results. coroutine_stalled_predicates {
551- let ( predicate, cause) = self . resolve ( ( * predicate, cause. clone ( ) ) , & cause. span ) ;
551+ let ( predicate, cause) = self . resolve ( ( * predicate, cause. clone ( ) ) , & cause. span , false ) ;
552552 self . typeck_results . coroutine_stalled_predicates . insert ( ( predicate, cause) ) ;
553553 }
554554 }
@@ -565,8 +565,8 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
565565 // fixpoint.
566566 let opaque_types = self . fcx . infcx . clone_opaque_types ( ) ;
567567 for ( opaque_type_key, hidden_type) in opaque_types {
568- let hidden_type = self . resolve ( hidden_type, & hidden_type. span ) ;
569- let opaque_type_key = self . resolve ( opaque_type_key, & hidden_type. span ) ;
568+ let hidden_type = self . resolve ( hidden_type, & hidden_type. span , true ) ;
569+ let opaque_type_key = self . resolve ( opaque_type_key, & hidden_type. span , true ) ;
570570
571571 if !self . fcx . next_trait_solver ( ) {
572572 if let ty:: Alias ( ty:: Opaque , alias_ty) = hidden_type. ty . kind ( )
@@ -612,13 +612,13 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
612612
613613 // Resolve the type of the node with id `node_id`
614614 let n_ty = self . fcx . node_ty ( hir_id) ;
615- let n_ty = self . resolve ( n_ty, & span) ;
615+ let n_ty = self . resolve ( n_ty, & span, true ) ;
616616 self . write_ty_to_typeck_results ( hir_id, n_ty) ;
617617 debug ! ( ?n_ty) ;
618618
619619 // Resolve any generic parameters
620620 if let Some ( args) = self . fcx . typeck_results . borrow ( ) . node_args_opt ( hir_id) {
621- let args = self . resolve ( args, & span) ;
621+ let args = self . resolve ( args, & span, true ) ;
622622 debug ! ( "write_args_to_tcx({:?}, {:?})" , hir_id, args) ;
623623 assert ! ( !args. has_infer( ) && !args. has_placeholders( ) ) ;
624624 self . typeck_results . node_args_mut ( ) . insert ( hir_id, args) ;
@@ -634,7 +634,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
634634 }
635635
636636 Some ( adjustment) => {
637- let resolved_adjustment = self . resolve ( adjustment, & span) ;
637+ let resolved_adjustment = self . resolve ( adjustment, & span, true ) ;
638638 debug ! ( ?resolved_adjustment) ;
639639 self . typeck_results . adjustments_mut ( ) . insert ( hir_id, resolved_adjustment) ;
640640 }
@@ -668,7 +668,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
668668 }
669669
670670 Some ( adjustment) => {
671- let resolved_adjustment = self . resolve ( adjustment, & span) ;
671+ let resolved_adjustment = self . resolve ( adjustment, & span, true ) ;
672672 debug ! ( ?resolved_adjustment) ;
673673 self . typeck_results . pat_adjustments_mut ( ) . insert ( hir_id, resolved_adjustment) ;
674674 }
@@ -692,7 +692,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
692692
693693 for ( local_id, & fn_sig) in fcx_liberated_fn_sigs {
694694 let hir_id = HirId { owner : common_hir_owner, local_id } ;
695- let fn_sig = self . resolve ( fn_sig, & hir_id) ;
695+ let fn_sig = self . resolve ( fn_sig, & hir_id, true ) ;
696696 self . typeck_results . liberated_fn_sigs_mut ( ) . insert ( hir_id, fn_sig) ;
697697 }
698698 }
@@ -706,7 +706,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
706706
707707 for ( local_id, ftys) in fcx_fru_field_types {
708708 let hir_id = HirId { owner : common_hir_owner, local_id } ;
709- let ftys = self . resolve ( ftys. clone ( ) , & hir_id) ;
709+ let ftys = self . resolve ( ftys. clone ( ) , & hir_id, true ) ;
710710 self . typeck_results . fru_field_types_mut ( ) . insert ( hir_id, ftys) ;
711711 }
712712 }
@@ -720,17 +720,18 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
720720 fcx_typeck_results. offset_of_data ( ) . items_in_stable_order ( )
721721 {
722722 let hir_id = HirId { owner : common_hir_owner, local_id } ;
723- let container = self . resolve ( container, & hir_id) ;
723+ let container = self . resolve ( container, & hir_id, true ) ;
724724 self . typeck_results . offset_of_data_mut ( ) . insert ( hir_id, ( container, indices. clone ( ) ) ) ;
725725 }
726726 }
727727
728- fn resolve < T > ( & mut self , value : T , span : & dyn Locatable ) -> T
728+ fn resolve < T > ( & mut self , value : T , span : & dyn Locatable , should_normalize : bool ) -> T
729729 where
730730 T : TypeFoldable < TyCtxt < ' tcx > > ,
731731 {
732732 let value = self . fcx . resolve_vars_if_possible ( value) ;
733- let value = value. fold_with ( & mut Resolver :: new ( self . fcx , span, self . body ) ) ;
733+ let value =
734+ value. fold_with ( & mut Resolver :: new ( self . fcx , span, self . body , should_normalize) ) ;
734735 assert ! ( !value. has_infer( ) ) ;
735736
736737 // We may have introduced e.g. `ty::Error`, if inference failed, make sure
@@ -774,8 +775,9 @@ impl<'cx, 'tcx> Resolver<'cx, 'tcx> {
774775 fcx : & ' cx FnCtxt < ' cx , ' tcx > ,
775776 span : & ' cx dyn Locatable ,
776777 body : & ' tcx hir:: Body < ' tcx > ,
778+ should_normalize : bool ,
777779 ) -> Resolver < ' cx , ' tcx > {
778- Resolver { fcx, span, body, should_normalize : fcx . next_trait_solver ( ) }
780+ Resolver { fcx, span, body, should_normalize }
779781 }
780782
781783 fn report_error ( & self , p : impl Into < ty:: GenericArg < ' tcx > > ) -> ErrorGuaranteed {
@@ -805,10 +807,9 @@ impl<'cx, 'tcx> Resolver<'cx, 'tcx> {
805807 T : Into < ty:: GenericArg < ' tcx > > + TypeSuperFoldable < TyCtxt < ' tcx > > + Copy ,
806808 {
807809 let tcx = self . fcx . tcx ;
808- // We must deeply normalize in the new solver, since later lints
809- // expect that types that show up in the typeck are fully
810- // normalized.
811- let mut value = if self . should_normalize {
810+ // We must deeply normalize in the new solver, since later lints expect
811+ // that types that show up in the typeck are fully normalized.
812+ let mut value = if self . should_normalize && self . fcx . next_trait_solver ( ) {
812813 let body_id = tcx. hir_body_owner_def_id ( self . body . id ( ) ) ;
813814 let cause = ObligationCause :: misc ( self . span . to_span ( tcx) , body_id) ;
814815 let at = self . fcx . at ( & cause, self . fcx . param_env ) ;
@@ -868,13 +869,11 @@ impl<'cx, 'tcx> TypeFolder<TyCtxt<'tcx>> for Resolver<'cx, 'tcx> {
868869 }
869870
870871 fn fold_predicate ( & mut self , predicate : ty:: Predicate < ' tcx > ) -> ty:: Predicate < ' tcx > {
871- // Do not normalize predicates in the new solver. The new solver is
872- // supposed to handle unnormalized predicates and incorrectly normalizing
873- // them can be unsound, e.g. for `WellFormed` predicates.
874- let prev = mem:: replace ( & mut self . should_normalize , false ) ;
875- let predicate = predicate. super_fold_with ( self ) ;
876- self . should_normalize = prev;
877- predicate
872+ assert ! (
873+ !self . should_normalize,
874+ "normalizing predicats in writeback is not generally sound"
875+ ) ;
876+ predicate. super_fold_with ( self )
878877 }
879878}
880879
0 commit comments