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