@@ -34,14 +34,10 @@ pub(super) fn check<'tcx>(
34
34
}
35
35
36
36
fn 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
+ {
45
41
let ecx = ConstEvalCtxt :: new ( cx) ;
46
42
matches ! ( ecx. eval( lhs) , Some ( Constant :: Int ( 0 ) ) ) || matches ! ( ecx. eval( rhs) , Some ( Constant :: Int ( 0 ) ) )
47
43
} else {
@@ -56,35 +52,28 @@ struct OperandInfo {
56
52
}
57
53
58
54
fn 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 ( ) {
61
57
ty:: Int ( ity) => {
62
58
let value = sext ( cx. tcx , v, ity) ;
63
- return Some ( OperandInfo {
59
+ Some ( OperandInfo {
64
60
string_representation : Some ( value. to_string ( ) ) ,
65
61
is_negative : value < 0 ,
66
62
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
+ } )
75
64
} ,
76
- _ => { } ,
65
+ ty:: Uint ( _) => Some ( OperandInfo {
66
+ string_representation : None ,
67
+ is_negative : false ,
68
+ is_integral : true ,
69
+ } ) ,
70
+ _ => None ,
77
71
} ,
78
72
// 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 ,
86
76
}
87
- None
88
77
}
89
78
90
79
fn floating_point_operand_info < T : Display + PartialOrd + From < f32 > > ( f : & T ) -> OperandInfo {
0 commit comments