stop linting [blocks_in_conditions] on match on proc macros

This commit is contained in:
J-ZhengLi 2024-02-12 04:16:11 +08:00
parent 92537a0e5b
commit 4cc7b7e092
3 changed files with 4 additions and 10 deletions

View File

@ -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};
@ -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

View File

@ -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,

View File

@ -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