From 18ab705073faed3c01aa2f66a9d99d26d047c7bc Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Mon, 19 Sep 2022 14:00:34 +0000 Subject: [PATCH] Actually visit/fold the types inside CanonicalVarInfos --- compiler/rustc_middle/src/infer/canonical.rs | 23 ++++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/compiler/rustc_middle/src/infer/canonical.rs b/compiler/rustc_middle/src/infer/canonical.rs index 4bad0950451..e46cf48142f 100644 --- a/compiler/rustc_middle/src/infer/canonical.rs +++ b/compiler/rustc_middle/src/infer/canonical.rs @@ -29,7 +29,7 @@ use rustc_macros::HashStable; use smallvec::SmallVec; use std::iter; -use std::ops::Index; +use std::ops::{ControlFlow, Index}; /// A "canonicalized" type `V` is one where all free inference /// variables have been rewritten to "canonical vars". These are @@ -44,6 +44,21 @@ pub struct Canonical<'tcx, V> { pub type CanonicalVarInfos<'tcx> = &'tcx List>; +impl<'tcx> ty::TypeFoldable<'tcx> for CanonicalVarInfos<'tcx> { + fn try_fold_with>( + self, + folder: &mut F, + ) -> Result { + ty::util::fold_list(self, folder, |tcx, v| tcx.intern_canonical_var_infos(v)) + } +} + +impl<'tcx> ty::TypeVisitable<'tcx> for CanonicalVarInfos<'tcx> { + fn visit_with>(&self, visitor: &mut V) -> ControlFlow { + self.iter().try_for_each(|t| t.visit_with(visitor)) + } +} + /// A set of values corresponding to the canonical variables from some /// `Canonical`. You can give these values to /// `canonical_value.substitute` to substitute them into the canonical @@ -305,12 +320,6 @@ pub fn unchecked_map(self, map_op: impl FnOnce(V) -> W) -> Canonical<'tcx, W> } } -TrivialTypeTraversalImpls! { - for <'tcx> { - crate::infer::canonical::CanonicalVarInfos<'tcx>, - } -} - impl<'tcx> CanonicalVarValues<'tcx> { #[inline] pub fn len(&self) -> usize {