@@ -583,11 +583,15 @@ impl<'tcx> Validator<'_, 'tcx> {
583583
584584 fn validate_rvalue ( & self , rvalue : & Rvalue < ' tcx > ) -> Result < ( ) , Unpromotable > {
585585 match rvalue {
586- Rvalue :: Use ( operand) | Rvalue :: Repeat ( operand, _) | Rvalue :: UnaryOp ( _, operand) => {
586+ Rvalue :: Use ( operand)
587+ | Rvalue :: Repeat ( operand, _)
588+ | Rvalue :: UnaryOp ( UnOp :: Not | UnOp :: Neg , operand) => {
587589 self . validate_operand ( operand) ?;
588590 }
589591
590- Rvalue :: Discriminant ( place) | Rvalue :: Len ( place) => self . validate_place ( place. as_ref ( ) ) ?,
592+ Rvalue :: Discriminant ( place) | Rvalue :: Len ( place) => {
593+ self . validate_place ( place. as_ref ( ) ) ?
594+ }
591595
592596 Rvalue :: ThreadLocalRef ( _) => return Err ( Unpromotable ) ,
593597
@@ -606,35 +610,52 @@ impl<'tcx> Validator<'_, 'tcx> {
606610 self . validate_operand ( operand) ?;
607611 }
608612
609- Rvalue :: BinaryOp ( op, lhs, rhs)
610- | Rvalue :: CheckedBinaryOp ( op, lhs, rhs) => {
613+ Rvalue :: BinaryOp ( op, lhs, rhs) | Rvalue :: CheckedBinaryOp ( op, lhs, rhs) => {
611614 let op = * op;
612615 if let ty:: RawPtr ( _) | ty:: FnPtr ( ..) = lhs. ty ( self . body , self . tcx ) . kind ( ) {
613- assert ! (
614- op == BinOp :: Eq
615- || op == BinOp :: Ne
616- || op == BinOp :: Le
617- || op == BinOp :: Lt
618- || op == BinOp :: Ge
619- || op == BinOp :: Gt
620- || op == BinOp :: Offset
621- ) ;
622-
623616 // raw pointer operations are not allowed inside consts and thus not promotable
617+ assert ! ( matches!(
618+ op,
619+ BinOp :: Eq
620+ | BinOp :: Ne
621+ | BinOp :: Le
622+ | BinOp :: Lt
623+ | BinOp :: Ge
624+ | BinOp :: Gt
625+ | BinOp :: Offset
626+ ) ) ;
624627 return Err ( Unpromotable ) ;
625628 }
626629
627- // FIXME: reject operations that can fail -- namely, division and modulo.
630+ match op {
631+ // FIXME: reject operations that can fail -- namely, division and modulo.
632+ BinOp :: Eq
633+ | BinOp :: Ne
634+ | BinOp :: Le
635+ | BinOp :: Lt
636+ | BinOp :: Ge
637+ | BinOp :: Gt
638+ | BinOp :: Offset
639+ | BinOp :: Add
640+ | BinOp :: Sub
641+ | BinOp :: Mul
642+ | BinOp :: Div
643+ | BinOp :: Rem
644+ | BinOp :: BitXor
645+ | BinOp :: BitAnd
646+ | BinOp :: BitOr
647+ | BinOp :: Shl
648+ | BinOp :: Shr => { }
649+ }
628650
629651 self . validate_operand ( lhs) ?;
630652 self . validate_operand ( rhs) ?;
631653 }
632654
633- Rvalue :: NullaryOp ( op, _) => {
634- if matches ! ( op, NullOp :: Box ) {
635- return Err ( Unpromotable ) ;
636- }
637- }
655+ Rvalue :: NullaryOp ( op, _) => match op {
656+ NullOp :: Box => return Err ( Unpromotable ) ,
657+ NullOp :: SizeOf => { }
658+ } ,
638659
639660 Rvalue :: AddressOf ( _, place) => {
640661 // We accept `&raw *`, i.e., raw reborrows -- creating a raw pointer is
0 commit comments