@@ -5,7 +5,7 @@ use crate::const_eval::CanAccessStatics;
5
5
use crate :: interpret:: MPlaceTy ;
6
6
use crate :: interpret:: {
7
7
intern_const_alloc_recursive, ConstValue , ImmTy , Immediate , InternKind , MemPlaceMeta ,
8
- MemoryKind , PlaceTy , Projectable , Scalar ,
8
+ MemoryKind , Place , Projectable , Scalar ,
9
9
} ;
10
10
use rustc_middle:: ty:: { self , ScalarInt , Ty , TyCtxt } ;
11
11
use rustc_span:: source_map:: DUMMY_SP ;
@@ -21,7 +21,7 @@ fn branches<'tcx>(
21
21
) -> ValTreeCreationResult < ' tcx > {
22
22
let place = match variant {
23
23
Some ( variant) => ecx. project_downcast ( place, variant) . unwrap ( ) ,
24
- None => * place,
24
+ None => place. clone ( ) ,
25
25
} ;
26
26
let variant = variant. map ( |variant| Some ( ty:: ValTree :: Leaf ( ScalarInt :: from ( variant. as_u32 ( ) ) ) ) ) ;
27
27
debug ! ( ?place, ?variant) ;
@@ -86,7 +86,7 @@ pub(crate) fn const_to_valtree_inner<'tcx>(
86
86
Ok ( ty:: ValTree :: zst ( ) )
87
87
}
88
88
ty:: Bool | ty:: Int ( _) | ty:: Uint ( _) | ty:: Float ( _) | ty:: Char => {
89
- let Ok ( val) = ecx. read_immediate ( & place. into ( ) ) else {
89
+ let Ok ( val) = ecx. read_immediate ( place) else {
90
90
return Err ( ValTreeCreationError :: Other ) ;
91
91
} ;
92
92
let val = val. to_scalar ( ) ;
@@ -102,7 +102,7 @@ pub(crate) fn const_to_valtree_inner<'tcx>(
102
102
ty:: FnPtr ( _) | ty:: RawPtr ( _) => Err ( ValTreeCreationError :: NonSupportedType ) ,
103
103
104
104
ty:: Ref ( _, _, _) => {
105
- let Ok ( derefd_place) = ecx. deref_operand ( & place. into ( ) ) else {
105
+ let Ok ( derefd_place) = ecx. deref_operand ( place) else {
106
106
return Err ( ValTreeCreationError :: Other ) ;
107
107
} ;
108
108
debug ! ( ?derefd_place) ;
@@ -130,7 +130,7 @@ pub(crate) fn const_to_valtree_inner<'tcx>(
130
130
bug ! ( "uninhabited types should have errored and never gotten converted to valtree" )
131
131
}
132
132
133
- let Ok ( variant) = ecx. read_discriminant ( & place. into ( ) ) else {
133
+ let Ok ( variant) = ecx. read_discriminant ( place) else {
134
134
return Err ( ValTreeCreationError :: Other ) ;
135
135
} ;
136
136
branches ( ecx, place, def. variant ( variant) . fields . len ( ) , def. is_enum ( ) . then_some ( variant) , num_nodes)
@@ -280,7 +280,7 @@ pub fn valtree_to_const_value<'tcx>(
280
280
) ,
281
281
} ,
282
282
ty:: Ref ( _, _, _) | ty:: Tuple ( _) | ty:: Array ( _, _) | ty:: Adt ( ..) => {
283
- let mut place = match ty. kind ( ) {
283
+ let place = match ty. kind ( ) {
284
284
ty:: Ref ( _, inner_ty, _) => {
285
285
// Need to create a place for the pointee to fill for Refs
286
286
create_pointee_place ( & mut ecx, * inner_ty, valtree)
@@ -289,8 +289,8 @@ pub fn valtree_to_const_value<'tcx>(
289
289
} ;
290
290
debug ! ( ?place) ;
291
291
292
- valtree_into_mplace ( & mut ecx, & mut place, valtree) ;
293
- dump_place ( & ecx, place. into ( ) ) ;
292
+ valtree_into_mplace ( & mut ecx, & place, valtree) ;
293
+ dump_place ( & ecx, & place) ;
294
294
intern_const_alloc_recursive ( & mut ecx, InternKind :: Constant , & place) . unwrap ( ) ;
295
295
296
296
match ty. kind ( ) {
@@ -329,7 +329,7 @@ pub fn valtree_to_const_value<'tcx>(
329
329
#[ instrument( skip( ecx) , level = "debug" ) ]
330
330
fn valtree_into_mplace < ' tcx > (
331
331
ecx : & mut CompileTimeEvalContext < ' tcx , ' tcx > ,
332
- place : & mut MPlaceTy < ' tcx > ,
332
+ place : & MPlaceTy < ' tcx > ,
333
333
valtree : ty:: ValTree < ' tcx > ,
334
334
) {
335
335
// This will match on valtree and write the value(s) corresponding to the ValTree
@@ -345,14 +345,14 @@ fn valtree_into_mplace<'tcx>(
345
345
ty:: Bool | ty:: Int ( _) | ty:: Uint ( _) | ty:: Float ( _) | ty:: Char => {
346
346
let scalar_int = valtree. unwrap_leaf ( ) ;
347
347
debug ! ( "writing trivial valtree {:?} to place {:?}" , scalar_int, place) ;
348
- ecx. write_immediate ( Immediate :: Scalar ( scalar_int. into ( ) ) , & place. into ( ) ) . unwrap ( ) ;
348
+ ecx. write_immediate ( Immediate :: Scalar ( scalar_int. into ( ) ) , place) . unwrap ( ) ;
349
349
}
350
350
ty:: Ref ( _, inner_ty, _) => {
351
- let mut pointee_place = create_pointee_place ( ecx, * inner_ty, valtree) ;
351
+ let pointee_place = create_pointee_place ( ecx, * inner_ty, valtree) ;
352
352
debug ! ( ?pointee_place) ;
353
353
354
- valtree_into_mplace ( ecx, & mut pointee_place, valtree) ;
355
- dump_place ( ecx, pointee_place. into ( ) ) ;
354
+ valtree_into_mplace ( ecx, & pointee_place, valtree) ;
355
+ dump_place ( ecx, & pointee_place) ;
356
356
intern_const_alloc_recursive ( ecx, InternKind :: Constant , & pointee_place) . unwrap ( ) ;
357
357
358
358
let imm = match inner_ty. kind ( ) {
@@ -369,7 +369,7 @@ fn valtree_into_mplace<'tcx>(
369
369
} ;
370
370
debug ! ( ?imm) ;
371
371
372
- ecx. write_immediate ( imm, & place. into ( ) ) . unwrap ( ) ;
372
+ ecx. write_immediate ( imm, place) . unwrap ( ) ;
373
373
}
374
374
ty:: Adt ( _, _) | ty:: Tuple ( _) | ty:: Array ( _, _) | ty:: Str | ty:: Slice ( _) => {
375
375
let branches = valtree. unwrap_branch ( ) ;
@@ -389,7 +389,7 @@ fn valtree_into_mplace<'tcx>(
389
389
Some ( variant_idx) ,
390
390
)
391
391
}
392
- _ => ( * place, branches, None ) ,
392
+ _ => ( place. clone ( ) , branches, None ) ,
393
393
} ;
394
394
debug ! ( ?place_adjusted, ?branches) ;
395
395
@@ -398,7 +398,7 @@ fn valtree_into_mplace<'tcx>(
398
398
for ( i, inner_valtree) in branches. iter ( ) . enumerate ( ) {
399
399
debug ! ( ?i, ?inner_valtree) ;
400
400
401
- let mut place_inner = match ty. kind ( ) {
401
+ let place_inner = match ty. kind ( ) {
402
402
ty:: Str | ty:: Slice ( _) => ecx. project_index ( place, i as u64 ) . unwrap ( ) ,
403
403
_ if !ty. is_sized ( * ecx. tcx , ty:: ParamEnv :: empty ( ) )
404
404
&& i == branches. len ( ) - 1 =>
@@ -443,25 +443,25 @@ fn valtree_into_mplace<'tcx>(
443
443
} ;
444
444
445
445
debug ! ( ?place_inner) ;
446
- valtree_into_mplace ( ecx, & mut place_inner, * inner_valtree) ;
447
- dump_place ( & ecx, place_inner. into ( ) ) ;
446
+ valtree_into_mplace ( ecx, & place_inner, * inner_valtree) ;
447
+ dump_place ( & ecx, & place_inner) ;
448
448
}
449
449
450
450
debug ! ( "dump of place_adjusted:" ) ;
451
- dump_place ( ecx, place_adjusted. into ( ) ) ;
451
+ dump_place ( ecx, & place_adjusted) ;
452
452
453
453
if let Some ( variant_idx) = variant_idx {
454
454
// don't forget filling the place with the discriminant of the enum
455
- ecx. write_discriminant ( variant_idx, & place. into ( ) ) . unwrap ( ) ;
455
+ ecx. write_discriminant ( variant_idx, place) . unwrap ( ) ;
456
456
}
457
457
458
458
debug ! ( "dump of place after writing discriminant:" ) ;
459
- dump_place ( ecx, place. into ( ) ) ;
459
+ dump_place ( ecx, place) ;
460
460
}
461
461
_ => bug ! ( "shouldn't have created a ValTree for {:?}" , ty) ,
462
462
}
463
463
}
464
464
465
- fn dump_place < ' tcx > ( ecx : & CompileTimeEvalContext < ' tcx , ' tcx > , place : PlaceTy < ' tcx > ) {
466
- trace ! ( "{:?}" , ecx. dump_place( * place) ) ;
465
+ fn dump_place < ' tcx > ( ecx : & CompileTimeEvalContext < ' tcx , ' tcx > , place : & MPlaceTy < ' tcx > ) {
466
+ trace ! ( "{:?}" , ecx. dump_place( Place :: Ptr ( * * place) ) ) ;
467
467
}
0 commit comments