From b5587a894f34e77b103947d37594c91ce124a2c0 Mon Sep 17 00:00:00 2001
From: daxpedda <daxpedda@users.noreply.github.com>
Date: Mon, 24 Dec 2018 22:06:08 +0100
Subject: [PATCH 1/4] Fix lint detection on macro expansion.

---
 clippy_lints/src/implicit_return.rs | 5 +++--
 clippy_lints/src/loops.rs           | 5 +++++
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/clippy_lints/src/implicit_return.rs b/clippy_lints/src/implicit_return.rs
index 96022db56aa..ee64c01b385 100644
--- a/clippy_lints/src/implicit_return.rs
+++ b/clippy_lints/src/implicit_return.rs
@@ -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);
         }
     }
diff --git a/clippy_lints/src/loops.rs b/clippy_lints/src/loops.rs
index 7ff43bd2da2..66a54ad2443 100644
--- a/clippy_lints/src/loops.rs
+++ b/clippy_lints/src/loops.rs
@@ -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);
         }

From a77bcadaa55801cc870ef740ca0d9fa4ca45df42 Mon Sep 17 00:00:00 2001
From: daxpedda <daxpedda@users.noreply.github.com>
Date: Tue, 25 Dec 2018 12:48:54 +0100
Subject: [PATCH 2/4] Changed `macro_backtrace()` to `in_macro()`.

---
 clippy_lints/src/implicit_return.rs | 4 ++--
 clippy_lints/src/loops.rs           | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/clippy_lints/src/implicit_return.rs b/clippy_lints/src/implicit_return.rs
index ee64c01b385..912ed43aab3 100644
--- a/clippy_lints/src/implicit_return.rs
+++ b/clippy_lints/src/implicit_return.rs
@@ -12,7 +12,7 @@ use crate::rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
 use crate::rustc::{declare_tool_lint, lint_array};
 use crate::rustc_errors::Applicability;
 use crate::syntax::{ast::NodeId, source_map::Span};
-use crate::utils::{snippet_opt, span_lint_and_then};
+use crate::utils::{snippet_opt, span_lint_and_then, in_macro};
 
 /// **What it does:** Checks for missing return statements at the end of a block.
 ///
@@ -124,7 +124,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
 
         // checking return type through MIR, HIR is not able to determine inferred closure return types
         // make sure it's not a macro
-        if !mir.return_ty().is_unit() && span.macro_backtrace().is_empty() {
+        if !mir.return_ty().is_unit() && !in_macro(span) {
             Self::expr_match(cx, &body.value);
         }
     }
diff --git a/clippy_lints/src/loops.rs b/clippy_lints/src/loops.rs
index 66a54ad2443..66f85e88398 100644
--- a/clippy_lints/src/loops.rs
+++ b/clippy_lints/src/loops.rs
@@ -479,7 +479,7 @@ 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() {
+        if !in_macro(expr.span) {
             return;
         }
 

From 197914439ac0354f48c35a8eb2b6c43a6999f7fc Mon Sep 17 00:00:00 2001
From: Philipp Krones <hello@philkrones.com>
Date: Tue, 25 Dec 2018 12:57:16 +0100
Subject: [PATCH 3/4] Fix macro detection in `empty_loop`.

Co-Authored-By: daxpedda <1645124+daxpedda@users.noreply.github.com>
---
 clippy_lints/src/loops.rs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clippy_lints/src/loops.rs b/clippy_lints/src/loops.rs
index 66f85e88398..8664061fb7a 100644
--- a/clippy_lints/src/loops.rs
+++ b/clippy_lints/src/loops.rs
@@ -479,7 +479,7 @@ 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 !in_macro(expr.span) {
+        if in_macro(expr.span) {
             return;
         }
 

From 2d96ef1315ebf933be79533c6c39ec2e3d7d1b85 Mon Sep 17 00:00:00 2001
From: daxpedda <daxpedda@users.noreply.github.com>
Date: Wed, 26 Dec 2018 18:13:33 +0100
Subject: [PATCH 4/4] Rustfmt.

---
 clippy_lints/src/implicit_return.rs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clippy_lints/src/implicit_return.rs b/clippy_lints/src/implicit_return.rs
index 912ed43aab3..dc1869ae04e 100644
--- a/clippy_lints/src/implicit_return.rs
+++ b/clippy_lints/src/implicit_return.rs
@@ -12,7 +12,7 @@ use crate::rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
 use crate::rustc::{declare_tool_lint, lint_array};
 use crate::rustc_errors::Applicability;
 use crate::syntax::{ast::NodeId, source_map::Span};
-use crate::utils::{snippet_opt, span_lint_and_then, in_macro};
+use crate::utils::{in_macro, snippet_opt, span_lint_and_then};
 
 /// **What it does:** Checks for missing return statements at the end of a block.
 ///