diff options
| author | Martin Nordholts <martin.nordholts@codetale.se> | 2024-01-12 08:22:05 +0100 |
|---|---|---|
| committer | Martin Nordholts <martin.nordholts@codetale.se> | 2024-01-15 19:07:11 +0100 |
| commit | 924ea05103da3bd25e6021535615ca7f8b9ec76d (patch) | |
| tree | 7e81d08d5b93c00f38a5b6867462d61668fddd52 /compiler | |
| parent | 1ead4761e9e2f056385768614c23ffa7acb6a19e (diff) | |
| download | rust-924ea05103da3bd25e6021535615ca7f8b9ec76d.tar.gz rust-924ea05103da3bd25e6021535615ca7f8b9ec76d.zip | |
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).
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_middle/src/ty/structural_impls.rs | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/compiler/rustc_middle/src/ty/structural_impls.rs b/compiler/rustc_middle/src/ty/structural_impls.rs index 7c869adbd83..11b579a1f85 100644 --- a/compiler/rustc_middle/src/ty/structural_impls.rs +++ b/compiler/rustc_middle/src/ty/structural_impls.rs @@ -9,6 +9,7 @@ use crate::ty::print::{with_no_trimmed_paths, FmtPrinter, Printer}; use crate::ty::visit::{TypeSuperVisitable, TypeVisitable, TypeVisitor}; use crate::ty::{self, AliasTy, InferConst, Lift, Term, TermKind, Ty, TyCtxt}; use rustc_hir::def::Namespace; +use rustc_span::source_map::Spanned; use rustc_target::abi::TyAndLayout; use rustc_type_ir::{ConstKind, DebugWithInfcx, InferCtxtLike, WithInfcx}; @@ -819,3 +820,27 @@ impl<'tcx> TypeVisitable<TyCtxt<'tcx>> for TyAndLayout<'tcx, Ty<'tcx>> { visitor.visit_ty(self.ty) } } + +impl<'tcx, T: TypeVisitable<TyCtxt<'tcx>> + Debug + Clone> TypeVisitable<TyCtxt<'tcx>> + for Spanned<T> +{ + fn visit_with<V: TypeVisitor<TyCtxt<'tcx>>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> { + self.node.visit_with(visitor)?; + self.span.visit_with(visitor)?; + ControlFlow::Continue(()) + } +} + +impl<'tcx, T: TypeFoldable<TyCtxt<'tcx>> + Debug + Clone> TypeFoldable<TyCtxt<'tcx>> + for Spanned<T> +{ + fn try_fold_with<F: FallibleTypeFolder<TyCtxt<'tcx>>>( + self, + folder: &mut F, + ) -> Result<Self, F::Error> { + Ok(Spanned { + node: self.node.try_fold_with(folder)?, + span: self.span.try_fold_with(folder)?, + }) + } +} |
