]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_middle/src/mir/type_foldable.rs
8e18cad442ed9f46a3c6cf6cdcbcaf2a065d025f
[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::mir;
7 use crate::ty;
8
9 TrivialTypeTraversalAndLiftImpls! {
10     BlockTailInfo,
11     MirPhase,
12     SourceInfo,
13     FakeReadCause,
14     RetagKind,
15     SourceScope,
16     SourceScopeLocalData,
17     UserTypeAnnotationIndex,
18     BorrowKind,
19     CastKind,
20     BinOp,
21     NullOp,
22     UnOp,
23     hir::Movability,
24     BasicBlock,
25     SwitchTargets,
26     GeneratorKind,
27     GeneratorSavedLocal,
28 }
29
30 impl<'tcx> TypeFoldable<'tcx> for &'tcx [InlineAsmTemplatePiece] {
31     fn try_fold_with<F: FallibleTypeFolder<'tcx>>(self, _folder: &mut F) -> Result<Self, F::Error> {
32         Ok(self)
33     }
34 }
35
36 impl<'tcx> TypeFoldable<'tcx> for &'tcx [Span] {
37     fn try_fold_with<F: FallibleTypeFolder<'tcx>>(self, _folder: &mut F) -> Result<Self, F::Error> {
38         Ok(self)
39     }
40 }
41
42 impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List<PlaceElem<'tcx>> {
43     fn try_fold_with<F: FallibleTypeFolder<'tcx>>(self, folder: &mut F) -> Result<Self, F::Error> {
44         ty::util::fold_list(self, folder, |tcx, v| tcx.intern_place_elems(v))
45     }
46 }
47
48 impl<'tcx, R: Idx, C: Idx> TypeFoldable<'tcx> for BitMatrix<R, C> {
49     fn try_fold_with<F: FallibleTypeFolder<'tcx>>(self, _: &mut F) -> Result<Self, F::Error> {
50         Ok(self)
51     }
52 }
53
54 impl<'tcx> TypeFoldable<'tcx> for mir::UnevaluatedConst<'tcx> {
55     fn try_fold_with<F: FallibleTypeFolder<'tcx>>(self, folder: &mut F) -> Result<Self, F::Error> {
56         folder.try_fold_mir_unevaluated(self)
57     }
58 }
59
60 impl<'tcx> TypeSuperFoldable<'tcx> for mir::UnevaluatedConst<'tcx> {
61     fn try_super_fold_with<F: FallibleTypeFolder<'tcx>>(
62         self,
63         folder: &mut F,
64     ) -> Result<Self, F::Error> {
65         Ok(mir::UnevaluatedConst {
66             def: self.def,
67             substs: self.substs.try_fold_with(folder)?,
68             promoted: self.promoted,
69         })
70     }
71 }
72
73 impl<'tcx> TypeFoldable<'tcx> for ConstantKind<'tcx> {
74     #[inline(always)]
75     fn try_fold_with<F: FallibleTypeFolder<'tcx>>(self, folder: &mut F) -> Result<Self, F::Error> {
76         folder.try_fold_mir_const(self)
77     }
78 }
79
80 impl<'tcx> TypeSuperFoldable<'tcx> for ConstantKind<'tcx> {
81     fn try_super_fold_with<F: FallibleTypeFolder<'tcx>>(
82         self,
83         folder: &mut F,
84     ) -> Result<Self, F::Error> {
85         match self {
86             ConstantKind::Ty(c) => Ok(ConstantKind::Ty(c.try_fold_with(folder)?)),
87             ConstantKind::Val(v, t) => Ok(ConstantKind::Val(v, t.try_fold_with(folder)?)),
88             ConstantKind::Unevaluated(uv, t) => {
89                 Ok(ConstantKind::Unevaluated(uv.try_fold_with(folder)?, t.try_fold_with(folder)?))
90             }
91         }
92     }
93 }