about summary refs log tree commit diff
path: root/compiler/rustc_middle/src/lint.rs
diff options
context:
space:
mode:
authorNicholas Nethercote <n.nethercote@gmail.com>2025-02-02 13:54:50 +1100
committerNicholas Nethercote <n.nethercote@gmail.com>2025-02-02 13:57:34 +1100
commit06090e89d3007b4877f14267ed9cc02447332a5a (patch)
tree7a07f86870fc3606255496d8fcbdb273beae5093 /compiler/rustc_middle/src/lint.rs
parente08cd3cf05e5bfa3323cc21ea8f81f4a15a2f969 (diff)
downloadrust-06090e89d3007b4877f14267ed9cc02447332a5a.tar.gz
rust-06090e89d3007b4877f14267ed9cc02447332a5a.zip
Convert two `rustc_middle::lint` functions to `Span` methods.
`rustc_middle` is a huge crate and it's always good to move stuff out of
it. There are lots of similar methods already on `Span`, so these two
functions, `in_external_macro` and `is_from_async_await`, fit right in.
The diff is big because `in_external_macro` is used a lot by clippy
lints.
Diffstat (limited to 'compiler/rustc_middle/src/lint.rs')
-rw-r--r--compiler/rustc_middle/src/lint.rs40
1 files changed, 3 insertions, 37 deletions
diff --git a/compiler/rustc_middle/src/lint.rs b/compiler/rustc_middle/src/lint.rs
index cae980cde61..ab711aca573 100644
--- a/compiler/rustc_middle/src/lint.rs
+++ b/compiler/rustc_middle/src/lint.rs
@@ -8,8 +8,7 @@ use rustc_macros::{Decodable, Encodable, HashStable};
 use rustc_session::Session;
 use rustc_session::lint::builtin::{self, FORBIDDEN_LINT_GROUPS};
 use rustc_session::lint::{FutureIncompatibilityReason, Level, Lint, LintExpectationId, LintId};
-use rustc_span::hygiene::{ExpnKind, MacroKind};
-use rustc_span::{DUMMY_SP, DesugaringKind, Span, Symbol, kw};
+use rustc_span::{DUMMY_SP, Span, Symbol, kw};
 use tracing::instrument;
 
 use crate::ty::TyCtxt;
@@ -201,7 +200,7 @@ impl LintExpectation {
     }
 }
 
-pub fn explain_lint_level_source(
+fn explain_lint_level_source(
     lint: &'static Lint,
     level: Level,
     src: LintLevelSource,
@@ -325,7 +324,7 @@ pub fn lint_level(
         // If this code originates in a foreign macro, aka something that this crate
         // did not itself author, then it's likely that there's nothing this crate
         // can do about it. We probably want to skip the lint entirely.
-        if err.span.primary_spans().iter().any(|s| in_external_macro(sess, *s)) {
+        if err.span.primary_spans().iter().any(|s| s.in_external_macro(sess.source_map())) {
             // Any suggestions made here are likely to be incorrect, so anything we
             // emit shouldn't be automatically fixed by rustfix.
             err.disable_suggestions();
@@ -422,36 +421,3 @@ pub fn lint_level(
     }
     lint_level_impl(sess, lint, level, src, span, Box::new(decorate))
 }
-
-/// Returns whether `span` originates in a foreign crate's external macro.
-///
-/// This is used to test whether a lint should not even begin to figure out whether it should
-/// be reported on the current node.
-pub fn in_external_macro(sess: &Session, span: Span) -> bool {
-    let expn_data = span.ctxt().outer_expn_data();
-    match expn_data.kind {
-        ExpnKind::Root
-        | ExpnKind::Desugaring(
-            DesugaringKind::ForLoop
-            | DesugaringKind::WhileLoop
-            | DesugaringKind::OpaqueTy
-            | DesugaringKind::Async
-            | DesugaringKind::Await,
-        ) => false,
-        ExpnKind::AstPass(_) | ExpnKind::Desugaring(_) => true, // well, it's "external"
-        ExpnKind::Macro(MacroKind::Bang, _) => {
-            // Dummy span for the `def_site` means it's an external macro.
-            expn_data.def_site.is_dummy() || sess.source_map().is_imported(expn_data.def_site)
-        }
-        ExpnKind::Macro { .. } => true, // definitely a plugin
-    }
-}
-
-/// Return whether `span` is generated by `async` or `await`.
-pub fn is_from_async_await(span: Span) -> bool {
-    let expn_data = span.ctxt().outer_expn_data();
-    match expn_data.kind {
-        ExpnKind::Desugaring(DesugaringKind::Async | DesugaringKind::Await) => true,
-        _ => false,
-    }
-}