Skip to content

Commit b5587a8

Browse files
committed
Fix lint detection on macro expansion.
1 parent fc24fce commit b5587a8

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

clippy_lints/src/implicit_return.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -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() && span.macro_backtrace().is_empty() {
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 !expr.span.macro_backtrace().is_empty() {
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)