hir_ty/next_solver/infer/
resolve.rs1use rustc_type_ir::{
4 ConstKind, FallibleTypeFolder, InferConst, InferTy, RegionKind, TyKind, TypeFoldable,
5 TypeFolder, TypeSuperFoldable, TypeVisitableExt, data_structures::DelayedMap,
6 inherent::IntoKind,
7};
8
9use crate::next_solver::{Const, DbInterner, Region, Ty};
10
11use super::{FixupError, FixupResult, InferCtxt};
12
13pub struct OpportunisticVarResolver<'a, 'db> {
22 infcx: &'a InferCtxt<'db>,
23 cache: DelayedMap<Ty<'db>, Ty<'db>>,
26}
27
28impl<'a, 'db> OpportunisticVarResolver<'a, 'db> {
29 #[inline]
30 pub fn new(infcx: &'a InferCtxt<'db>) -> Self {
31 OpportunisticVarResolver { infcx, cache: Default::default() }
32 }
33}
34
35impl<'a, 'db> TypeFolder<DbInterner<'db>> for OpportunisticVarResolver<'a, 'db> {
36 fn cx(&self) -> DbInterner<'db> {
37 self.infcx.interner
38 }
39
40 #[inline]
41 fn fold_ty(&mut self, t: Ty<'db>) -> Ty<'db> {
42 if !t.has_non_region_infer() {
43 t } else if let Some(ty) = self.cache.get(&t) {
45 *ty
46 } else {
47 let shallow = self.infcx.shallow_resolve(t);
48 let res = shallow.super_fold_with(self);
49 assert!(self.cache.insert(t, res));
50 res
51 }
52 }
53
54 fn fold_const(&mut self, ct: Const<'db>) -> Const<'db> {
55 if !ct.has_non_region_infer() {
56 ct } else {
58 let ct = self.infcx.shallow_resolve_const(ct);
59 ct.super_fold_with(self)
60 }
61 }
62}