@@ -343,10 +343,15 @@ pub fn eval_const_expr(tcx: &TyCtxt, e: &Expr) -> ConstVal {
343343 match eval_const_expr_partial ( tcx, e, ExprTypeChecked , None ) {
344344 Ok ( r) => r,
345345 // non-const path still needs to be a fatal error, because enums are funky
346- Err ( ref s) if s. kind == NonConstPath => tcx. sess . span_fatal ( s. span , & s. description ( ) ) ,
347346 Err ( s) => {
348- tcx. sess . span_err ( s. span , & s. description ( ) ) ;
349- Dummy
347+ match s. kind {
348+ NonConstPath |
349+ UnimplementedConstVal ( _) => tcx. sess . span_fatal ( s. span , & s. description ( ) ) ,
350+ _ => {
351+ tcx. sess . span_err ( s. span , & s. description ( ) ) ;
352+ Dummy
353+ }
354+ }
350355 } ,
351356 }
352357}
@@ -607,6 +612,7 @@ pub fn eval_const_expr_partial<'tcx>(tcx: &TyCtxt<'tcx>,
607612 const_val => signal ! ( e, NotOn ( const_val) ) ,
608613 }
609614 }
615+ hir:: ExprUnary ( hir:: UnDeref , _) => signal ! ( e, UnimplementedConstVal ( "deref operation" ) ) ,
610616 hir:: ExprBinary ( op, ref a, ref b) => {
611617 let b_ty = match op. node {
612618 hir:: BiShl | hir:: BiShr => ty_hint. erase_hint ( ) ,
@@ -745,7 +751,7 @@ pub fn eval_const_expr_partial<'tcx>(tcx: &TyCtxt<'tcx>,
745751 if let Some ( const_expr) = lookup_variant_by_id ( tcx, enum_def, variant_def) {
746752 eval_const_expr_partial ( tcx, const_expr, ty_hint, None ) ?
747753 } else {
748- signal ! ( e, NonConstPath ) ;
754+ signal ! ( e, UnimplementedConstVal ( "enum variants" ) ) ;
749755 }
750756 }
751757 Def :: Struct ( ..) => {
@@ -768,6 +774,7 @@ pub fn eval_const_expr_partial<'tcx>(tcx: &TyCtxt<'tcx>,
768774 let callee_val = eval_const_expr_partial ( tcx, callee, sub_ty_hint, fn_args) ?;
769775 let did = match callee_val {
770776 Function ( did) => did,
777+ Struct ( _) => signal ! ( e, UnimplementedConstVal ( "tuple struct constructors" ) ) ,
771778 callee => signal ! ( e, CallOn ( callee) ) ,
772779 } ;
773780 let ( decl, result) = if let Some ( fn_like) = lookup_const_fn_by_id ( tcx, did) {
@@ -798,7 +805,7 @@ pub fn eval_const_expr_partial<'tcx>(tcx: &TyCtxt<'tcx>,
798805 hir:: ExprBlock ( ref block) => {
799806 match block. expr {
800807 Some ( ref expr) => eval_const_expr_partial ( tcx, & expr, ty_hint, fn_args) ?,
801- None => bug ! ( ) ,
808+ None => signal ! ( e , UnimplementedConstVal ( "empty block" ) ) ,
802809 }
803810 }
804811 hir:: ExprType ( ref e, _) => eval_const_expr_partial ( tcx, & e, ty_hint, fn_args) ?,
@@ -840,7 +847,8 @@ pub fn eval_const_expr_partial<'tcx>(tcx: &TyCtxt<'tcx>,
840847 } ,
841848
842849 Str ( ref s) if idx as usize >= s. len ( ) => signal ! ( e, IndexOutOfBounds ) ,
843- Str ( _) => bug ! ( "unimplemented" ) , // FIXME: return a const char
850+ // FIXME: return a const char
851+ Str ( _) => signal ! ( e, UnimplementedConstVal ( "indexing into str" ) ) ,
844852 _ => signal ! ( e, IndexedNonVec ) ,
845853 }
846854 }
@@ -894,6 +902,7 @@ pub fn eval_const_expr_partial<'tcx>(tcx: &TyCtxt<'tcx>,
894902 signal ! ( base, ExpectedConstStruct ) ;
895903 }
896904 }
905+ hir:: ExprAddrOf ( ..) => signal ! ( e, UnimplementedConstVal ( "address operator" ) ) ,
897906 _ => signal ! ( e, MiscCatchAll )
898907 } ;
899908
@@ -1073,6 +1082,7 @@ fn cast_const_int<'tcx>(tcx: &TyCtxt<'tcx>, val: ConstInt, ty: ty::Ty) -> CastRe
10731082 Ok ( Float ( val as f64 ) )
10741083 } ,
10751084 ty:: TyFloat ( ast:: FloatTy :: F32 ) => Ok ( Float ( val. to_u64 ( ) . unwrap ( ) as f32 as f64 ) ) ,
1085+ ty:: TyRawPtr ( _) => Err ( ErrKind :: UnimplementedConstVal ( "casting an address to a raw ptr" ) ) ,
10761086 _ => Err ( CannotCast ) ,
10771087 }
10781088}
@@ -1094,6 +1104,7 @@ fn cast_const<'tcx>(tcx: &TyCtxt<'tcx>, val: ConstVal, ty: ty::Ty) -> CastResult
10941104 Bool ( b) => cast_const_int ( tcx, Infer ( b as u64 ) , ty) ,
10951105 Float ( f) => cast_const_float ( tcx, f, ty) ,
10961106 Char ( c) => cast_const_int ( tcx, Infer ( c as u64 ) , ty) ,
1107+ Function ( _) => Err ( UnimplementedConstVal ( "casting fn pointers" ) ) ,
10971108 _ => Err ( CannotCast ) ,
10981109 }
10991110}
0 commit comments