From caee3b6c2d9a7dbcf678cc06d0c1832a4bf19be4 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Wed, 7 Apr 2021 21:26:37 +0200 Subject: Replace some `fold` calls --- crates/hir_ty/src/lower.rs | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) (limited to 'crates/hir_ty/src/lower.rs') diff --git a/crates/hir_ty/src/lower.rs b/crates/hir_ty/src/lower.rs index b45e811fa..109157a5e 100644 --- a/crates/hir_ty/src/lower.rs +++ b/crates/hir_ty/src/lower.rs @@ -1016,22 +1016,16 @@ 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 = 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) - TyKind::Error.intern(&Interner) - } else { - ty - } - } - _ => ty, - }, - DebruijnIndex::INNERMOST, - ); + ty = crate::fold_free_vars(ty, |bound, binders| { + if bound.index >= idx && bound.debruijn == DebruijnIndex::INNERMOST { + // type variable default referring to parameter coming + // after it. This is forbidden (FIXME: report + // diagnostic) + TyKind::Error.intern(&Interner) + } else { + bound.shifted_in_from(binders).to_ty(&Interner) + } + }); crate::make_only_type_binders(idx, ty) }) -- cgit v1.2.3