@@ -17,6 +17,9 @@ use crate::infer::TyOrConstInferVar;
1717/// points for correctness.
1818pub struct OpportunisticVarResolver < ' a , ' tcx > {
1919 infcx : & ' a InferCtxt < ' tcx > ,
20+ /// If true, we don't resolve ty/const vars to their roots.
21+ /// See comments on [`InferCtxt::resolve_vars_if_possible_for_fudging`]
22+ for_fudging : bool ,
2023 /// We're able to use a cache here as the folder does
2124 /// not have any mutable state.
2225 cache : DelayedMap < Ty < ' tcx > , Ty < ' tcx > > ,
@@ -25,7 +28,12 @@ pub struct OpportunisticVarResolver<'a, 'tcx> {
2528impl < ' a , ' tcx > OpportunisticVarResolver < ' a , ' tcx > {
2629 #[ inline]
2730 pub fn new ( infcx : & ' a InferCtxt < ' tcx > ) -> Self {
28- OpportunisticVarResolver { infcx, cache : Default :: default ( ) }
31+ OpportunisticVarResolver { infcx, for_fudging : false , cache : Default :: default ( ) }
32+ }
33+
34+ #[ inline]
35+ pub fn new_for_fudging ( infcx : & ' a InferCtxt < ' tcx > ) -> Self {
36+ OpportunisticVarResolver { infcx, for_fudging : true , cache : Default :: default ( ) }
2937 }
3038}
3139
@@ -43,6 +51,7 @@ impl<'a, 'tcx> TypeFolder<TyCtxt<'tcx>> for OpportunisticVarResolver<'a, 'tcx> {
4351 } else {
4452 let shallow = self . infcx . shallow_resolve ( t) ;
4553 let res = shallow. super_fold_with ( self ) ;
54+ let res = if self . for_fudging && res. is_ty_var ( ) { t } else { res } ;
4655 assert ! ( self . cache. insert( t, res) ) ;
4756 res
4857 }
@@ -52,8 +61,11 @@ impl<'a, 'tcx> TypeFolder<TyCtxt<'tcx>> for OpportunisticVarResolver<'a, 'tcx> {
5261 if !ct. has_non_region_infer ( ) {
5362 ct // micro-optimize -- if there is nothing in this const that this fold affects...
5463 } else {
55- let ct = self . infcx . shallow_resolve_const ( ct) ;
56- ct. super_fold_with ( self )
64+ let res = self . infcx . shallow_resolve_const ( ct) ;
65+ if self . for_fudging && res. is_ct_infer ( ) {
66+ return ct;
67+ } ;
68+ res. super_fold_with ( self )
5769 }
5870 }
5971
0 commit comments