@@ -344,7 +344,7 @@ impl<'cx, 'tcx> Visitor<'tcx> for WritebackCx<'cx, 'tcx> {
344
344
fn visit_local ( & mut self , l : & ' tcx hir:: LetStmt < ' tcx > ) {
345
345
intravisit:: walk_local ( self , l) ;
346
346
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 ) ;
348
348
self . write_ty_to_typeck_results ( l. hir_id , var_ty) ;
349
349
}
350
350
@@ -353,7 +353,7 @@ impl<'cx, 'tcx> Visitor<'tcx> for WritebackCx<'cx, 'tcx> {
353
353
// If there are type checking errors, Type privacy pass will stop,
354
354
// so we may not get the type from hid_id, see #104513
355
355
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 ) ;
357
357
self . write_ty_to_typeck_results ( hir_ty. hir_id , ty) ;
358
358
}
359
359
}
@@ -370,7 +370,7 @@ impl<'cx, 'tcx> Visitor<'tcx> for WritebackCx<'cx, 'tcx> {
370
370
// the typeck results as there is not yet any part of the compiler that
371
371
// needs this information.
372
372
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 ) ;
374
374
self . write_ty_to_typeck_results ( inf_id, ty) ;
375
375
}
376
376
}
@@ -387,7 +387,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
387
387
. into_iter ( )
388
388
. map ( |( & closure_def_id, data) | {
389
389
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 ) ;
391
391
( closure_def_id, data)
392
392
} )
393
393
. collect ( ) ;
@@ -413,7 +413,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
413
413
captured_place. info . path_expr_id . unwrap_or_else ( || {
414
414
self . tcx ( ) . local_def_id_to_hir_id ( closure_def_id)
415
415
} ) ;
416
- self . resolve ( captured_place. clone ( ) , & locatable)
416
+ self . resolve ( captured_place. clone ( ) , & locatable, true )
417
417
} )
418
418
. collect ( ) ;
419
419
( * var_hir_id, min_list_wb)
@@ -438,7 +438,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
438
438
. iter ( )
439
439
. map ( |( place, cause, hir_id) | {
440
440
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 ) ;
442
442
( resolved_fake_read, * cause, * hir_id)
443
443
} )
444
444
. collect ( ) ;
@@ -460,7 +460,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
460
460
for ( local_id, origin) in fcx_closure_kind_origins {
461
461
let hir_id = HirId { owner : common_hir_owner, local_id } ;
462
462
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 ) ;
464
464
self . typeck_results . closure_kind_origins_mut ( ) . insert ( hir_id, ( place_span, place) ) ;
465
465
}
466
466
}
@@ -548,7 +548,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
548
548
let fcx_typeck_results = self . fcx . typeck_results . borrow ( ) ;
549
549
assert_eq ! ( fcx_typeck_results. hir_owner, self . typeck_results. hir_owner) ;
550
550
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 ) ;
552
552
self . typeck_results . coroutine_stalled_predicates . insert ( ( predicate, cause) ) ;
553
553
}
554
554
}
@@ -565,8 +565,8 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
565
565
// fixpoint.
566
566
let opaque_types = self . fcx . infcx . clone_opaque_types ( ) ;
567
567
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 ) ;
570
570
571
571
if !self . fcx . next_trait_solver ( ) {
572
572
if let ty:: Alias ( ty:: Opaque , alias_ty) = hidden_type. ty . kind ( )
@@ -612,13 +612,13 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
612
612
613
613
// Resolve the type of the node with id `node_id`
614
614
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 ) ;
616
616
self . write_ty_to_typeck_results ( hir_id, n_ty) ;
617
617
debug ! ( ?n_ty) ;
618
618
619
619
// Resolve any generic parameters
620
620
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 ) ;
622
622
debug ! ( "write_args_to_tcx({:?}, {:?})" , hir_id, args) ;
623
623
assert ! ( !args. has_infer( ) && !args. has_placeholders( ) ) ;
624
624
self . typeck_results . node_args_mut ( ) . insert ( hir_id, args) ;
@@ -634,7 +634,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
634
634
}
635
635
636
636
Some ( adjustment) => {
637
- let resolved_adjustment = self . resolve ( adjustment, & span) ;
637
+ let resolved_adjustment = self . resolve ( adjustment, & span, true ) ;
638
638
debug ! ( ?resolved_adjustment) ;
639
639
self . typeck_results . adjustments_mut ( ) . insert ( hir_id, resolved_adjustment) ;
640
640
}
@@ -668,7 +668,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
668
668
}
669
669
670
670
Some ( adjustment) => {
671
- let resolved_adjustment = self . resolve ( adjustment, & span) ;
671
+ let resolved_adjustment = self . resolve ( adjustment, & span, true ) ;
672
672
debug ! ( ?resolved_adjustment) ;
673
673
self . typeck_results . pat_adjustments_mut ( ) . insert ( hir_id, resolved_adjustment) ;
674
674
}
@@ -692,7 +692,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
692
692
693
693
for ( local_id, & fn_sig) in fcx_liberated_fn_sigs {
694
694
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 ) ;
696
696
self . typeck_results . liberated_fn_sigs_mut ( ) . insert ( hir_id, fn_sig) ;
697
697
}
698
698
}
@@ -706,7 +706,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
706
706
707
707
for ( local_id, ftys) in fcx_fru_field_types {
708
708
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 ) ;
710
710
self . typeck_results . fru_field_types_mut ( ) . insert ( hir_id, ftys) ;
711
711
}
712
712
}
@@ -720,17 +720,18 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
720
720
fcx_typeck_results. offset_of_data ( ) . items_in_stable_order ( )
721
721
{
722
722
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 ) ;
724
724
self . typeck_results . offset_of_data_mut ( ) . insert ( hir_id, ( container, indices. clone ( ) ) ) ;
725
725
}
726
726
}
727
727
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
729
729
where
730
730
T : TypeFoldable < TyCtxt < ' tcx > > ,
731
731
{
732
732
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) ) ;
734
735
assert ! ( !value. has_infer( ) ) ;
735
736
736
737
// We may have introduced e.g. `ty::Error`, if inference failed, make sure
@@ -774,8 +775,9 @@ impl<'cx, 'tcx> Resolver<'cx, 'tcx> {
774
775
fcx : & ' cx FnCtxt < ' cx , ' tcx > ,
775
776
span : & ' cx dyn Locatable ,
776
777
body : & ' tcx hir:: Body < ' tcx > ,
778
+ should_normalize : bool ,
777
779
) -> Resolver < ' cx , ' tcx > {
778
- Resolver { fcx, span, body, should_normalize : fcx . next_trait_solver ( ) }
780
+ Resolver { fcx, span, body, should_normalize }
779
781
}
780
782
781
783
fn report_error ( & self , p : impl Into < ty:: GenericArg < ' tcx > > ) -> ErrorGuaranteed {
@@ -805,10 +807,9 @@ impl<'cx, 'tcx> Resolver<'cx, 'tcx> {
805
807
T : Into < ty:: GenericArg < ' tcx > > + TypeSuperFoldable < TyCtxt < ' tcx > > + Copy ,
806
808
{
807
809
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 ( ) {
812
813
let body_id = tcx. hir_body_owner_def_id ( self . body . id ( ) ) ;
813
814
let cause = ObligationCause :: misc ( self . span . to_span ( tcx) , body_id) ;
814
815
let at = self . fcx . at ( & cause, self . fcx . param_env ) ;
@@ -868,13 +869,11 @@ impl<'cx, 'tcx> TypeFolder<TyCtxt<'tcx>> for Resolver<'cx, 'tcx> {
868
869
}
869
870
870
871
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 )
878
877
}
879
878
}
880
879
0 commit comments