@@ -95,8 +95,10 @@ pub fn is_const_evaluatable<'cx, 'tcx>(
95
95
/// and should not leak any information about desugarings.
96
96
#[ derive( Clone , Copy ) ]
97
97
pub struct AbstractConst < ' tcx > {
98
- pub inner : & ' tcx [ Node < ' tcx > ] ,
99
- pub substs : SubstsRef < ' tcx > ,
98
+ // FIXME: Consider adding something like `IndexSlice`
99
+ // and use this here.
100
+ inner : & ' tcx [ Node < ' tcx > ] ,
101
+ substs : SubstsRef < ' tcx > ,
100
102
}
101
103
102
104
impl AbstractConst < ' tcx > {
@@ -117,7 +119,7 @@ impl AbstractConst<'tcx> {
117
119
118
120
#[ inline]
119
121
pub fn subtree ( self , node : NodeId ) -> AbstractConst < ' tcx > {
120
- AbstractConst { inner : & self . inner [ ..=node] , substs : self . substs }
122
+ AbstractConst { inner : & self . inner [ ..=node. index ( ) ] , substs : self . substs }
121
123
}
122
124
123
125
#[ inline]
@@ -129,7 +131,7 @@ impl AbstractConst<'tcx> {
129
131
struct AbstractConstBuilder < ' a , ' tcx > {
130
132
tcx : TyCtxt < ' tcx > ,
131
133
body : & ' a mir:: Body < ' tcx > ,
132
- nodes : Vec < Node < ' tcx > > ,
134
+ nodes : IndexVec < NodeId , Node < ' tcx > > ,
133
135
locals : IndexVec < mir:: Local , NodeId > ,
134
136
checked_op_locals : BitSet < mir:: Local > ,
135
137
}
@@ -143,18 +145,12 @@ impl<'a, 'tcx> AbstractConstBuilder<'a, 'tcx> {
143
145
Some ( AbstractConstBuilder {
144
146
tcx,
145
147
body,
146
- nodes : vec ! [ ] ,
148
+ nodes : IndexVec :: new ( ) ,
147
149
locals : IndexVec :: from_elem ( NodeId :: MAX , & body. local_decls ) ,
148
150
checked_op_locals : BitSet :: new_empty ( body. local_decls . len ( ) ) ,
149
151
} )
150
152
}
151
153
152
- fn add_node ( & mut self , n : Node < ' tcx > ) -> NodeId {
153
- let len = self . nodes . len ( ) ;
154
- self . nodes . push ( n) ;
155
- len
156
- }
157
-
158
154
fn operand_to_node ( & mut self , op : & mir:: Operand < ' tcx > ) -> Option < NodeId > {
159
155
debug ! ( "operand_to_node: op={:?}" , op) ;
160
156
const ZERO_FIELD : mir:: Field = mir:: Field :: from_usize ( 0 ) ;
@@ -174,7 +170,7 @@ impl<'a, 'tcx> AbstractConstBuilder<'a, 'tcx> {
174
170
None
175
171
}
176
172
}
177
- mir:: Operand :: Constant ( ct) => Some ( self . add_node ( Node :: Leaf ( ct. literal ) ) ) ,
173
+ mir:: Operand :: Constant ( ct) => Some ( self . nodes . push ( Node :: Leaf ( ct. literal ) ) ) ,
178
174
}
179
175
}
180
176
@@ -199,15 +195,15 @@ impl<'a, 'tcx> AbstractConstBuilder<'a, 'tcx> {
199
195
Rvalue :: BinaryOp ( op, ref lhs, ref rhs) if Self :: check_binop ( op) => {
200
196
let lhs = self . operand_to_node ( lhs) ?;
201
197
let rhs = self . operand_to_node ( rhs) ?;
202
- self . locals [ local] = self . add_node ( Node :: Binop ( op, lhs, rhs) ) ;
198
+ self . locals [ local] = self . nodes . push ( Node :: Binop ( op, lhs, rhs) ) ;
203
199
if op. is_checkable ( ) {
204
200
bug ! ( "unexpected unchecked checkable binary operation" ) ;
205
201
}
206
202
}
207
203
Rvalue :: CheckedBinaryOp ( op, ref lhs, ref rhs) if Self :: check_binop ( op) => {
208
204
let lhs = self . operand_to_node ( lhs) ?;
209
205
let rhs = self . operand_to_node ( rhs) ?;
210
- self . locals [ local] = self . add_node ( Node :: Binop ( op, lhs, rhs) ) ;
206
+ self . locals [ local] = self . nodes . push ( Node :: Binop ( op, lhs, rhs) ) ;
211
207
self . checked_op_locals . insert ( local) ;
212
208
}
213
209
_ => return None ,
0 commit comments