about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2022-01-05 00:49:23 +0000
committerbors <bors@rust-lang.org>2022-01-05 00:49:23 +0000
commitd5dcda2f42cf398df3e3fb486a1b54ee8eba5bf2 (patch)
treedbd2b27132aaa94fa10448daa06e0f0a38d603ba
parentba03dc70fd219273934b4fa3280ccaf7bb0dcd9b (diff)
parent00da1b8f14989b57e56ed28da177b5819a2b53f9 (diff)
downloadrust-d5dcda2f42cf398df3e3fb486a1b54ee8eba5bf2.tar.gz
rust-d5dcda2f42cf398df3e3fb486a1b54ee8eba5bf2.zip
Auto merge of #8223 - camsteffen:remove-in-macro, r=llogiq
Remove in_macro from clippy_utils

changelog: none

Previously done in #7897 but reverted in #8170. I'd like to keep `in_macro` out of utils because if a span is from expansion in any way (desugaring or macro), we should not proceed without understanding the nature of the expansion IMO.

r? `@llogiq`
-rw-r--r--clippy_lints/src/init_numbered_fields.rs3
-rw-r--r--clippy_lints/src/macro_use.rs6
-rw-r--r--clippy_utils/src/lib.rs7
3 files changed, 6 insertions, 10 deletions
diff --git a/clippy_lints/src/init_numbered_fields.rs b/clippy_lints/src/init_numbered_fields.rs
index 5fe6725b581..9284e002409 100644
--- a/clippy_lints/src/init_numbered_fields.rs
+++ b/clippy_lints/src/init_numbered_fields.rs
@@ -1,5 +1,4 @@
 use clippy_utils::diagnostics::span_lint_and_sugg;
-use clippy_utils::in_macro;
 use clippy_utils::source::snippet_with_applicability;
 use rustc_errors::Applicability;
 use rustc_hir::{Expr, ExprKind};
@@ -46,7 +45,7 @@ impl<'tcx> LateLintPass<'tcx> for NumberedFields {
     fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) {
         if let ExprKind::Struct(path, fields, None) = e.kind {
             if !fields.is_empty()
-                && !in_macro(e.span)
+                && !e.span.from_expansion()
                 && fields
                     .iter()
                     .all(|f| f.ident.as_str().as_bytes().iter().all(u8::is_ascii_digit))
diff --git a/clippy_lints/src/macro_use.rs b/clippy_lints/src/macro_use.rs
index bbc14fc535d..262a26951c6 100644
--- a/clippy_lints/src/macro_use.rs
+++ b/clippy_lints/src/macro_use.rs
@@ -1,5 +1,4 @@
 use clippy_utils::diagnostics::span_lint_and_sugg;
-use clippy_utils::in_macro;
 use clippy_utils::source::snippet;
 use hir::def::{DefKind, Res};
 use if_chain::if_chain;
@@ -9,6 +8,7 @@ use rustc_errors::Applicability;
 use rustc_hir as hir;
 use rustc_lint::{LateContext, LateLintPass, LintContext};
 use rustc_session::{declare_tool_lint, impl_lint_pass};
+use rustc_span::hygiene::ExpnKind;
 use rustc_span::{edition::Edition, sym, Span};
 
 declare_clippy_lint! {
@@ -214,3 +214,7 @@ impl<'tcx> LateLintPass<'tcx> for MacroUseImports {
         }
     }
 }
+
+fn in_macro(span: Span) -> bool {
+    span.from_expansion() && !matches!(span.ctxt().outer_expn_data().kind, ExpnKind::Desugaring(..))
+}
diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs
index 52e28a5679c..16bcffb8df9 100644
--- a/clippy_utils/src/lib.rs
+++ b/clippy_utils/src/lib.rs
@@ -148,13 +148,6 @@ macro_rules! extract_msrv_attr {
     };
 }
 
-/// Returns `true` if the span comes from a macro expansion, no matter if from a
-/// macro by example or from a procedural macro
-#[must_use]
-pub fn in_macro(span: Span) -> bool {
-    span.from_expansion() && !matches!(span.ctxt().outer_expn_data().kind, ExpnKind::Desugaring(..))
-}
-
 /// Returns `true` if the two spans come from differing expansions (i.e., one is
 /// from a macro and one isn't).
 #[must_use]