Skip to content

Commit 30ee440

Browse files
committed
Fix duplicate lint emmission from [else_if_without_else]
1 parent 0b4b684 commit 30ee440

File tree

3 files changed

+14
-18
lines changed

3 files changed

+14
-18
lines changed

clippy_lints/src/else_if_without_else.rs

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -49,24 +49,22 @@ declare_clippy_lint! {
4949
declare_lint_pass!(ElseIfWithoutElse => [ELSE_IF_WITHOUT_ELSE]);
5050

5151
impl EarlyLintPass for ElseIfWithoutElse {
52-
fn check_expr(&mut self, cx: &EarlyContext<'_>, mut item: &Expr) {
52+
fn check_expr(&mut self, cx: &EarlyContext<'_>, item: &Expr) {
5353
if in_external_macro(cx.sess(), item.span) {
5454
return;
5555
}
5656

57-
while let ExprKind::If(_, _, Some(ref els)) = item.kind {
58-
if let ExprKind::If(_, _, None) = els.kind {
59-
span_lint_and_help(
60-
cx,
61-
ELSE_IF_WITHOUT_ELSE,
62-
els.span,
63-
"`if` expression with an `else if`, but without a final `else`",
64-
None,
65-
"add an `else` block here",
66-
);
67-
}
68-
69-
item = els;
57+
if let ExprKind::If(_, _, Some(ref els)) = item.kind
58+
&& let ExprKind::If(_, _, None) = els.kind
59+
{
60+
span_lint_and_help(
61+
cx,
62+
ELSE_IF_WITHOUT_ELSE,
63+
els.span,
64+
"`if` expression with an `else if`, but without a final `else`",
65+
None,
66+
"add an `else` block here",
67+
);
7068
}
7169
}
7270
}

tests/ui/else_if_without_else.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
//@compile-flags: -Zdeduplicate-diagnostics=yes
2-
31
#![warn(clippy::all)]
42
#![warn(clippy::else_if_without_else)]
53

tests/ui/else_if_without_else.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: `if` expression with an `else if`, but without a final `else`
2-
--> tests/ui/else_if_without_else.rs:47:12
2+
--> tests/ui/else_if_without_else.rs:45:12
33
|
44
LL | } else if bla2() {
55
| ____________^
@@ -13,7 +13,7 @@ LL | | }
1313
= help: to override `-D warnings` add `#[allow(clippy::else_if_without_else)]`
1414

1515
error: `if` expression with an `else if`, but without a final `else`
16-
--> tests/ui/else_if_without_else.rs:56:12
16+
--> tests/ui/else_if_without_else.rs:54:12
1717
|
1818
LL | } else if bla3() {
1919
| ____________^

0 commit comments

Comments
 (0)