@@ -40,31 +40,36 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
40
40
& mut self ,
41
41
constant : & mir:: Constant < ' tcx > ,
42
42
) -> Result < ConstValue < ' tcx > , ErrorHandled > {
43
- match constant. literal . val {
43
+ let const_ = match constant. literal . val {
44
44
ty:: ConstKind :: Unevaluated ( def_id, substs, promoted) => {
45
45
let substs = self . monomorphize ( & substs) ;
46
- self . cx
47
- . tcx ( )
48
- . const_eval_resolve ( ty:: ParamEnv :: reveal_all ( ) , def_id, substs, promoted, None )
49
- . map_err ( |err| {
50
- if promoted. is_none ( ) {
51
- self . cx
52
- . tcx ( )
53
- . sess
54
- . span_err ( constant. span , "erroneous constant encountered" ) ;
55
- }
56
- err
57
- } )
46
+ ty:: ConstKind :: Unevaluated ( def_id, substs, promoted)
58
47
}
48
+ ty:: ConstKind :: Value ( value) => ty:: ConstKind :: Value ( value) ,
49
+ ty:: ConstKind :: Param ( _) => self . monomorphize ( & constant. literal ) . val ,
50
+ _ => span_bug ! ( constant. span, "encountered bad Const in codegen: {:?}" , constant) ,
51
+ } ;
52
+
53
+ match const_ {
54
+ ty:: ConstKind :: Unevaluated ( def_id, substs, promoted) => self
55
+ . cx
56
+ . tcx ( )
57
+ . const_eval_resolve ( ty:: ParamEnv :: reveal_all ( ) , def_id, substs, promoted, None )
58
+ . map_err ( |err| {
59
+ if promoted. is_none ( ) {
60
+ self . cx
61
+ . tcx ( )
62
+ . sess
63
+ . span_err ( constant. span , "erroneous constant encountered" ) ;
64
+ }
65
+ err
66
+ } ) ,
59
67
ty:: ConstKind :: Value ( value) => Ok ( value) ,
60
- _ => {
61
- let const_ = self . monomorphize ( & constant. literal ) ;
62
- if let ty:: ConstKind :: Value ( value) = const_. val {
63
- Ok ( value)
64
- } else {
65
- span_bug ! ( constant. span, "encountered bad ConstKind in codegen: {:?}" , const_) ;
66
- }
67
- }
68
+ _ => span_bug ! (
69
+ constant. span,
70
+ "encountered bad ConstKind after monomorphizing: {:?}" ,
71
+ const_
72
+ ) ,
68
73
}
69
74
}
70
75
0 commit comments