99// except according to those terms.
1010
1111use self :: ConstVal :: * ;
12+ use self :: ConstAggregate :: * ;
1213pub use rustc_const_math:: ConstInt ;
1314
1415use hir;
@@ -22,30 +23,55 @@ use rustc_const_math::*;
2223
2324use graphviz:: IntoCow ;
2425use errors:: DiagnosticBuilder ;
26+ use serialize:: { self , Encodable , Encoder , Decodable , Decoder } ;
2527use syntax:: symbol:: InternedString ;
2628use syntax:: ast;
2729use syntax_pos:: Span ;
2830
2931use std:: borrow:: Cow ;
30- use std:: collections:: BTreeMap ;
31- use std:: rc:: Rc ;
3232
33- pub type EvalResult < ' tcx > = Result < ConstVal < ' tcx > , ConstEvalErr < ' tcx > > ;
33+ pub type EvalResult < ' tcx > = Result < & ' tcx ConstVal < ' tcx > , ConstEvalErr < ' tcx > > ;
3434
35- #[ derive( Clone , Debug , Hash , RustcEncodable , RustcDecodable , Eq , PartialEq ) ]
35+ #[ derive( Copy , Clone , Debug , Hash , RustcEncodable , RustcDecodable , Eq , PartialEq ) ]
3636pub enum ConstVal < ' tcx > {
3737 Float ( ConstFloat ) ,
3838 Integral ( ConstInt ) ,
3939 Str ( InternedString ) ,
40- ByteStr ( Rc < Vec < u8 > > ) ,
40+ ByteStr ( ByteArray < ' tcx > ) ,
4141 Bool ( bool ) ,
4242 Char ( char ) ,
4343 Variant ( DefId ) ,
4444 Function ( DefId , & ' tcx Substs < ' tcx > ) ,
45- Struct ( BTreeMap < ast:: Name , ConstVal < ' tcx > > ) ,
46- Tuple ( Vec < ConstVal < ' tcx > > ) ,
47- Array ( Vec < ConstVal < ' tcx > > ) ,
48- Repeat ( Box < ConstVal < ' tcx > > , u64 ) ,
45+ Aggregate ( ConstAggregate < ' tcx > ) ,
46+ }
47+
48+ impl < ' tcx > serialize:: UseSpecializedDecodable for & ' tcx ConstVal < ' tcx > { }
49+
50+ #[ derive( Copy , Clone , Debug , Hash , RustcEncodable , Eq , PartialEq ) ]
51+ pub struct ByteArray < ' tcx > {
52+ pub data : & ' tcx [ u8 ] ,
53+ }
54+
55+ impl < ' tcx > serialize:: UseSpecializedDecodable for ByteArray < ' tcx > { }
56+
57+ #[ derive( Copy , Clone , Debug , Hash , Eq , PartialEq ) ]
58+ pub enum ConstAggregate < ' tcx > {
59+ Struct ( & ' tcx [ ( ast:: Name , & ' tcx ConstVal < ' tcx > ) ] ) ,
60+ Tuple ( & ' tcx [ & ' tcx ConstVal < ' tcx > ] ) ,
61+ Array ( & ' tcx [ & ' tcx ConstVal < ' tcx > ] ) ,
62+ Repeat ( & ' tcx ConstVal < ' tcx > , u64 ) ,
63+ }
64+
65+ impl < ' tcx > Encodable for ConstAggregate < ' tcx > {
66+ fn encode < S : Encoder > ( & self , _: & mut S ) -> Result < ( ) , S :: Error > {
67+ bug ! ( "should never encode ConstAggregate::{:?}" , self )
68+ }
69+ }
70+
71+ impl < ' tcx > Decodable for ConstAggregate < ' tcx > {
72+ fn decode < D : Decoder > ( _: & mut D ) -> Result < Self , D :: Error > {
73+ bug ! ( "should never decode ConstAggregate" )
74+ }
4975}
5076
5177impl < ' tcx > ConstVal < ' tcx > {
@@ -58,11 +84,11 @@ impl<'tcx> ConstVal<'tcx> {
5884 Bool ( _) => "boolean" ,
5985 Char ( ..) => "char" ,
6086 Variant ( _) => "enum variant" ,
61- Struct ( _) => "struct" ,
62- Tuple ( _) => "tuple" ,
87+ Aggregate ( Struct ( _) ) => "struct" ,
88+ Aggregate ( Tuple ( _) ) => "tuple" ,
6389 Function ( ..) => "function definition" ,
64- Array ( ..) => "array" ,
65- Repeat ( ..) => "repeat" ,
90+ Aggregate ( Array ( ..) ) => "array" ,
91+ Aggregate ( Repeat ( ..) ) => "repeat" ,
6692 }
6793 }
6894
@@ -233,7 +259,7 @@ pub fn eval_length(tcx: TyCtxt,
233259 let param_env = ty:: ParamEnv :: empty ( Reveal :: UserFacing ) ;
234260 let substs = Substs :: identity_for_item ( tcx. global_tcx ( ) , count_def_id) ;
235261 match tcx. at ( count_expr. span ) . const_eval ( param_env. and ( ( count_def_id, substs) ) ) {
236- Ok ( Integral ( Usize ( count) ) ) => {
262+ Ok ( & Integral ( Usize ( count) ) ) => {
237263 let val = count. as_u64 ( tcx. sess . target . uint_type ) ;
238264 assert_eq ! ( val as usize as u64 , val) ;
239265 Ok ( val as usize )
0 commit comments