@@ -583,11 +583,15 @@ impl<'tcx> Validator<'_, 'tcx> {
583
583
584
584
fn validate_rvalue ( & self , rvalue : & Rvalue < ' tcx > ) -> Result < ( ) , Unpromotable > {
585
585
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) => {
587
589
self . validate_operand ( operand) ?;
588
590
}
589
591
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
+ }
591
595
592
596
Rvalue :: ThreadLocalRef ( _) => return Err ( Unpromotable ) ,
593
597
@@ -606,35 +610,52 @@ impl<'tcx> Validator<'_, 'tcx> {
606
610
self . validate_operand ( operand) ?;
607
611
}
608
612
609
- Rvalue :: BinaryOp ( op, lhs, rhs)
610
- | Rvalue :: CheckedBinaryOp ( op, lhs, rhs) => {
613
+ Rvalue :: BinaryOp ( op, lhs, rhs) | Rvalue :: CheckedBinaryOp ( op, lhs, rhs) => {
611
614
let op = * op;
612
615
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
-
623
616
// 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
+ ) ) ;
624
627
return Err ( Unpromotable ) ;
625
628
}
626
629
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
+ }
628
650
629
651
self . validate_operand ( lhs) ?;
630
652
self . validate_operand ( rhs) ?;
631
653
}
632
654
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
+ } ,
638
659
639
660
Rvalue :: AddressOf ( _, place) => {
640
661
// We accept `&raw *`, i.e., raw reborrows -- creating a raw pointer is
0 commit comments