Skip to content

Commit 924ea05

Browse files
committed
Implement TypeVisitable and TypeFoldable for Spanned
The traits are already implemented for Span, so it makes sense to also have them for Spanned (upcoming commits will make use of this).
1 parent 1ead476 commit 924ea05

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

compiler/rustc_middle/src/ty/structural_impls.rs

+25
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use crate::ty::print::{with_no_trimmed_paths, FmtPrinter, Printer};
99
use crate::ty::visit::{TypeSuperVisitable, TypeVisitable, TypeVisitor};
1010
use crate::ty::{self, AliasTy, InferConst, Lift, Term, TermKind, Ty, TyCtxt};
1111
use rustc_hir::def::Namespace;
12+
use rustc_span::source_map::Spanned;
1213
use rustc_target::abi::TyAndLayout;
1314
use rustc_type_ir::{ConstKind, DebugWithInfcx, InferCtxtLike, WithInfcx};
1415

@@ -819,3 +820,27 @@ impl<'tcx> TypeVisitable<TyCtxt<'tcx>> for TyAndLayout<'tcx, Ty<'tcx>> {
819820
visitor.visit_ty(self.ty)
820821
}
821822
}
823+
824+
impl<'tcx, T: TypeVisitable<TyCtxt<'tcx>> + Debug + Clone> TypeVisitable<TyCtxt<'tcx>>
825+
for Spanned<T>
826+
{
827+
fn visit_with<V: TypeVisitor<TyCtxt<'tcx>>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
828+
self.node.visit_with(visitor)?;
829+
self.span.visit_with(visitor)?;
830+
ControlFlow::Continue(())
831+
}
832+
}
833+
834+
impl<'tcx, T: TypeFoldable<TyCtxt<'tcx>> + Debug + Clone> TypeFoldable<TyCtxt<'tcx>>
835+
for Spanned<T>
836+
{
837+
fn try_fold_with<F: FallibleTypeFolder<TyCtxt<'tcx>>>(
838+
self,
839+
folder: &mut F,
840+
) -> Result<Self, F::Error> {
841+
Ok(Spanned {
842+
node: self.node.try_fold_with(folder)?,
843+
span: self.span.try_fold_with(folder)?,
844+
})
845+
}
846+
}

0 commit comments

Comments
 (0)