Skip to content

Commit

Permalink
stop linting [blocks_in_conditions] on match on proc macros
Browse files Browse the repository at this point in the history
  • Loading branch information
J-ZhengLi committed Feb 11, 2024
1 parent 92537a0 commit 4cc7b7e
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 10 deletions.
4 changes: 2 additions & 2 deletions clippy_lints/src/blocks_in_conditions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use clippy_utils::diagnostics::{span_lint, span_lint_and_sugg};
use clippy_utils::source::snippet_block_with_applicability;
use clippy_utils::ty::implements_trait;
use clippy_utils::visitors::{for_each_expr, Descend};
use clippy_utils::{get_parent_expr, higher};
use clippy_utils::{get_parent_expr, higher, is_from_proc_macro};
use core::ops::ControlFlow;
use rustc_errors::Applicability;
use rustc_hir::{BlockCheckMode, Expr, ExprKind, MatchSource};
Expand Down Expand Up @@ -94,7 +94,7 @@ impl<'tcx> LateLintPass<'tcx> for BlocksInConditions {
}
} else {
let span = block.expr.as_ref().map_or_else(|| block.stmts[0].span, |e| e.span);
if span.from_expansion() || expr.span.from_expansion() {
if span.from_expansion() || expr.span.from_expansion() || is_from_proc_macro(cx, cond) {
return;
}
// move block higher
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/blocks_in_conditions.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ fn issue_12162() {
mod issue_12016 {
#[proc_macro_attr::fake_desugar_await]
pub async fn await_becomes_block() -> i32 {
let res = await; match res {
match Some(1).await {
Some(1) => 2,
Some(2) => 3,
_ => 0,
Expand Down
8 changes: 1 addition & 7 deletions tests/ui/blocks_in_conditions.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,5 @@ LL + opt
LL ~ }; match res {
|

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`
--> $DIR/blocks_in_conditions.rs:107:9
|
LL | match Some(1).await {
| ^^^^^^^^^^^^^^^^^^^ help: try: `let res = await; match res`

error: aborting due to 5 previous errors
error: aborting due to 4 previous errors

0 comments on commit 4cc7b7e

Please sign in to comment.