@@ -34,14 +34,10 @@ pub(super) fn check<'tcx>(
3434}
3535
3636fn used_in_comparison_with_zero ( cx : & LateContext < ' _ > , expr : & Expr < ' _ > ) -> bool {
37- let Node :: Expr ( parent_expr) = cx. tcx . parent_hir_node ( expr. hir_id ) else {
38- return false ;
39- } ;
40- let ExprKind :: Binary ( op, lhs, rhs) = parent_expr. kind else {
41- return false ;
42- } ;
43-
44- if op. node == BinOpKind :: Eq || op. node == BinOpKind :: Ne {
37+ if let Node :: Expr ( parent_expr) = cx. tcx . parent_hir_node ( expr. hir_id )
38+ && let ExprKind :: Binary ( op, lhs, rhs) = parent_expr. kind
39+ && let BinOpKind :: Eq | BinOpKind :: Ne = op. node
40+ {
4541 let ecx = ConstEvalCtxt :: new ( cx) ;
4642 matches ! ( ecx. eval( lhs) , Some ( Constant :: Int ( 0 ) ) ) || matches ! ( ecx. eval( rhs) , Some ( Constant :: Int ( 0 ) ) )
4743 } else {
@@ -56,35 +52,28 @@ struct OperandInfo {
5652}
5753
5854fn analyze_operand ( operand : & Expr < ' _ > , cx : & LateContext < ' _ > , expr : & Expr < ' _ > ) -> Option < OperandInfo > {
59- match ConstEvalCtxt :: new ( cx) . eval ( operand) {
60- Some ( Constant :: Int ( v) ) => match * cx. typeck_results ( ) . expr_ty ( expr) . kind ( ) {
55+ match ConstEvalCtxt :: new ( cx) . eval ( operand) ? {
56+ Constant :: Int ( v) => match * cx. typeck_results ( ) . expr_ty ( expr) . kind ( ) {
6157 ty:: Int ( ity) => {
6258 let value = sext ( cx. tcx , v, ity) ;
63- return Some ( OperandInfo {
59+ Some ( OperandInfo {
6460 string_representation : Some ( value. to_string ( ) ) ,
6561 is_negative : value < 0 ,
6662 is_integral : true ,
67- } ) ;
68- } ,
69- ty:: Uint ( _) => {
70- return Some ( OperandInfo {
71- string_representation : None ,
72- is_negative : false ,
73- is_integral : true ,
74- } ) ;
63+ } )
7564 } ,
76- _ => { } ,
65+ ty:: Uint ( _) => Some ( OperandInfo {
66+ string_representation : None ,
67+ is_negative : false ,
68+ is_integral : true ,
69+ } ) ,
70+ _ => None ,
7771 } ,
7872 // FIXME(f16_f128): add when casting is available on all platforms
79- Some ( Constant :: F32 ( f) ) => {
80- return Some ( floating_point_operand_info ( & f) ) ;
81- } ,
82- Some ( Constant :: F64 ( f) ) => {
83- return Some ( floating_point_operand_info ( & f) ) ;
84- } ,
85- _ => { } ,
73+ Constant :: F32 ( f) => Some ( floating_point_operand_info ( & f) ) ,
74+ Constant :: F64 ( f) => Some ( floating_point_operand_info ( & f) ) ,
75+ _ => None ,
8676 }
87- None
8877}
8978
9079fn floating_point_operand_info < T : Display + PartialOrd + From < f32 > > ( f : & T ) -> OperandInfo {
0 commit comments