@@ -21,32 +21,29 @@ use crate::interpret::{
21
21
fn branches < ' tcx > (
22
22
ecx : & CompileTimeInterpCx < ' tcx > ,
23
23
place : & MPlaceTy < ' tcx > ,
24
- n : usize ,
24
+ field_count : usize ,
25
25
variant : Option < VariantIdx > ,
26
26
num_nodes : & mut usize ,
27
27
) -> ValTreeCreationResult < ' tcx > {
28
28
let place = match variant {
29
29
Some ( variant) => ecx. project_downcast ( place, variant) . unwrap ( ) ,
30
30
None => place. clone ( ) ,
31
31
} ;
32
- let variant = variant
33
- . map ( |variant| Some ( ty:: ValTree :: from_scalar_int ( * ecx. tcx , variant. as_u32 ( ) . into ( ) ) ) ) ;
34
- debug ! ( ?place, ?variant) ;
32
+ debug ! ( ?place) ;
35
33
36
- let mut fields = Vec :: with_capacity ( n) ;
37
- for i in 0 ..n {
38
- let field = ecx. project_field ( & place, i) . unwrap ( ) ;
39
- let valtree = const_to_valtree_inner ( ecx, & field, num_nodes) ?;
40
- fields. push ( Some ( valtree) ) ;
41
- }
34
+ let mut branches = Vec :: with_capacity ( field_count + variant. is_some ( ) as usize ) ;
42
35
43
36
// For enums, we prepend their variant index before the variant's fields so we can figure out
44
37
// the variant again when just seeing a valtree.
45
- let branches = variant
46
- . into_iter ( )
47
- . chain ( fields. into_iter ( ) )
48
- . collect :: < Option < Vec < _ > > > ( )
49
- . expect ( "should have already checked for errors in ValTree creation" ) ;
38
+ if let Some ( variant) = variant {
39
+ branches. push ( ty:: ValTree :: from_scalar_int ( * ecx. tcx , variant. as_u32 ( ) . into ( ) ) ) ;
40
+ }
41
+
42
+ for i in 0 ..field_count {
43
+ let field = ecx. project_field ( & place, i) . unwrap ( ) ;
44
+ let valtree = const_to_valtree_inner ( ecx, & field, num_nodes) ?;
45
+ branches. push ( valtree) ;
46
+ }
50
47
51
48
// Have to account for ZSTs here
52
49
if branches. len ( ) == 0 {
0 commit comments