Skip to content

Commit e28f0c9

Browse files
committed
Get rid of some walk_mut uses
1 parent 30a339e commit e28f0c9

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

crates/hir_ty/src/infer/unify.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,19 +108,22 @@ impl<'a, 'b> Canonicalizer<'a, 'b> {
108108
}
109109

110110
impl<T> Canonicalized<T> {
111-
pub(super) fn decanonicalize_ty(&self, mut ty: Ty) -> Ty {
112-
ty.walk_mut_binders(
111+
pub(super) fn decanonicalize_ty(&self, ty: Ty) -> Ty {
112+
ty.fold_binders(
113113
&mut |ty, binders| {
114-
if let &mut TyKind::BoundVar(bound) = ty.interned_mut() {
114+
if let TyKind::BoundVar(bound) = ty.kind(&Interner) {
115115
if bound.debruijn >= binders {
116116
let (v, k) = self.free_vars[bound.index];
117-
*ty = TyKind::InferenceVar(v, k).intern(&Interner);
117+
TyKind::InferenceVar(v, k).intern(&Interner)
118+
} else {
119+
ty
118120
}
121+
} else {
122+
ty
119123
}
120124
},
121125
DebruijnIndex::INNERMOST,
122-
);
123-
ty
126+
)
124127
}
125128

126129
pub(super) fn apply_solution(

crates/hir_ty/src/lower.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,17 +1011,19 @@ pub(crate) fn generic_defaults_query(
10111011
p.default.as_ref().map_or(TyKind::Error.intern(&Interner), |t| ctx.lower_ty(t));
10121012

10131013
// Each default can only refer to previous parameters.
1014-
ty.walk_mut_binders(
1015-
&mut |ty, binders| match ty.interned_mut() {
1014+
ty = ty.fold_binders(
1015+
&mut |ty, binders| match ty.kind(&Interner) {
10161016
TyKind::BoundVar(BoundVar { debruijn, index }) if *debruijn == binders => {
10171017
if *index >= idx {
10181018
// type variable default referring to parameter coming
10191019
// after it. This is forbidden (FIXME: report
10201020
// diagnostic)
1021-
*ty = TyKind::Error.intern(&Interner);
1021+
TyKind::Error.intern(&Interner)
1022+
} else {
1023+
ty
10221024
}
10231025
}
1024-
_ => {}
1026+
_ => ty,
10251027
},
10261028
DebruijnIndex::INNERMOST,
10271029
);

0 commit comments

Comments
 (0)