@@ -65,12 +65,12 @@ pub(crate) fn eval_promoted<'a, 'mir, 'tcx>(
65
65
fn mplace_to_const < ' tcx > (
66
66
ecx : & CompileTimeEvalContext < ' _ , ' _ , ' tcx > ,
67
67
mplace : MPlaceTy < ' tcx > ,
68
- ) -> EvalResult < ' tcx , ty:: Const < ' tcx > > {
68
+ ) -> ty:: Const < ' tcx > {
69
69
let MemPlace { ptr, align, meta } = * mplace;
70
70
// extract alloc-offset pair
71
71
assert ! ( meta. is_none( ) ) ;
72
- let ptr = ptr. to_ptr ( ) ? ;
73
- let alloc = ecx. memory . get ( ptr. alloc_id ) ? ;
72
+ let ptr = ptr. to_ptr ( ) . unwrap ( ) ;
73
+ let alloc = ecx. memory . get ( ptr. alloc_id ) . unwrap ( ) ;
74
74
assert ! ( alloc. align >= align) ;
75
75
assert ! ( alloc. bytes. len( ) as u64 - ptr. offset. bytes( ) >= mplace. layout. size. bytes( ) ) ;
76
76
let mut alloc = alloc. clone ( ) ;
@@ -79,16 +79,16 @@ fn mplace_to_const<'tcx>(
79
79
// interned this? I thought that is the entire point of that `FinishStatic` stuff?
80
80
let alloc = ecx. tcx . intern_const_alloc ( alloc) ;
81
81
let val = ConstValue :: ByRef ( ptr, alloc) ;
82
- Ok ( ty:: Const { val, ty : mplace. layout . ty } )
82
+ ty:: Const { val, ty : mplace. layout . ty }
83
83
}
84
84
85
85
fn op_to_const < ' tcx > (
86
86
ecx : & CompileTimeEvalContext < ' _ , ' _ , ' tcx > ,
87
87
op : OpTy < ' tcx > ,
88
- ) -> EvalResult < ' tcx , ty:: Const < ' tcx > > {
89
- // We do not normalize just any data. Only scalar layout and slices.
88
+ ) -> ty:: Const < ' tcx > {
89
+ // We do not normalize just any data. Only non-union scalars and slices.
90
90
let normalize = match op. layout . abi {
91
- layout:: Abi :: Scalar ( ..) => true ,
91
+ layout:: Abi :: Scalar ( ..) => op . layout . ty . ty_adt_def ( ) . map_or ( true , |adt| !adt . is_union ( ) ) ,
92
92
layout:: Abi :: ScalarPair ( ..) => op. layout . ty . is_slice ( ) ,
93
93
_ => false ,
94
94
} ;
@@ -100,11 +100,11 @@ fn op_to_const<'tcx>(
100
100
let val = match normalized_op {
101
101
Ok ( mplace) => return mplace_to_const ( ecx, mplace) ,
102
102
Err ( Immediate :: Scalar ( x) ) =>
103
- ConstValue :: Scalar ( x. not_undef ( ) ? ) ,
103
+ ConstValue :: Scalar ( x. not_undef ( ) . unwrap ( ) ) ,
104
104
Err ( Immediate :: ScalarPair ( a, b) ) =>
105
- ConstValue :: Slice ( a. not_undef ( ) ? , b. to_usize ( ecx) ? ) ,
105
+ ConstValue :: Slice ( a. not_undef ( ) . unwrap ( ) , b. to_usize ( ecx) . unwrap ( ) ) ,
106
106
} ;
107
- Ok ( ty:: Const { val, ty : op. layout . ty } )
107
+ ty:: Const { val, ty : op. layout . ty }
108
108
}
109
109
110
110
fn eval_body_and_ecx < ' a , ' mir , ' tcx > (
@@ -488,7 +488,7 @@ pub fn const_field<'a, 'tcx>(
488
488
let field = ecx. operand_field ( down, field. index ( ) as u64 ) . unwrap ( ) ;
489
489
// and finally move back to the const world, always normalizing because
490
490
// this is not called for statics.
491
- op_to_const ( & ecx, field) . unwrap ( )
491
+ op_to_const ( & ecx, field)
492
492
}
493
493
494
494
// this function uses `unwrap` copiously, because an already validated constant must have valid
@@ -534,9 +534,9 @@ fn validate_and_turn_into_const<'a, 'tcx>(
534
534
// Now that we validated, turn this into a proper constant.
535
535
let def_id = cid. instance . def . def_id ( ) ;
536
536
if tcx. is_static ( def_id) . is_some ( ) || cid. promoted . is_some ( ) {
537
- mplace_to_const ( & ecx, mplace)
537
+ Ok ( mplace_to_const ( & ecx, mplace) )
538
538
} else {
539
- op_to_const ( & ecx, mplace. into ( ) )
539
+ Ok ( op_to_const ( & ecx, mplace. into ( ) ) )
540
540
}
541
541
} ) ( ) ;
542
542
0 commit comments