|
11 | 11 | // Type substitutions.
|
12 | 12 |
|
13 | 13 | use hir::def_id::DefId;
|
14 |
| -use ty::{self, Lift, Slice, Region, Ty, TyCtxt}; |
| 14 | +use ty::{self, Lift, Slice, Ty, TyCtxt}; |
15 | 15 | use ty::fold::{TypeFoldable, TypeFolder, TypeVisitor};
|
16 | 16 |
|
17 | 17 | use serialize::{self, Encodable, Encoder, Decodable, Decoder};
|
@@ -39,7 +39,7 @@ const TAG_MASK: usize = 0b11;
|
39 | 39 | const TYPE_TAG: usize = 0b00;
|
40 | 40 | const REGION_TAG: usize = 0b01;
|
41 | 41 |
|
42 |
| -#[derive(Debug)] |
| 42 | +#[derive(Debug, RustcEncodable, RustcDecodable)] |
43 | 43 | pub enum UnpackedKind<'tcx> {
|
44 | 44 | Lifetime(ty::Region<'tcx>),
|
45 | 45 | Type(Ty<'tcx>),
|
@@ -142,34 +142,13 @@ impl<'tcx> TypeFoldable<'tcx> for Kind<'tcx> {
|
142 | 142 |
|
143 | 143 | impl<'tcx> Encodable for Kind<'tcx> {
|
144 | 144 | fn encode<E: Encoder>(&self, e: &mut E) -> Result<(), E::Error> {
|
145 |
| - e.emit_enum("Kind", |e| { |
146 |
| - match self.unpack() { |
147 |
| - UnpackedKind::Lifetime(lt) => { |
148 |
| - e.emit_enum_variant("Region", REGION_TAG, 1, |e| { |
149 |
| - e.emit_enum_variant_arg(0, |e| lt.encode(e)) |
150 |
| - }) |
151 |
| - } |
152 |
| - UnpackedKind::Type(ty) => { |
153 |
| - e.emit_enum_variant("Ty", TYPE_TAG, 1, |e| { |
154 |
| - e.emit_enum_variant_arg(0, |e| ty.encode(e)) |
155 |
| - }) |
156 |
| - } |
157 |
| - } |
158 |
| - }) |
| 145 | + self.unpack().encode(e) |
159 | 146 | }
|
160 | 147 | }
|
161 | 148 |
|
162 | 149 | impl<'tcx> Decodable for Kind<'tcx> {
|
163 | 150 | fn decode<D: Decoder>(d: &mut D) -> Result<Kind<'tcx>, D::Error> {
|
164 |
| - d.read_enum("Kind", |d| { |
165 |
| - d.read_enum_variant(&["Ty", "Region"], |d, tag| { |
166 |
| - match tag { |
167 |
| - TYPE_TAG => Ty::decode(d).map(Kind::from), |
168 |
| - REGION_TAG => Region::decode(d).map(Kind::from), |
169 |
| - _ => Err(d.error("invalid Kind tag")) |
170 |
| - } |
171 |
| - }) |
172 |
| - }) |
| 151 | + Ok(UnpackedKind::decode(d)?.pack()) |
173 | 152 | }
|
174 | 153 | }
|
175 | 154 |
|
|
0 commit comments