@@ -343,10 +343,15 @@ pub fn eval_const_expr(tcx: &TyCtxt, e: &Expr) -> ConstVal {
343
343
match eval_const_expr_partial ( tcx, e, ExprTypeChecked , None ) {
344
344
Ok ( r) => r,
345
345
// 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 ( ) ) ,
347
346
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
+ }
350
355
} ,
351
356
}
352
357
}
@@ -607,6 +612,7 @@ pub fn eval_const_expr_partial<'tcx>(tcx: &TyCtxt<'tcx>,
607
612
const_val => signal ! ( e, NotOn ( const_val) ) ,
608
613
}
609
614
}
615
+ hir:: ExprUnary ( hir:: UnDeref , _) => signal ! ( e, UnimplementedConstVal ( "deref operation" ) ) ,
610
616
hir:: ExprBinary ( op, ref a, ref b) => {
611
617
let b_ty = match op. node {
612
618
hir:: BiShl | hir:: BiShr => ty_hint. erase_hint ( ) ,
@@ -745,7 +751,7 @@ pub fn eval_const_expr_partial<'tcx>(tcx: &TyCtxt<'tcx>,
745
751
if let Some ( const_expr) = lookup_variant_by_id ( tcx, enum_def, variant_def) {
746
752
eval_const_expr_partial ( tcx, const_expr, ty_hint, None ) ?
747
753
} else {
748
- signal ! ( e, NonConstPath ) ;
754
+ signal ! ( e, UnimplementedConstVal ( "enum variants" ) ) ;
749
755
}
750
756
}
751
757
Def :: Struct ( ..) => {
@@ -768,6 +774,7 @@ pub fn eval_const_expr_partial<'tcx>(tcx: &TyCtxt<'tcx>,
768
774
let callee_val = eval_const_expr_partial ( tcx, callee, sub_ty_hint, fn_args) ?;
769
775
let did = match callee_val {
770
776
Function ( did) => did,
777
+ Struct ( _) => signal ! ( e, UnimplementedConstVal ( "tuple struct constructors" ) ) ,
771
778
callee => signal ! ( e, CallOn ( callee) ) ,
772
779
} ;
773
780
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>,
798
805
hir:: ExprBlock ( ref block) => {
799
806
match block. expr {
800
807
Some ( ref expr) => eval_const_expr_partial ( tcx, & expr, ty_hint, fn_args) ?,
801
- None => bug ! ( ) ,
808
+ None => signal ! ( e , UnimplementedConstVal ( "empty block" ) ) ,
802
809
}
803
810
}
804
811
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>,
840
847
} ,
841
848
842
849
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" ) ) ,
844
852
_ => signal ! ( e, IndexedNonVec ) ,
845
853
}
846
854
}
@@ -894,6 +902,7 @@ pub fn eval_const_expr_partial<'tcx>(tcx: &TyCtxt<'tcx>,
894
902
signal ! ( base, ExpectedConstStruct ) ;
895
903
}
896
904
}
905
+ hir:: ExprAddrOf ( ..) => signal ! ( e, UnimplementedConstVal ( "address operator" ) ) ,
897
906
_ => signal ! ( e, MiscCatchAll )
898
907
} ;
899
908
@@ -1073,6 +1082,7 @@ fn cast_const_int<'tcx>(tcx: &TyCtxt<'tcx>, val: ConstInt, ty: ty::Ty) -> CastRe
1073
1082
Ok ( Float ( val as f64 ) )
1074
1083
} ,
1075
1084
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" ) ) ,
1076
1086
_ => Err ( CannotCast ) ,
1077
1087
}
1078
1088
}
@@ -1094,6 +1104,7 @@ fn cast_const<'tcx>(tcx: &TyCtxt<'tcx>, val: ConstVal, ty: ty::Ty) -> CastResult
1094
1104
Bool ( b) => cast_const_int ( tcx, Infer ( b as u64 ) , ty) ,
1095
1105
Float ( f) => cast_const_float ( tcx, f, ty) ,
1096
1106
Char ( c) => cast_const_int ( tcx, Infer ( c as u64 ) , ty) ,
1107
+ Function ( _) => Err ( UnimplementedConstVal ( "casting fn pointers" ) ) ,
1097
1108
_ => Err ( CannotCast ) ,
1098
1109
}
1099
1110
}
0 commit comments