@@ -15,7 +15,7 @@ use rustc_apfloat::ieee::{Half, Quad};
15
15
use rustc_ast:: ast:: { self , LitFloatType , LitKind } ;
16
16
use rustc_hir:: def:: { DefKind , Res } ;
17
17
use rustc_hir:: {
18
- BinOp , BinOpKind , Block , ConstBlock , Expr , ExprKind , HirId , Item , ItemKind , Node , PatExpr , PatExprKind , QPath , UnOp ,
18
+ BinOpKind , Block , ConstBlock , Expr , ExprKind , HirId , Item , ItemKind , Node , PatExpr , PatExprKind , QPath , UnOp ,
19
19
} ;
20
20
use rustc_lexer:: tokenize;
21
21
use rustc_lint:: LateContext ;
@@ -506,7 +506,7 @@ impl<'tcx> ConstEvalCtxt<'tcx> {
506
506
UnOp :: Deref => Some ( if let Constant :: Ref ( r) = o { * r } else { o } ) ,
507
507
} ) ,
508
508
ExprKind :: If ( cond, then, ref otherwise) => self . ifthenelse ( cond, then, * otherwise) ,
509
- ExprKind :: Binary ( op, left, right) => self . binop ( op, left, right) ,
509
+ ExprKind :: Binary ( op, left, right) => self . binop ( op. node , left, right) ,
510
510
ExprKind :: Call ( callee, [ ] ) => {
511
511
// We only handle a few const functions for now.
512
512
if let ExprKind :: Path ( qpath) = & callee. kind
@@ -744,7 +744,7 @@ impl<'tcx> ConstEvalCtxt<'tcx> {
744
744
}
745
745
}
746
746
747
- fn binop ( & self , op : BinOp , left : & Expr < ' _ > , right : & Expr < ' _ > ) -> Option < Constant < ' tcx > > {
747
+ fn binop ( & self , op : BinOpKind , left : & Expr < ' _ > , right : & Expr < ' _ > ) -> Option < Constant < ' tcx > > {
748
748
let l = self . expr ( left) ?;
749
749
let r = self . expr ( right) ;
750
750
match ( l, r) {
@@ -757,15 +757,15 @@ impl<'tcx> ConstEvalCtxt<'tcx> {
757
757
758
758
// Using / or %, where the left-hand argument is the smallest integer of a signed integer type and
759
759
// the right-hand argument is -1 always panics, even with overflow-checks disabled
760
- if let BinOpKind :: Div | BinOpKind :: Rem = op. node
760
+ if let BinOpKind :: Div | BinOpKind :: Rem = op
761
761
&& l == ty_min_value
762
762
&& r == -1
763
763
{
764
764
return None ;
765
765
}
766
766
767
767
let zext = |n : i128 | Constant :: Int ( unsext ( self . tcx , n, ity) ) ;
768
- match op. node {
768
+ match op {
769
769
// When +, * or binary - create a value greater than the maximum value, or less than
770
770
// the minimum value that can be stored, it panics.
771
771
BinOpKind :: Add => l. checked_add ( r) . and_then ( |n| ity. ensure_fits ( n) ) . map ( zext) ,
@@ -792,7 +792,7 @@ impl<'tcx> ConstEvalCtxt<'tcx> {
792
792
ty:: Uint ( ity) => {
793
793
let bits = ity. bits ( ) ;
794
794
795
- match op. node {
795
+ match op {
796
796
BinOpKind :: Add => l. checked_add ( r) . and_then ( |n| ity. ensure_fits ( n) ) . map ( Constant :: Int ) ,
797
797
BinOpKind :: Sub => l. checked_sub ( r) . and_then ( |n| ity. ensure_fits ( n) ) . map ( Constant :: Int ) ,
798
798
BinOpKind :: Mul => l. checked_mul ( r) . and_then ( |n| ity. ensure_fits ( n) ) . map ( Constant :: Int ) ,
@@ -815,7 +815,7 @@ impl<'tcx> ConstEvalCtxt<'tcx> {
815
815
_ => None ,
816
816
} ,
817
817
// FIXME(f16_f128): add these types when binary operations are available on all platforms
818
- ( Constant :: F32 ( l) , Some ( Constant :: F32 ( r) ) ) => match op. node {
818
+ ( Constant :: F32 ( l) , Some ( Constant :: F32 ( r) ) ) => match op {
819
819
BinOpKind :: Add => Some ( Constant :: F32 ( l + r) ) ,
820
820
BinOpKind :: Sub => Some ( Constant :: F32 ( l - r) ) ,
821
821
BinOpKind :: Mul => Some ( Constant :: F32 ( l * r) ) ,
@@ -829,7 +829,7 @@ impl<'tcx> ConstEvalCtxt<'tcx> {
829
829
BinOpKind :: Gt => Some ( Constant :: Bool ( l > r) ) ,
830
830
_ => None ,
831
831
} ,
832
- ( Constant :: F64 ( l) , Some ( Constant :: F64 ( r) ) ) => match op. node {
832
+ ( Constant :: F64 ( l) , Some ( Constant :: F64 ( r) ) ) => match op {
833
833
BinOpKind :: Add => Some ( Constant :: F64 ( l + r) ) ,
834
834
BinOpKind :: Sub => Some ( Constant :: F64 ( l - r) ) ,
835
835
BinOpKind :: Mul => Some ( Constant :: F64 ( l * r) ) ,
@@ -843,7 +843,7 @@ impl<'tcx> ConstEvalCtxt<'tcx> {
843
843
BinOpKind :: Gt => Some ( Constant :: Bool ( l > r) ) ,
844
844
_ => None ,
845
845
} ,
846
- ( l, r) => match ( op. node , l, r) {
846
+ ( l, r) => match ( op, l, r) {
847
847
( BinOpKind :: And , Constant :: Bool ( false ) , _) => Some ( Constant :: Bool ( false ) ) ,
848
848
( BinOpKind :: Or , Constant :: Bool ( true ) , _) => Some ( Constant :: Bool ( true ) ) ,
849
849
( BinOpKind :: And , Constant :: Bool ( true ) , Some ( r) ) | ( BinOpKind :: Or , Constant :: Bool ( false ) , Some ( r) ) => {
0 commit comments