Skip to content

Commit 4cc7b7e

Browse files
committed
stop linting [blocks_in_conditions] on match on proc macros
1 parent 92537a0 commit 4cc7b7e

File tree

3 files changed

+4
-10
lines changed

3 files changed

+4
-10
lines changed

clippy_lints/src/blocks_in_conditions.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use clippy_utils::diagnostics::{span_lint, span_lint_and_sugg};
22
use clippy_utils::source::snippet_block_with_applicability;
33
use clippy_utils::ty::implements_trait;
44
use clippy_utils::visitors::{for_each_expr, Descend};
5-
use clippy_utils::{get_parent_expr, higher};
5+
use clippy_utils::{get_parent_expr, higher, is_from_proc_macro};
66
use core::ops::ControlFlow;
77
use rustc_errors::Applicability;
88
use rustc_hir::{BlockCheckMode, Expr, ExprKind, MatchSource};
@@ -94,7 +94,7 @@ impl<'tcx> LateLintPass<'tcx> for BlocksInConditions {
9494
}
9595
} else {
9696
let span = block.expr.as_ref().map_or_else(|| block.stmts[0].span, |e| e.span);
97-
if span.from_expansion() || expr.span.from_expansion() {
97+
if span.from_expansion() || expr.span.from_expansion() || is_from_proc_macro(cx, cond) {
9898
return;
9999
}
100100
// move block higher

tests/ui/blocks_in_conditions.fixed

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ fn issue_12162() {
104104
mod issue_12016 {
105105
#[proc_macro_attr::fake_desugar_await]
106106
pub async fn await_becomes_block() -> i32 {
107-
let res = await; match res {
107+
match Some(1).await {
108108
Some(1) => 2,
109109
Some(2) => 3,
110110
_ => 0,

tests/ui/blocks_in_conditions.stderr

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,5 @@ LL + opt
5353
LL ~ }; match res {
5454
|
5555

56-
error: in a `match` scrutinee, avoid complex blocks or closures with blocks; instead, move the block or closure higher and bind it with a `let`
57-
--> $DIR/blocks_in_conditions.rs:107:9
58-
|
59-
LL | match Some(1).await {
60-
| ^^^^^^^^^^^^^^^^^^^ help: try: `let res = await; match res`
61-
62-
error: aborting due to 5 previous errors
56+
error: aborting due to 4 previous errors
6357

0 commit comments

Comments
 (0)