@@ -174,6 +174,7 @@ impl<'a, 'tcx> AbstractConstBuilder<'a, 'tcx> {
174174 }
175175 }
176176
177+ /// We do not allow all binary operations in abstract consts, so filter disallowed ones.
177178 fn check_binop ( op : mir:: BinOp ) -> bool {
178179 use mir:: BinOp :: * ;
179180 match op {
@@ -183,6 +184,15 @@ impl<'a, 'tcx> AbstractConstBuilder<'a, 'tcx> {
183184 }
184185 }
185186
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+
186196 fn build_statement ( & mut self , stmt : & mir:: Statement < ' tcx > ) -> Option < ( ) > {
187197 debug ! ( "AbstractConstBuilder: stmt={:?}" , stmt) ;
188198 match stmt. kind {
@@ -191,28 +201,37 @@ impl<'a, 'tcx> AbstractConstBuilder<'a, 'tcx> {
191201 match * rvalue {
192202 Rvalue :: Use ( ref operand) => {
193203 self . locals [ local] = self . operand_to_node ( operand) ?;
204+ Some ( ( ) )
194205 }
195206 Rvalue :: BinaryOp ( op, ref lhs, ref rhs) if Self :: check_binop ( op) => {
196207 let lhs = self . operand_to_node ( lhs) ?;
197208 let rhs = self . operand_to_node ( rhs) ?;
198209 self . locals [ local] = self . nodes . push ( Node :: Binop ( op, lhs, rhs) ) ;
199210 if op. is_checkable ( ) {
200211 bug ! ( "unexpected unchecked checkable binary operation" ) ;
212+ } else {
213+ Some ( ( ) )
201214 }
202215 }
203216 Rvalue :: CheckedBinaryOp ( op, ref lhs, ref rhs) if Self :: check_binop ( op) => {
204217 let lhs = self . operand_to_node ( lhs) ?;
205218 let rhs = self . operand_to_node ( rhs) ?;
206219 self . locals [ local] = self . nodes . push ( Node :: Binop ( op, lhs, rhs) ) ;
207220 self . checked_op_locals . insert ( local) ;
221+ Some ( ( ) )
208222 }
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 ,
210229 }
211230 }
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 ,
213234 }
214-
215- Some ( ( ) )
216235 }
217236
218237 fn build_terminator (
0 commit comments