@@ -3,6 +3,7 @@ use crate::throw_ub;
3
3
use rustc_apfloat:: ieee:: { Double , Single } ;
4
4
use rustc_apfloat:: Float ;
5
5
use rustc_macros:: HashStable ;
6
+ use rustc_serialize:: { Decodable , Decoder , Encodable , Encoder } ;
6
7
use rustc_target:: abi:: { Size , TargetDataLayout } ;
7
8
use std:: convert:: { TryFrom , TryInto } ;
8
9
use std:: fmt;
@@ -115,7 +116,7 @@ impl std::fmt::Debug for ConstInt {
115
116
116
117
// FIXME: reuse in `super::int::ConstInt` and `Scalar::Bits`
117
118
/// The raw bytes of a simple value.
118
- #[ derive( Clone , Copy , Eq , PartialEq , Ord , PartialOrd , TyEncodable , TyDecodable , Hash ) ]
119
+ #[ derive( Clone , Copy , Eq , PartialEq , Ord , PartialOrd , Hash ) ]
119
120
#[ derive( HashStable ) ]
120
121
pub struct ScalarInt {
121
122
/// The first `size` bytes of `data` are the value.
@@ -127,6 +128,19 @@ pub struct ScalarInt {
127
128
size : u8 ,
128
129
}
129
130
131
+ impl < S : Encoder > Encodable < S > for ScalarInt {
132
+ fn encode ( & self , s : & mut S ) -> Result < ( ) , S :: Error > {
133
+ s. emit_u128 ( self . data ( ) ) ?;
134
+ s. emit_u8 ( self . size )
135
+ }
136
+ }
137
+
138
+ impl < D : Decoder > Decodable < D > for ScalarInt {
139
+ fn decode ( d : & mut D ) -> Result < ScalarInt , D :: Error > {
140
+ Ok ( ScalarInt { bytes : d. read_u128 ( ) ?. to_ne_bytes ( ) , size : d. read_u8 ( ) ? } )
141
+ }
142
+ }
143
+
130
144
impl ScalarInt {
131
145
pub const TRUE : ScalarInt = ScalarInt { bytes : 1_u128 . to_ne_bytes ( ) , size : 1 } ;
132
146
0 commit comments