]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_middle/src/mir/type_foldable.rs
Merge all `TypeVisitable for &List<T>` impls into one generic one
[rust.git] / compiler / rustc_middle / src / mir / type_foldable.rs
1 //! `TypeFoldable` implementations for MIR types
2
3 use rustc_ast::InlineAsmTemplatePiece;
4
5 use super::*;
6 use crate::ty;
7
8 TrivialTypeTraversalAndLiftImpls! {
9     BlockTailInfo,
10     MirPhase,
11     SourceInfo,
12     FakeReadCause,
13     RetagKind,
14     SourceScope,
15     SourceScopeLocalData,
16     UserTypeAnnotationIndex,
17     BorrowKind,
18     CastKind,
19     BinOp,
20     NullOp,
21     UnOp,
22     hir::Movability,
23     BasicBlock,
24     SwitchTargets,
25     GeneratorKind,
26     GeneratorSavedLocal,
27 }
28
29 impl<'tcx> TypeFoldable<'tcx> for &'tcx [InlineAsmTemplatePiece] {
30     fn try_fold_with<F: FallibleTypeFolder<'tcx>>(self, _folder: &mut F) -> Result<Self, F::Error> {
31         Ok(self)
32     }
33 }
34
35 impl<'tcx> TypeFoldable<'tcx> for &'tcx [Span] {
36     fn try_fold_with<F: FallibleTypeFolder<'tcx>>(self, _folder: &mut F) -> Result<Self, F::Error> {
37         Ok(self)
38     }
39 }
40
41 impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List<PlaceElem<'tcx>> {
42     fn try_fold_with<F: FallibleTypeFolder<'tcx>>(self, folder: &mut F) -> Result<Self, F::Error> {
43         ty::util::fold_list(self, folder, |tcx, v| tcx.intern_place_elems(v))
44     }
45 }
46
47 impl<'tcx, R: Idx, C: Idx> TypeFoldable<'tcx> for BitMatrix<R, C> {
48     fn try_fold_with<F: FallibleTypeFolder<'tcx>>(self, _: &mut F) -> Result<Self, F::Error> {
49         Ok(self)
50     }
51 }
52
53 impl<'tcx> TypeFoldable<'tcx> for ConstantKind<'tcx> {
54     #[inline(always)]
55     fn try_fold_with<F: FallibleTypeFolder<'tcx>>(self, folder: &mut F) -> Result<Self, F::Error> {
56         folder.try_fold_mir_const(self)
57     }
58 }
59
60 impl<'tcx> TypeSuperFoldable<'tcx> for ConstantKind<'tcx> {
61     fn try_super_fold_with<F: FallibleTypeFolder<'tcx>>(
62         self,
63         folder: &mut F,
64     ) -> Result<Self, F::Error> {
65         match self {
66             ConstantKind::Ty(c) => Ok(ConstantKind::Ty(c.try_fold_with(folder)?)),
67             ConstantKind::Val(v, t) => Ok(ConstantKind::Val(v, t.try_fold_with(folder)?)),
68         }
69     }
70 }