@@ -28,7 +28,7 @@ pub(crate) fn new_allocation<'tcx>(
28
28
tables : & mut Tables < ' tcx > ,
29
29
) -> Allocation {
30
30
try_new_allocation ( ty, const_value, tables)
31
- . expect ( & format ! ( "Failed to convert: {const_value:?} to {ty:?}" ) )
31
+ . unwrap_or_else ( |_| panic ! ( "Failed to convert: {const_value:?} to {ty:?}" ) )
32
32
}
33
33
34
34
#[ allow( rustc:: usage_of_qualified_ty) ]
@@ -37,39 +37,30 @@ pub(crate) fn try_new_allocation<'tcx>(
37
37
const_value : ConstValue < ' tcx > ,
38
38
tables : & mut Tables < ' tcx > ,
39
39
) -> Result < Allocation , Error > {
40
+ let layout = tables
41
+ . tcx
42
+ . layout_of ( rustc_middle:: ty:: TypingEnv :: fully_monomorphized ( ) . as_query_input ( ty) )
43
+ . map_err ( |e| e. stable ( tables) ) ?;
40
44
Ok ( match const_value {
41
45
ConstValue :: Scalar ( scalar) => {
42
46
let size = scalar. size ( ) ;
43
- let align = tables
44
- . tcx
45
- . layout_of ( rustc_middle:: ty:: TypingEnv :: fully_monomorphized ( ) . as_query_input ( ty) )
46
- . map_err ( |e| e. stable ( tables) ) ?
47
- . align ;
48
- let mut allocation =
49
- rustc_middle:: mir:: interpret:: Allocation :: new ( size, align. abi , AllocInit :: Uninit ) ;
47
+ let mut allocation = rustc_middle:: mir:: interpret:: Allocation :: new (
48
+ size,
49
+ layout. align . abi ,
50
+ AllocInit :: Uninit ,
51
+ ) ;
50
52
allocation
51
53
. write_scalar ( & tables. tcx , alloc_range ( Size :: ZERO , size) , scalar)
52
54
. map_err ( |e| e. stable ( tables) ) ?;
53
55
allocation. stable ( tables)
54
56
}
55
- ConstValue :: ZeroSized => {
56
- let align = tables
57
- . tcx
58
- . layout_of ( rustc_middle:: ty:: TypingEnv :: fully_monomorphized ( ) . as_query_input ( ty) )
59
- . map_err ( |e| e. stable ( tables) ) ?
60
- . align ;
61
- new_empty_allocation ( align. abi )
62
- }
57
+ ConstValue :: ZeroSized => new_empty_allocation ( layout. align . abi ) ,
63
58
ConstValue :: Slice { data, meta } => {
64
59
let alloc_id = tables. tcx . reserve_and_set_memory_alloc ( data) ;
65
60
let ptr = Pointer :: new ( alloc_id. into ( ) , Size :: ZERO ) ;
66
61
let scalar_ptr = rustc_middle:: mir:: interpret:: Scalar :: from_pointer ( ptr, & tables. tcx ) ;
67
62
let scalar_meta =
68
63
rustc_middle:: mir:: interpret:: Scalar :: from_target_usize ( meta, & tables. tcx ) ;
69
- let layout = tables
70
- . tcx
71
- . layout_of ( rustc_middle:: ty:: TypingEnv :: fully_monomorphized ( ) . as_query_input ( ty) )
72
- . map_err ( |e| e. stable ( tables) ) ?;
73
64
let mut allocation = rustc_middle:: mir:: interpret:: Allocation :: new (
74
65
layout. size ,
75
66
layout. align . abi ,
@@ -93,12 +84,7 @@ pub(crate) fn try_new_allocation<'tcx>(
93
84
}
94
85
ConstValue :: Indirect { alloc_id, offset } => {
95
86
let alloc = tables. tcx . global_alloc ( alloc_id) . unwrap_memory ( ) ;
96
- let ty_size = tables
97
- . tcx
98
- . layout_of ( rustc_middle:: ty:: TypingEnv :: fully_monomorphized ( ) . as_query_input ( ty) )
99
- . map_err ( |e| e. stable ( tables) ) ?
100
- . size ;
101
- allocation_filter ( & alloc. 0 , alloc_range ( offset, ty_size) , tables)
87
+ allocation_filter ( & alloc. 0 , alloc_range ( offset, layout. size ) , tables)
102
88
}
103
89
} )
104
90
}
0 commit comments