@@ -6,7 +6,7 @@ use rustc_hir::{self as hir};
6
6
use rustc_span:: Span ;
7
7
use rustc_target:: abi:: { HasDataLayout , Size } ;
8
8
9
- use crate :: mir:: interpret:: { alloc_range, AllocId , ConstAllocation , ErrorHandled , Scalar } ;
9
+ use crate :: mir:: interpret:: { alloc_range, AllocId , ErrorHandled , Scalar } ;
10
10
use crate :: mir:: { pretty_print_const_value, Promoted } ;
11
11
use crate :: ty:: ScalarInt ;
12
12
use crate :: ty:: { self , print:: pretty_print_const, List , Ty , TyCtxt } ;
@@ -29,8 +29,8 @@ pub struct ConstAlloc<'tcx> {
29
29
/// Represents a constant value in Rust. `Scalar` and `Slice` are optimizations for
30
30
/// array length computations, enum discriminants and the pattern matching logic.
31
31
#[ derive( Copy , Clone , Debug , Eq , PartialEq , TyEncodable , TyDecodable , Hash ) ]
32
- #[ derive( HashStable , Lift ) ]
33
- pub enum ConstValue < ' tcx > {
32
+ #[ derive( HashStable ) ]
33
+ pub enum ConstValue {
34
34
/// Used for types with `layout::abi::Scalar` ABI.
35
35
///
36
36
/// Not using the enum `Value` to encode that this must not be `Uninit`.
@@ -48,7 +48,7 @@ pub enum ConstValue<'tcx> {
48
48
Slice {
49
49
/// The allocation storing the slice contents.
50
50
/// This always points to the beginning of the allocation.
51
- data : ConstAllocation < ' tcx > ,
51
+ alloc_id : AllocId ,
52
52
/// The metadata field of the reference.
53
53
/// This is a "target usize", so we use `u64` as in the interpreter.
54
54
meta : u64 ,
@@ -71,9 +71,9 @@ pub enum ConstValue<'tcx> {
71
71
}
72
72
73
73
#[ cfg( all( target_arch = "x86_64" , target_pointer_width = "64" ) ) ]
74
- static_assert_size ! ( ConstValue < ' _> , 24 ) ;
74
+ static_assert_size ! ( ConstValue , 24 ) ;
75
75
76
- impl < ' tcx > ConstValue < ' tcx > {
76
+ impl ConstValue {
77
77
#[ inline]
78
78
pub fn try_to_scalar ( & self ) -> Option < Scalar < AllocId > > {
79
79
match * self {
@@ -94,11 +94,11 @@ impl<'tcx> ConstValue<'tcx> {
94
94
self . try_to_scalar_int ( ) ?. try_into ( ) . ok ( )
95
95
}
96
96
97
- pub fn try_to_target_usize ( & self , tcx : TyCtxt < ' tcx > ) -> Option < u64 > {
97
+ pub fn try_to_target_usize ( & self , tcx : TyCtxt < ' _ > ) -> Option < u64 > {
98
98
self . try_to_scalar_int ( ) ?. try_to_target_usize ( tcx) . ok ( )
99
99
}
100
100
101
- pub fn try_to_bits_for_ty (
101
+ pub fn try_to_bits_for_ty < ' tcx > (
102
102
& self ,
103
103
tcx : TyCtxt < ' tcx > ,
104
104
param_env : ty:: ParamEnv < ' tcx > ,
@@ -125,12 +125,15 @@ impl<'tcx> ConstValue<'tcx> {
125
125
}
126
126
127
127
/// Must only be called on constants of type `&str` or `&[u8]`!
128
- pub fn try_get_slice_bytes_for_diagnostics ( & self , tcx : TyCtxt < ' tcx > ) -> Option < & ' tcx [ u8 ] > {
129
- let ( data, start, end) = match self {
128
+ pub fn try_get_slice_bytes_for_diagnostics < ' tcx > (
129
+ & self ,
130
+ tcx : TyCtxt < ' tcx > ,
131
+ ) -> Option < & ' tcx [ u8 ] > {
132
+ let ( alloc_id, start, len) = match self {
130
133
ConstValue :: Scalar ( _) | ConstValue :: ZeroSized => {
131
134
bug ! ( "`try_get_slice_bytes` on non-slice constant" )
132
135
}
133
- & ConstValue :: Slice { data , meta } => ( data , 0 , meta) ,
136
+ & ConstValue :: Slice { alloc_id , meta } => ( alloc_id , 0 , meta) ,
134
137
& ConstValue :: Indirect { alloc_id, offset } => {
135
138
// The reference itself is stored behind an indirection.
136
139
// Load the reference, and then load the actual slice contents.
@@ -162,14 +165,15 @@ impl<'tcx> ConstValue<'tcx> {
162
165
}
163
166
// Non-empty slice, must have memory. We know this is a relative pointer.
164
167
let ( inner_alloc_id, offset) = ptr. into_parts ( ) ;
165
- let data = tcx. global_alloc ( inner_alloc_id?) . unwrap_memory ( ) ;
166
- ( data, offset. bytes ( ) , offset. bytes ( ) + len)
168
+ ( inner_alloc_id?, offset. bytes ( ) , len)
167
169
}
168
170
} ;
169
171
172
+ let data = tcx. global_alloc ( alloc_id) . unwrap_memory ( ) ;
173
+
170
174
// This is for diagnostics only, so we are okay to use `inspect_with_uninit_and_ptr_outside_interpreter`.
171
175
let start = start. try_into ( ) . unwrap ( ) ;
172
- let end = end . try_into ( ) . unwrap ( ) ;
176
+ let end = start + usize :: try_from ( len ) . unwrap ( ) ;
173
177
Some ( data. inner ( ) . inspect_with_uninit_and_ptr_outside_interpreter ( start..end) )
174
178
}
175
179
}
@@ -197,7 +201,7 @@ pub enum Const<'tcx> {
197
201
198
202
/// This constant cannot go back into the type system, as it represents
199
203
/// something the type system cannot handle (e.g. pointers).
200
- Val ( ConstValue < ' tcx > , Ty < ' tcx > ) ,
204
+ Val ( ConstValue , Ty < ' tcx > ) ,
201
205
}
202
206
203
207
impl < ' tcx > Const < ' tcx > {
@@ -245,7 +249,7 @@ impl<'tcx> Const<'tcx> {
245
249
tcx : TyCtxt < ' tcx > ,
246
250
param_env : ty:: ParamEnv < ' tcx > ,
247
251
span : Option < Span > ,
248
- ) -> Result < ConstValue < ' tcx > , ErrorHandled > {
252
+ ) -> Result < ConstValue , ErrorHandled > {
249
253
match self {
250
254
Const :: Ty ( c) => {
251
255
// We want to consistently have a "clean" value for type system constants (i.e., no
@@ -337,7 +341,7 @@ impl<'tcx> Const<'tcx> {
337
341
}
338
342
339
343
#[ inline]
340
- pub fn from_value ( val : ConstValue < ' tcx > , ty : Ty < ' tcx > ) -> Self {
344
+ pub fn from_value ( val : ConstValue , ty : Ty < ' tcx > ) -> Self {
341
345
Self :: Val ( val, ty)
342
346
}
343
347
0 commit comments