@@ -109,32 +109,27 @@ impl LintKind {
109
109
110
110
impl LateLintPass < ' _ > for EndianBytes {
111
111
fn check_expr ( & mut self , cx : & LateContext < ' _ > , expr : & Expr < ' _ > ) {
112
- if in_external_macro ( cx. sess ( ) , expr. span ) {
113
- return ;
114
- }
115
-
116
- if let ExprKind :: MethodCall ( method_name, receiver, args, ..) = expr. kind
117
- && args. is_empty ( )
118
- && let ty = cx. typeck_results ( ) . expr_ty ( receiver)
112
+ let ( prefix, name, ty_expr) = match expr. kind {
113
+ ExprKind :: MethodCall ( method_name, receiver, [ ] , ..) => ( Prefix :: To , method_name. ident . name , receiver) ,
114
+ ExprKind :: Call ( function, ..)
115
+ if let ExprKind :: Path ( qpath) = function. kind
116
+ && let Some ( def_id) = cx. qpath_res ( & qpath, function. hir_id ) . opt_def_id ( )
117
+ && let Some ( function_name) = cx. get_def_path ( def_id) . last ( ) =>
118
+ {
119
+ ( Prefix :: From , * function_name, expr)
120
+ } ,
121
+ _ => return ,
122
+ } ;
123
+ if !in_external_macro ( cx. sess ( ) , expr. span )
124
+ && let ty = cx. typeck_results ( ) . expr_ty ( ty_expr)
119
125
&& ty. is_primitive_ty ( )
120
- && maybe_lint_endian_bytes ( cx, expr, Prefix :: To , method_name. ident . name , ty)
121
126
{
122
- return ;
123
- }
124
-
125
- if let ExprKind :: Call ( function, ..) = expr. kind
126
- && let ExprKind :: Path ( qpath) = function. kind
127
- && let Some ( def_id) = cx. qpath_res ( & qpath, function. hir_id ) . opt_def_id ( )
128
- && let Some ( function_name) = cx. get_def_path ( def_id) . last ( )
129
- && let ty = cx. typeck_results ( ) . expr_ty ( expr)
130
- && ty. is_primitive_ty ( )
131
- {
132
- maybe_lint_endian_bytes ( cx, expr, Prefix :: From , * function_name, ty) ;
127
+ maybe_lint_endian_bytes ( cx, expr, prefix, name, ty) ;
133
128
}
134
129
}
135
130
}
136
131
137
- fn maybe_lint_endian_bytes ( cx : & LateContext < ' _ > , expr : & Expr < ' _ > , prefix : Prefix , name : Symbol , ty : Ty < ' _ > ) -> bool {
132
+ fn maybe_lint_endian_bytes ( cx : & LateContext < ' _ > , expr : & Expr < ' _ > , prefix : Prefix , name : Symbol , ty : Ty < ' _ > ) {
138
133
let ne = LintKind :: Host . as_name ( prefix) ;
139
134
let le = LintKind :: Little . as_name ( prefix) ;
140
135
let be = LintKind :: Big . as_name ( prefix) ;
@@ -143,7 +138,7 @@ fn maybe_lint_endian_bytes(cx: &LateContext<'_>, expr: &Expr<'_>, prefix: Prefix
143
138
name if name == ne => ( ( & LintKind :: Host ) , [ ( & LintKind :: Little ) , ( & LintKind :: Big ) ] ) ,
144
139
name if name == le => ( ( & LintKind :: Little ) , [ ( & LintKind :: Host ) , ( & LintKind :: Big ) ] ) ,
145
140
name if name == be => ( ( & LintKind :: Big ) , [ ( & LintKind :: Host ) , ( & LintKind :: Little ) ] ) ,
146
- _ => return false ,
141
+ _ => return ,
147
142
} ;
148
143
149
144
let mut help = None ;
@@ -208,6 +203,4 @@ fn maybe_lint_endian_bytes(cx: &LateContext<'_>, expr: &Expr<'_>, prefix: Prefix
208
203
}
209
204
} ,
210
205
) ;
211
-
212
- true
213
206
}
0 commit comments