Skip to content

Commit ff4e62d

Browse files
committed
len_zero: Check HIR tree first
1 parent a413281 commit ff4e62d

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

clippy_lints/src/len_zero.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,9 @@ declare_lint_pass!(LenZero => [LEN_ZERO, LEN_WITHOUT_IS_EMPTY, COMPARISON_TO_EMP
121121

122122
impl<'tcx> LateLintPass<'tcx> for LenZero {
123123
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) {
124-
if item.span.from_expansion() {
125-
return;
126-
}
127-
128-
if let ItemKind::Trait(_, _, _, _, trait_items) = item.kind {
124+
if let ItemKind::Trait(_, _, _, _, trait_items) = item.kind
125+
&& !item.span.from_expansion()
126+
{
129127
check_trait_items(cx, item, trait_items);
130128
}
131129
}
@@ -162,17 +160,14 @@ impl<'tcx> LateLintPass<'tcx> for LenZero {
162160
}
163161

164162
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
165-
if expr.span.from_expansion() {
166-
return;
167-
}
168-
169163
if let ExprKind::Let(lt) = expr.kind
170-
&& has_is_empty(cx, lt.init)
171164
&& match lt.pat.kind {
172165
PatKind::Slice([], None, []) => true,
173166
PatKind::Lit(lit) if is_empty_string(lit) => true,
174167
_ => false,
175168
}
169+
&& !expr.span.from_expansion()
170+
&& has_is_empty(cx, lt.init)
176171
{
177172
let mut applicability = Applicability::MachineApplicable;
178173

@@ -190,7 +185,9 @@ impl<'tcx> LateLintPass<'tcx> for LenZero {
190185
);
191186
}
192187

193-
if let ExprKind::Binary(Spanned { node: cmp, .. }, left, right) = expr.kind {
188+
if let ExprKind::Binary(Spanned { node: cmp, .. }, left, right) = expr.kind
189+
&& !expr.span.from_expansion()
190+
{
194191
// expr.span might contains parenthesis, see issue #10529
195192
let actual_span = span_without_enclosing_paren(cx, expr.span);
196193
match cmp {

0 commit comments

Comments
 (0)