aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/hir_ty/src/infer/unify.rs15
-rw-r--r--crates/hir_ty/src/lower.rs10
2 files changed, 15 insertions, 10 deletions
diff --git a/crates/hir_ty/src/infer/unify.rs b/crates/hir_ty/src/infer/unify.rs
index 8370f2e1c..06187df56 100644
--- a/crates/hir_ty/src/infer/unify.rs
+++ b/crates/hir_ty/src/infer/unify.rs
@@ -108,19 +108,22 @@ impl<'a, 'b> Canonicalizer<'a, 'b> {
108} 108}
109 109
110impl<T> Canonicalized<T> { 110impl<T> Canonicalized<T> {
111 pub(super) fn decanonicalize_ty(&self, mut ty: Ty) -> Ty { 111 pub(super) fn decanonicalize_ty(&self, ty: Ty) -> Ty {
112 ty.walk_mut_binders( 112 ty.fold_binders(
113 &mut |ty, binders| { 113 &mut |ty, binders| {
114 if let &mut TyKind::BoundVar(bound) = ty.interned_mut() { 114 if let TyKind::BoundVar(bound) = ty.kind(&Interner) {
115 if bound.debruijn >= binders { 115 if bound.debruijn >= binders {
116 let (v, k) = self.free_vars[bound.index]; 116 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
118 } 120 }
121 } else {
122 ty
119 } 123 }
120 }, 124 },
121 DebruijnIndex::INNERMOST, 125 DebruijnIndex::INNERMOST,
122 ); 126 )
123 ty
124 } 127 }
125 128
126 pub(super) fn apply_solution( 129 pub(super) fn apply_solution(
diff --git a/crates/hir_ty/src/lower.rs b/crates/hir_ty/src/lower.rs
index 00838b298..a3c3ef6b2 100644
--- a/crates/hir_ty/src/lower.rs
+++ b/crates/hir_ty/src/lower.rs
@@ -1011,17 +1011,19 @@ pub(crate) fn generic_defaults_query(
1011 p.default.as_ref().map_or(TyKind::Error.intern(&Interner), |t| ctx.lower_ty(t)); 1011 p.default.as_ref().map_or(TyKind::Error.intern(&Interner), |t| ctx.lower_ty(t));
1012 1012
1013 // Each default can only refer to previous parameters. 1013 // Each default can only refer to previous parameters.
1014 ty.walk_mut_binders( 1014 ty = ty.fold_binders(
1015 &mut |ty, binders| match ty.interned_mut() { 1015 &mut |ty, binders| match ty.kind(&Interner) {
1016 TyKind::BoundVar(BoundVar { debruijn, index }) if *debruijn == binders => { 1016 TyKind::BoundVar(BoundVar { debruijn, index }) if *debruijn == binders => {
1017 if *index >= idx { 1017 if *index >= idx {
1018 // type variable default referring to parameter coming 1018 // type variable default referring to parameter coming
1019 // after it. This is forbidden (FIXME: report 1019 // after it. This is forbidden (FIXME: report
1020 // diagnostic) 1020 // diagnostic)
1021 *ty = TyKind::Error.intern(&Interner); 1021 TyKind::Error.intern(&Interner)
1022 } else {
1023 ty
1022 } 1024 }
1023 } 1025 }
1024 _ => {} 1026 _ => ty,
1025 }, 1027 },
1026 DebruijnIndex::INNERMOST, 1028 DebruijnIndex::INNERMOST,
1027 ); 1029 );