@@ -174,6 +174,7 @@ impl<'a, 'tcx> AbstractConstBuilder<'a, 'tcx> {
174
174
}
175
175
}
176
176
177
+ /// We do not allow all binary operations in abstract consts, so filter disallowed ones.
177
178
fn check_binop ( op : mir:: BinOp ) -> bool {
178
179
use mir:: BinOp :: * ;
179
180
match op {
@@ -183,6 +184,15 @@ impl<'a, 'tcx> AbstractConstBuilder<'a, 'tcx> {
183
184
}
184
185
}
185
186
187
+ /// While we currently allow all unary operations, we still want to explicitly guard against
188
+ /// future changes here.
189
+ fn check_unop ( op : mir:: UnOp ) -> bool {
190
+ use mir:: UnOp :: * ;
191
+ match op {
192
+ Not | Neg => true ,
193
+ }
194
+ }
195
+
186
196
fn build_statement ( & mut self , stmt : & mir:: Statement < ' tcx > ) -> Option < ( ) > {
187
197
debug ! ( "AbstractConstBuilder: stmt={:?}" , stmt) ;
188
198
match stmt. kind {
@@ -191,28 +201,37 @@ impl<'a, 'tcx> AbstractConstBuilder<'a, 'tcx> {
191
201
match * rvalue {
192
202
Rvalue :: Use ( ref operand) => {
193
203
self . locals [ local] = self . operand_to_node ( operand) ?;
204
+ Some ( ( ) )
194
205
}
195
206
Rvalue :: BinaryOp ( op, ref lhs, ref rhs) if Self :: check_binop ( op) => {
196
207
let lhs = self . operand_to_node ( lhs) ?;
197
208
let rhs = self . operand_to_node ( rhs) ?;
198
209
self . locals [ local] = self . nodes . push ( Node :: Binop ( op, lhs, rhs) ) ;
199
210
if op. is_checkable ( ) {
200
211
bug ! ( "unexpected unchecked checkable binary operation" ) ;
212
+ } else {
213
+ Some ( ( ) )
201
214
}
202
215
}
203
216
Rvalue :: CheckedBinaryOp ( op, ref lhs, ref rhs) if Self :: check_binop ( op) => {
204
217
let lhs = self . operand_to_node ( lhs) ?;
205
218
let rhs = self . operand_to_node ( rhs) ?;
206
219
self . locals [ local] = self . nodes . push ( Node :: Binop ( op, lhs, rhs) ) ;
207
220
self . checked_op_locals . insert ( local) ;
221
+ Some ( ( ) )
208
222
}
209
- _ => return None ,
223
+ Rvalue :: UnaryOp ( op, ref operand) if Self :: check_unop ( op) => {
224
+ let operand = self . operand_to_node ( operand) ?;
225
+ self . locals [ local] = self . nodes . push ( Node :: UnaryOp ( op, operand) ) ;
226
+ Some ( ( ) )
227
+ }
228
+ _ => None ,
210
229
}
211
230
}
212
- _ => return None ,
231
+ // These are not actually relevant for us here, so we can ignore them.
232
+ StatementKind :: StorageLive ( _) | StatementKind :: StorageDead ( _) => Some ( ( ) ) ,
233
+ _ => None ,
213
234
}
214
-
215
- Some ( ( ) )
216
235
}
217
236
218
237
fn build_terminator (
0 commit comments