]> git.lizzy.rs Git - rust.git/blobdiff - compiler/rustc_infer/src/infer/higher_ranked/mod.rs
`BoundVarReplacer`: trait object instead of 3 fns
[rust.git] / compiler / rustc_infer / src / infer / higher_ranked / mod.rs
index e543ae1fcdab15b965ef6ac9e22f09c1b0b444f3..ed257c144e0aacb3b1d9cf2d7da7cd2f907d7123 100644 (file)
@@ -4,6 +4,7 @@
 use super::combine::CombineFields;
 use super::{HigherRankedType, InferCtxt};
 use crate::infer::CombinedSnapshot;
+use rustc_middle::ty::fold::FnMutDelegate;
 use rustc_middle::ty::relate::{Relate, RelateResult, TypeRelation};
 use rustc_middle::ty::{self, Binder, TypeFoldable};
 
@@ -79,31 +80,31 @@ pub fn replace_bound_vars_with_placeholders<T>(&self, binder: ty::Binder<'tcx, T
 
         let next_universe = self.create_next_universe();
 
-        let fld_r = |br: ty::BoundRegion| {
-            self.tcx.mk_region(ty::RePlaceholder(ty::PlaceholderRegion {
-                universe: next_universe,
-                name: br.kind,
-            }))
-        };
-
-        let fld_t = |bound_ty: ty::BoundTy| {
-            self.tcx.mk_ty(ty::Placeholder(ty::PlaceholderType {
-                universe: next_universe,
-                name: bound_ty.var,
-            }))
-        };
-
-        let fld_c = |bound_var: ty::BoundVar, ty| {
-            self.tcx.mk_const(ty::ConstS {
-                kind: ty::ConstKind::Placeholder(ty::PlaceholderConst {
+        let delegate = FnMutDelegate {
+            regions: |br: ty::BoundRegion| {
+                self.tcx.mk_region(ty::RePlaceholder(ty::PlaceholderRegion {
+                    universe: next_universe,
+                    name: br.kind,
+                }))
+            },
+            types: |bound_ty: ty::BoundTy| {
+                self.tcx.mk_ty(ty::Placeholder(ty::PlaceholderType {
                     universe: next_universe,
-                    name: ty::BoundConst { var: bound_var, ty },
-                }),
-                ty,
-            })
+                    name: bound_ty.var,
+                }))
+            },
+            consts: |bound_var: ty::BoundVar, ty| {
+                self.tcx.mk_const(ty::ConstS {
+                    kind: ty::ConstKind::Placeholder(ty::PlaceholderConst {
+                        universe: next_universe,
+                        name: ty::BoundConst { var: bound_var, ty },
+                    }),
+                    ty,
+                })
+            },
         };
 
-        let result = self.tcx.replace_bound_vars_uncached(binder, fld_r, fld_t, fld_c);
+        let result = self.tcx.replace_bound_vars_uncached(binder, delegate);
         debug!(?next_universe, ?result);
         result
     }