|
19 | 19 | use hir::def_id::{DefId, CrateNum}; |
20 | 20 | use middle::const_val::ByteArray; |
21 | 21 | use rustc_data_structures::fx::FxHashMap; |
22 | | -use rustc_serialize::{Decodable, Decoder, Encoder, Encodable}; |
| 22 | +use rustc_serialize::{Decodable, Decoder, Encoder, Encodable, opaque}; |
23 | 23 | use std::hash::Hash; |
24 | 24 | use std::intrinsics; |
25 | 25 | use ty::{self, Ty, TyCtxt}; |
@@ -53,6 +53,13 @@ pub trait TyEncoder: Encoder { |
53 | 53 | fn position(&self) -> usize; |
54 | 54 | } |
55 | 55 |
|
| 56 | +impl<'buf> TyEncoder for opaque::Encoder<'buf> { |
| 57 | + #[inline] |
| 58 | + fn position(&self) -> usize { |
| 59 | + self.position() |
| 60 | + } |
| 61 | +} |
| 62 | + |
56 | 63 | /// Encode the given value or a previously cached shorthand. |
57 | 64 | pub fn encode_with_shorthand<E, T, M>(encoder: &mut E, |
58 | 65 | value: &T, |
@@ -113,6 +120,8 @@ pub trait TyDecoder<'a, 'tcx: 'a>: Decoder { |
113 | 120 |
|
114 | 121 | fn peek_byte(&self) -> u8; |
115 | 122 |
|
| 123 | + fn position(&self) -> usize; |
| 124 | + |
116 | 125 | fn cached_ty_for_shorthand<F>(&mut self, |
117 | 126 | shorthand: usize, |
118 | 127 | or_insert_with: F) |
@@ -142,7 +151,6 @@ pub fn decode_ty<'a, 'tcx, D>(decoder: &mut D) -> Result<Ty<'tcx>, D::Error> |
142 | 151 | 'tcx: 'a, |
143 | 152 | { |
144 | 153 | // Handle shorthands first, if we have an usize > 0x80. |
145 | | - // if self.opaque.data[self.opaque.position()] & 0x80 != 0 { |
146 | 154 | if decoder.positioned_at_shorthand() { |
147 | 155 | let pos = decoder.read_usize()?; |
148 | 156 | assert!(pos >= SHORTHAND_OFFSET); |
|
0 commit comments