]> git.lizzy.rs Git - rust.git/commitdiff
Put a `ShallowResolver` within `OpportunisticVarResolver`.
authorNicholas Nethercote <n.nethercote@gmail.com>
Thu, 2 Feb 2023 22:00:56 +0000 (09:00 +1100)
committerNicholas Nethercote <n.nethercote@gmail.com>
Sun, 5 Feb 2023 21:50:48 +0000 (08:50 +1100)
So one doesn't have to be constructed every time.

compiler/rustc_infer/src/infer/resolve.rs

index 65b90aa3d79d3e285365339e8ec6812c000e09b6..49cd9a9c3d0fbfc0f6a063d218d01b72f3188dcb 100644 (file)
 /// useful for printing messages etc but also required at various
 /// points for correctness.
 pub struct OpportunisticVarResolver<'a, 'tcx> {
-    infcx: &'a InferCtxt<'tcx>,
+    // The shallow resolver is used to resolve inference variables at every
+    // level of the type.
+    shallow_resolver: crate::infer::ShallowResolver<'a, 'tcx>,
 }
 
 impl<'a, 'tcx> OpportunisticVarResolver<'a, 'tcx> {
     #[inline]
     pub fn new(infcx: &'a InferCtxt<'tcx>) -> Self {
-        OpportunisticVarResolver { infcx }
+        OpportunisticVarResolver { shallow_resolver: crate::infer::ShallowResolver { infcx } }
     }
 }
 
 impl<'a, 'tcx> TypeFolder<'tcx> for OpportunisticVarResolver<'a, 'tcx> {
     fn tcx<'b>(&'b self) -> TyCtxt<'tcx> {
-        self.infcx.tcx
+        TypeFolder::tcx(&self.shallow_resolver)
     }
 
     fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> {
         if !t.has_non_region_infer() {
             t // micro-optimize -- if there is nothing in this type that this fold affects...
         } else {
-            let t = self.infcx.shallow_resolve(t);
+            let t = self.shallow_resolver.fold_ty(t);
             t.super_fold_with(self)
         }
     }
@@ -44,7 +46,7 @@ fn fold_const(&mut self, ct: Const<'tcx>) -> Const<'tcx> {
         if !ct.has_non_region_infer() {
             ct // micro-optimize -- if there is nothing in this const that this fold affects...
         } else {
-            let ct = self.infcx.shallow_resolve(ct);
+            let ct = self.shallow_resolver.fold_const(ct);
             ct.super_fold_with(self)
         }
     }