mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-21 04:03:11 +00:00
Get rid of some walk_mut uses
This commit is contained in:
parent
30a339e038
commit
e28f0c98ba
@ -108,19 +108,22 @@ impl<'a, 'b> Canonicalizer<'a, 'b> {
|
||||
}
|
||||
|
||||
impl<T> Canonicalized<T> {
|
||||
pub(super) fn decanonicalize_ty(&self, mut ty: Ty) -> Ty {
|
||||
ty.walk_mut_binders(
|
||||
pub(super) fn decanonicalize_ty(&self, ty: Ty) -> Ty {
|
||||
ty.fold_binders(
|
||||
&mut |ty, binders| {
|
||||
if let &mut TyKind::BoundVar(bound) = ty.interned_mut() {
|
||||
if let TyKind::BoundVar(bound) = ty.kind(&Interner) {
|
||||
if bound.debruijn >= binders {
|
||||
let (v, k) = self.free_vars[bound.index];
|
||||
*ty = TyKind::InferenceVar(v, k).intern(&Interner);
|
||||
TyKind::InferenceVar(v, k).intern(&Interner)
|
||||
} else {
|
||||
ty
|
||||
}
|
||||
} else {
|
||||
ty
|
||||
}
|
||||
},
|
||||
DebruijnIndex::INNERMOST,
|
||||
);
|
||||
ty
|
||||
)
|
||||
}
|
||||
|
||||
pub(super) fn apply_solution(
|
||||
|
@ -1011,17 +1011,19 @@ pub(crate) fn generic_defaults_query(
|
||||
p.default.as_ref().map_or(TyKind::Error.intern(&Interner), |t| ctx.lower_ty(t));
|
||||
|
||||
// Each default can only refer to previous parameters.
|
||||
ty.walk_mut_binders(
|
||||
&mut |ty, binders| match ty.interned_mut() {
|
||||
ty = ty.fold_binders(
|
||||
&mut |ty, binders| match ty.kind(&Interner) {
|
||||
TyKind::BoundVar(BoundVar { debruijn, index }) if *debruijn == binders => {
|
||||
if *index >= idx {
|
||||
// type variable default referring to parameter coming
|
||||
// after it. This is forbidden (FIXME: report
|
||||
// diagnostic)
|
||||
*ty = TyKind::Error.intern(&Interner);
|
||||
TyKind::Error.intern(&Interner)
|
||||
} else {
|
||||
ty
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
_ => ty,
|
||||
},
|
||||
DebruijnIndex::INNERMOST,
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user