Skip to content

Commit 721f688

Browse files
committed
Auto merge of #3577 - daxpedda:master, r=flip1995
Fix false positives for `implicit_return` and `empty_loop` on macro expansion. This PR only fixes `implicit_return` and `empty_loop`. But I suspect this bug may affect a lot of other lints.
2 parents 44ffda7 + 2d96ef1 commit 721f688

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

clippy_lints/src/implicit_return.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use crate::rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
1212
use crate::rustc::{declare_tool_lint, lint_array};
1313
use crate::rustc_errors::Applicability;
1414
use crate::syntax::{ast::NodeId, source_map::Span};
15-
use crate::utils::{snippet_opt, span_lint_and_then};
15+
use crate::utils::{in_macro, snippet_opt, span_lint_and_then};
1616

1717
/// **What it does:** Checks for missing return statements at the end of a block.
1818
///
@@ -116,14 +116,15 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
116116
_: FnKind<'tcx>,
117117
_: &'tcx FnDecl,
118118
body: &'tcx Body,
119-
_: Span,
119+
span: Span,
120120
_: NodeId,
121121
) {
122122
let def_id = cx.tcx.hir().body_owner_def_id(body.id());
123123
let mir = cx.tcx.optimized_mir(def_id);
124124

125125
// checking return type through MIR, HIR is not able to determine inferred closure return types
126-
if !mir.return_ty().is_unit() {
126+
// make sure it's not a macro
127+
if !mir.return_ty().is_unit() && !in_macro(span) {
127128
Self::expr_match(cx, &body.value);
128129
}
129130
}

clippy_lints/src/loops.rs

+5
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,11 @@ impl LintPass for Pass {
478478

479479
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
480480
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
481+
// we don't want to check expanded macros
482+
if in_macro(expr.span) {
483+
return;
484+
}
485+
481486
if let Some((pat, arg, body)) = higher::for_loop(expr) {
482487
check_for_loop(cx, pat, arg, body, expr);
483488
}

0 commit comments

Comments
 (0)