@@ -208,7 +208,11 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
208208 self . memory . write_bool ( ptr, b) ?;
209209 Ok ( ptr)
210210 }
211- Char ( _c) => unimplemented ! ( ) ,
211+ Char ( c) => {
212+ let ptr = self . memory . allocate ( 4 ) ;
213+ self . memory . write_uint ( ptr, c as u64 , 4 ) ?;
214+ Ok ( ptr)
215+ } ,
212216 Struct ( _node_id) => unimplemented ! ( ) ,
213217 Tuple ( _node_id) => unimplemented ! ( ) ,
214218 Function ( _def_id) => unimplemented ! ( ) ,
@@ -402,11 +406,17 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
402406
403407 SwitchInt { ref discr, ref values, ref targets, .. } => {
404408 let discr_ptr = self . eval_lvalue ( discr) ?. to_ptr ( ) ;
409+ let discr_ty = self . lvalue_ty ( discr) ;
405410 let discr_size = self
406- . type_layout ( self . lvalue_ty ( discr ) )
411+ . type_layout ( discr_ty )
407412 . size ( & self . tcx . data_layout )
408413 . bytes ( ) as usize ;
409414 let discr_val = self . memory . read_uint ( discr_ptr, discr_size) ?;
415+ if let ty:: TyChar = discr_ty. sty {
416+ if :: std:: char:: from_u32 ( discr_val as u32 ) . is_none ( ) {
417+ return Err ( EvalError :: InvalidChar ( discr_val as u32 ) ) ;
418+ }
419+ }
410420
411421 // Branch to the `otherwise` case by default, if no match is found.
412422 let mut target_block = targets[ targets. len ( ) - 1 ] ;
@@ -1371,6 +1381,13 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
13711381 use syntax:: ast:: { IntTy , UintTy } ;
13721382 let val = match ( self . memory . pointer_size , & ty. sty ) {
13731383 ( _, & ty:: TyBool ) => PrimVal :: Bool ( self . memory . read_bool ( ptr) ?) ,
1384+ ( _, & ty:: TyChar ) => {
1385+ let c = self . memory . read_uint ( ptr, 4 ) ? as u32 ;
1386+ match :: std:: char:: from_u32 ( c) {
1387+ Some ( ch) => PrimVal :: Char ( ch) ,
1388+ None => return Err ( EvalError :: InvalidChar ( c) ) ,
1389+ }
1390+ }
13741391 ( _, & ty:: TyInt ( IntTy :: I8 ) ) => PrimVal :: I8 ( self . memory . read_int ( ptr, 1 ) ? as i8 ) ,
13751392 ( 2 , & ty:: TyInt ( IntTy :: Is ) ) |
13761393 ( _, & ty:: TyInt ( IntTy :: I16 ) ) => PrimVal :: I16 ( self . memory . read_int ( ptr, 2 ) ? as i16 ) ,
0 commit comments