Fix lint detection on macro expansion.

This commit is contained in:
daxpedda 2018-12-24 22:06:08 +01:00
parent fc24fce73f
commit b5587a894f
No known key found for this signature in database
GPG Key ID: C722DCB6A191EEAB
2 changed files with 8 additions and 2 deletions

View File

@ -116,14 +116,15 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
_: FnKind<'tcx>,
_: &'tcx FnDecl,
body: &'tcx Body,
_: Span,
span: Span,
_: NodeId,
) {
let def_id = cx.tcx.hir().body_owner_def_id(body.id());
let mir = cx.tcx.optimized_mir(def_id);
// checking return type through MIR, HIR is not able to determine inferred closure return types
if !mir.return_ty().is_unit() {
// make sure it's not a macro
if !mir.return_ty().is_unit() && span.macro_backtrace().is_empty() {
Self::expr_match(cx, &body.value);
}
}

View File

@ -478,6 +478,11 @@ impl LintPass for Pass {
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
// we don't want to check expanded macros
if !expr.span.macro_backtrace().is_empty() {
return;
}
if let Some((pat, arg, body)) = higher::for_loop(expr) {
check_for_loop(cx, pat, arg, body, expr);
}