1
Fork 0

Rollup merge of #136422 - nnethercote:convert-lint-functions, r=Noratrieb

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.

r? ``@Noratrieb``
This commit is contained in:
Matthias Krüger 2025-02-02 18:05:24 +01:00 committed by GitHub
commit 5bc5827636
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
102 changed files with 179 additions and 278 deletions

View file

@ -50,7 +50,6 @@ use rustc_infer::traits::{
IfExpressionCause, MatchExpressionArmCause, Obligation, PredicateObligation, IfExpressionCause, MatchExpressionArmCause, Obligation, PredicateObligation,
PredicateObligations, PredicateObligations,
}; };
use rustc_middle::lint::in_external_macro;
use rustc_middle::span_bug; use rustc_middle::span_bug;
use rustc_middle::traits::BuiltinImplSource; use rustc_middle::traits::BuiltinImplSource;
use rustc_middle::ty::adjustment::{ use rustc_middle::ty::adjustment::{
@ -1937,7 +1936,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
cond_expr.span.desugaring_kind(), cond_expr.span.desugaring_kind(),
None | Some(DesugaringKind::WhileLoop) None | Some(DesugaringKind::WhileLoop)
) )
&& !in_external_macro(fcx.tcx.sess, cond_expr.span) && !cond_expr.span.in_external_macro(fcx.tcx.sess.source_map())
&& !matches!( && !matches!(
cond_expr.kind, cond_expr.kind,
hir::ExprKind::Match(.., hir::MatchSource::TryDesugar(_)) hir::ExprKind::Match(.., hir::MatchSource::TryDesugar(_))

View file

@ -14,7 +14,6 @@ use rustc_hir::{
}; };
use rustc_hir_analysis::hir_ty_lowering::HirTyLowerer; use rustc_hir_analysis::hir_ty_lowering::HirTyLowerer;
use rustc_hir_analysis::suggest_impl_trait; use rustc_hir_analysis::suggest_impl_trait;
use rustc_middle::lint::in_external_macro;
use rustc_middle::middle::stability::EvalResult; use rustc_middle::middle::stability::EvalResult;
use rustc_middle::span_bug; use rustc_middle::span_bug;
use rustc_middle::ty::print::with_no_trimmed_paths; use rustc_middle::ty::print::with_no_trimmed_paths;
@ -770,7 +769,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// If the expression is from an external macro, then do not suggest // If the expression is from an external macro, then do not suggest
// adding a semicolon, because there's nowhere to put it. // adding a semicolon, because there's nowhere to put it.
// See issue #81943. // See issue #81943.
&& !in_external_macro(self.tcx.sess, expression.span) => && !expression.span.in_external_macro(self.tcx.sess.source_map()) =>
{ {
if needs_block { if needs_block {
err.multipart_suggestion( err.multipart_suggestion(
@ -2261,7 +2260,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
expected: Ty<'tcx>, expected: Ty<'tcx>,
expr_ty: Ty<'tcx>, expr_ty: Ty<'tcx>,
) -> bool { ) -> bool {
if in_external_macro(self.tcx.sess, expr.span) { if expr.span.in_external_macro(self.tcx.sess.source_map()) {
return false; return false;
} }
if let ty::Adt(expected_adt, args) = expected.kind() { if let ty::Adt(expected_adt, args) = expected.kind() {
@ -2589,14 +2588,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
)> { )> {
let sess = self.sess(); let sess = self.sess();
let sp = expr.span; let sp = expr.span;
let sm = sess.source_map();
// If the span is from an external macro, there's no suggestion we can make. // If the span is from an external macro, there's no suggestion we can make.
if in_external_macro(sess, sp) { if sp.in_external_macro(sm) {
return None; return None;
} }
let sm = sess.source_map();
let replace_prefix = |s: &str, old: &str, new: &str| { let replace_prefix = |s: &str, old: &str, new: &str| {
s.strip_prefix(old).map(|stripped| new.to_string() + stripped) s.strip_prefix(old).map(|stripped| new.to_string() + stripped)
}; };

View file

@ -29,7 +29,6 @@ use rustc_hir::def_id::{CRATE_DEF_ID, DefId, LocalDefId};
use rustc_hir::intravisit::FnKind as HirFnKind; use rustc_hir::intravisit::FnKind as HirFnKind;
use rustc_hir::{Body, FnDecl, GenericParamKind, PatKind, PredicateOrigin}; use rustc_hir::{Body, FnDecl, GenericParamKind, PatKind, PredicateOrigin};
use rustc_middle::bug; use rustc_middle::bug;
use rustc_middle::lint::in_external_macro;
use rustc_middle::ty::layout::LayoutOf; use rustc_middle::ty::layout::LayoutOf;
use rustc_middle::ty::print::with_no_trimmed_paths; use rustc_middle::ty::print::with_no_trimmed_paths;
use rustc_middle::ty::{self, Ty, TyCtxt, TypeVisitableExt, Upcast, VariantDef}; use rustc_middle::ty::{self, Ty, TyCtxt, TypeVisitableExt, Upcast, VariantDef};
@ -2029,7 +2028,7 @@ impl ExplicitOutlivesRequirements {
} }
let span = bound.span().find_ancestor_inside(predicate_span)?; let span = bound.span().find_ancestor_inside(predicate_span)?;
if in_external_macro(tcx.sess, span) { if span.in_external_macro(tcx.sess.source_map()) {
return None; return None;
} }

View file

@ -135,7 +135,7 @@ pub(super) fn unexpected_cfg_name(
}; };
let is_from_cargo = rustc_session::utils::was_invoked_from_cargo(); let is_from_cargo = rustc_session::utils::was_invoked_from_cargo();
let is_from_external_macro = rustc_middle::lint::in_external_macro(sess, name_span); let is_from_external_macro = name_span.in_external_macro(sess.source_map());
let mut is_feature_cfg = name == sym::feature; let mut is_feature_cfg = name == sym::feature;
let code_sugg = if is_feature_cfg && is_from_cargo { let code_sugg = if is_feature_cfg && is_from_cargo {
@ -281,7 +281,7 @@ pub(super) fn unexpected_cfg_value(
.collect(); .collect();
let is_from_cargo = rustc_session::utils::was_invoked_from_cargo(); let is_from_cargo = rustc_session::utils::was_invoked_from_cargo();
let is_from_external_macro = rustc_middle::lint::in_external_macro(sess, name_span); let is_from_external_macro = name_span.in_external_macro(sess.source_map());
// Show the full list if all possible values for a given name, but don't do it // Show the full list if all possible values for a given name, but don't do it
// for names as the possibilities could be very long // for names as the possibilities could be very long

View file

@ -2,7 +2,6 @@ use rustc_ast as ast;
use rustc_errors::Applicability; use rustc_errors::Applicability;
use rustc_hir::{self as hir, LangItem}; use rustc_hir::{self as hir, LangItem};
use rustc_infer::infer::TyCtxtInferExt; use rustc_infer::infer::TyCtxtInferExt;
use rustc_middle::lint::in_external_macro;
use rustc_middle::{bug, ty}; use rustc_middle::{bug, ty};
use rustc_parse_format::{ParseMode, Parser, Piece}; use rustc_parse_format::{ParseMode, Parser, Piece};
use rustc_session::lint::FutureIncompatibilityReason; use rustc_session::lint::FutureIncompatibilityReason;
@ -100,7 +99,7 @@ fn check_panic<'tcx>(cx: &LateContext<'tcx>, f: &'tcx hir::Expr<'tcx>, arg: &'tc
let (span, panic, symbol) = panic_call(cx, f); let (span, panic, symbol) = panic_call(cx, f);
if in_external_macro(cx.sess(), span) { if span.in_external_macro(cx.sess().source_map()) {
// Nothing that can be done about it in the current crate. // Nothing that can be done about it in the current crate.
return; return;
} }
@ -229,14 +228,15 @@ fn check_panic_str<'tcx>(
let (span, _, _) = panic_call(cx, f); let (span, _, _) = panic_call(cx, f);
if in_external_macro(cx.sess(), span) && in_external_macro(cx.sess(), arg.span) { let sm = cx.sess().source_map();
if span.in_external_macro(sm) && arg.span.in_external_macro(sm) {
// Nothing that can be done about it in the current crate. // Nothing that can be done about it in the current crate.
return; return;
} }
let fmt_span = arg.span.source_callsite(); let fmt_span = arg.span.source_callsite();
let (snippet, style) = match cx.sess().psess.source_map().span_to_snippet(fmt_span) { let (snippet, style) = match sm.span_to_snippet(fmt_span) {
Ok(snippet) => { Ok(snippet) => {
// Count the number of `#`s between the `r` and `"`. // Count the number of `#`s between the `r` and `"`.
let style = snippet.strip_prefix('r').and_then(|s| s.find('"')); let style = snippet.strip_prefix('r').and_then(|s| s.find('"'));
@ -283,7 +283,7 @@ fn check_panic_str<'tcx>(
/// Given the span of `some_macro!(args);`, gives the span of `(` and `)`, /// Given the span of `some_macro!(args);`, gives the span of `(` and `)`,
/// and the type of (opening) delimiter used. /// and the type of (opening) delimiter used.
fn find_delimiters(cx: &LateContext<'_>, span: Span) -> Option<(Span, Span, char)> { fn find_delimiters(cx: &LateContext<'_>, span: Span) -> Option<(Span, Span, char)> {
let snippet = cx.sess().psess.source_map().span_to_snippet(span).ok()?; let snippet = cx.sess().source_map().span_to_snippet(span).ok()?;
let (open, open_ch) = snippet.char_indices().find(|&(_, c)| "([{".contains(c))?; let (open, open_ch) = snippet.char_indices().find(|&(_, c)| "([{".contains(c))?;
let close = snippet.rfind(|c| ")]}".contains(c))?; let close = snippet.rfind(|c| ")]}".contains(c))?;
Some(( Some((

View file

@ -8,8 +8,7 @@ use rustc_macros::{Decodable, Encodable, HashStable};
use rustc_session::Session; use rustc_session::Session;
use rustc_session::lint::builtin::{self, FORBIDDEN_LINT_GROUPS}; use rustc_session::lint::builtin::{self, FORBIDDEN_LINT_GROUPS};
use rustc_session::lint::{FutureIncompatibilityReason, Level, Lint, LintExpectationId, LintId}; use rustc_session::lint::{FutureIncompatibilityReason, Level, Lint, LintExpectationId, LintId};
use rustc_span::hygiene::{ExpnKind, MacroKind}; use rustc_span::{DUMMY_SP, Span, Symbol, kw};
use rustc_span::{DUMMY_SP, DesugaringKind, Span, Symbol, kw};
use tracing::instrument; use tracing::instrument;
use crate::ty::TyCtxt; use crate::ty::TyCtxt;
@ -201,7 +200,7 @@ impl LintExpectation {
} }
} }
pub fn explain_lint_level_source( fn explain_lint_level_source(
lint: &'static Lint, lint: &'static Lint,
level: Level, level: Level,
src: LintLevelSource, src: LintLevelSource,
@ -325,7 +324,7 @@ pub fn lint_level(
// If this code originates in a foreign macro, aka something that this crate // 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 // 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. // 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 // Any suggestions made here are likely to be incorrect, so anything we
// emit shouldn't be automatically fixed by rustfix. // emit shouldn't be automatically fixed by rustfix.
err.disable_suggestions(); err.disable_suggestions();
@ -422,36 +421,3 @@ pub fn lint_level(
} }
lint_level_impl(sess, lint, level, src, span, Box::new(decorate)) 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,
}
}

View file

@ -600,11 +600,43 @@ impl Span {
!self.is_dummy() && sm.is_span_accessible(self) !self.is_dummy() && sm.is_span_accessible(self)
} }
/// 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(self, sm: &SourceMap) -> bool {
let expn_data = self.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() || sm.is_imported(expn_data.def_site)
}
ExpnKind::Macro { .. } => true, // definitely a plugin
}
}
/// Returns `true` if `span` originates in a derive-macro's expansion. /// Returns `true` if `span` originates in a derive-macro's expansion.
pub fn in_derive_expansion(self) -> bool { pub fn in_derive_expansion(self) -> bool {
matches!(self.ctxt().outer_expn_data().kind, ExpnKind::Macro(MacroKind::Derive, _)) matches!(self.ctxt().outer_expn_data().kind, ExpnKind::Macro(MacroKind::Derive, _))
} }
/// Return whether `span` is generated by `async` or `await`.
pub fn is_from_async_await(self) -> bool {
matches!(
self.ctxt().outer_expn_data().kind,
ExpnKind::Desugaring(DesugaringKind::Async | DesugaringKind::Await),
)
}
/// Gate suggestions that would not be appropriate in a context the user didn't write. /// Gate suggestions that would not be appropriate in a context the user didn't write.
pub fn can_be_used_for_suggestions(self) -> bool { pub fn can_be_used_for_suggestions(self) -> bool {
!self.from_expansion() !self.from_expansion()

View file

@ -788,7 +788,7 @@ don't hesitate to ask on [Zulip] or in the issue/PR.
[`snippet`]: https://doc.rust-lang.org/nightly/nightly-rustc/clippy_utils/source/fn.snippet.html [`snippet`]: https://doc.rust-lang.org/nightly/nightly-rustc/clippy_utils/source/fn.snippet.html
[let-chains]: https://github.com/rust-lang/rust/pull/94927 [let-chains]: https://github.com/rust-lang/rust/pull/94927
[from_expansion]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_span/struct.Span.html#method.from_expansion [from_expansion]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_span/struct.Span.html#method.from_expansion
[in_external_macro]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/lint/fn.in_external_macro.html [in_external_macro]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_span/struct.Span.html#method.in_external_macro
[span]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_span/struct.Span.html [span]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_span/struct.Span.html
[applicability]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_errors/enum.Applicability.html [applicability]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_errors/enum.Applicability.html
[rustc-dev-guide]: https://rustc-dev-guide.rust-lang.org/ [rustc-dev-guide]: https://rustc-dev-guide.rust-lang.org/

View file

@ -218,7 +218,7 @@ functions to deal with macros:
> context. And so just using `span.from_expansion()` is often good enough. > context. And so just using `span.from_expansion()` is often good enough.
- `in_external_macro(span)`: detect if the given span is from a macro defined in - `span.in_external_macro(sm)`: detect if the given span is from a macro defined in
a foreign crate. If you want the lint to work with macro-generated code, this a foreign crate. If you want the lint to work with macro-generated code, this
is the next line of defense to avoid macros not defined in the current crate. is the next line of defense to avoid macros not defined in the current crate.
It doesn't make sense to lint code that the coder can't change. It doesn't make sense to lint code that the coder can't change.
@ -227,15 +227,13 @@ functions to deal with macros:
crates crates
```rust ```rust
use rustc_middle::lint::in_external_macro;
use a_crate_with_macros::foo; use a_crate_with_macros::foo;
// `foo` is defined in `a_crate_with_macros` // `foo` is defined in `a_crate_with_macros`
foo!("bar"); foo!("bar");
// if we lint the `match` of `foo` call and test its span // if we lint the `match` of `foo` call and test its span
assert_eq!(in_external_macro(cx.sess(), match_span), true); assert_eq!(match_span.in_external_macro(cx.sess().source_map()), true);
``` ```
- `span.ctxt()`: the span's context represents whether it is from expansion, and - `span.ctxt()`: the span's context represents whether it is from expansion, and

View file

@ -120,7 +120,7 @@ assert_ne!(x_is_some_span.ctxt(), x_unwrap_span.ctxt());
### The `in_external_macro` function ### The `in_external_macro` function
`rustc_middle::lint` provides a function ([`in_external_macro`]) that can `Span` provides a method ([`in_external_macro`]) that can
detect if the given span is from a macro defined in a foreign crate. detect if the given span is from a macro defined in a foreign crate.
Therefore, if we really want a new lint to work with macro-generated code, Therefore, if we really want a new lint to work with macro-generated code,
@ -144,7 +144,7 @@ Also assume that we get the corresponding variable `foo_span` for the
results in `true` (note that `cx` can be `EarlyContext` or `LateContext`): results in `true` (note that `cx` can be `EarlyContext` or `LateContext`):
```rust ```rust
if in_external_macro(cx.sess(), foo_span) { if foo_span.in_external_macro(cx.sess().source_map()) {
// We should ignore macro from a foreign crate. // We should ignore macro from a foreign crate.
return; return;
} }
@ -153,6 +153,6 @@ if in_external_macro(cx.sess(), foo_span) {
[`ctxt`]: https://doc.rust-lang.org/stable/nightly-rustc/rustc_span/struct.Span.html#method.ctxt [`ctxt`]: https://doc.rust-lang.org/stable/nightly-rustc/rustc_span/struct.Span.html#method.ctxt
[expansion]: https://rustc-dev-guide.rust-lang.org/macro-expansion.html#expansion-and-ast-integration [expansion]: https://rustc-dev-guide.rust-lang.org/macro-expansion.html#expansion-and-ast-integration
[`from_expansion`]: https://doc.rust-lang.org/stable/nightly-rustc/rustc_span/struct.Span.html#method.from_expansion [`from_expansion`]: https://doc.rust-lang.org/stable/nightly-rustc/rustc_span/struct.Span.html#method.from_expansion
[`in_external_macro`]: https://doc.rust-lang.org/stable/nightly-rustc/rustc_middle/lint/fn.in_external_macro.html [`in_external_macro`]: https://doc.rust-lang.org/stable/nightly-rustc/rustc_span/struct.Span.html#method.in_external_macro
[Span]: https://doc.rust-lang.org/stable/nightly-rustc/rustc_span/struct.Span.html [Span]: https://doc.rust-lang.org/stable/nightly-rustc/rustc_span/struct.Span.html
[SyntaxContext]: https://doc.rust-lang.org/stable/nightly-rustc/rustc_span/hygiene/struct.SyntaxContext.html [SyntaxContext]: https://doc.rust-lang.org/stable/nightly-rustc/rustc_span/hygiene/struct.SyntaxContext.html

View file

@ -5,7 +5,6 @@ use clippy_utils::source::{trim_span, walk_span_to_context};
use rustc_ast::ast::{Expr, ExprKind, LitKind, Pat, PatKind, RangeEnd, RangeLimits}; use rustc_ast::ast::{Expr, ExprKind, LitKind, Pat, PatKind, RangeEnd, RangeLimits};
use rustc_errors::Applicability; use rustc_errors::Applicability;
use rustc_lint::{EarlyContext, EarlyLintPass, LintContext}; use rustc_lint::{EarlyContext, EarlyLintPass, LintContext};
use rustc_middle::lint::in_external_macro;
use rustc_session::impl_lint_pass; use rustc_session::impl_lint_pass;
declare_clippy_lint! { declare_clippy_lint! {
@ -45,7 +44,7 @@ impl EarlyLintPass for AlmostCompleteRange {
fn check_expr(&mut self, cx: &EarlyContext<'_>, e: &Expr) { fn check_expr(&mut self, cx: &EarlyContext<'_>, e: &Expr) {
if let ExprKind::Range(Some(start), Some(end), RangeLimits::HalfOpen) = &e.kind if let ExprKind::Range(Some(start), Some(end), RangeLimits::HalfOpen) = &e.kind
&& is_incomplete_range(start, end) && is_incomplete_range(start, end)
&& !in_external_macro(cx.sess(), e.span) && !e.span.in_external_macro(cx.sess().source_map())
{ {
span_lint_and_then( span_lint_and_then(
cx, cx,
@ -74,7 +73,7 @@ impl EarlyLintPass for AlmostCompleteRange {
if let PatKind::Range(Some(start), Some(end), kind) = &p.kind if let PatKind::Range(Some(start), Some(end), kind) = &p.kind
&& matches!(kind.node, RangeEnd::Excluded) && matches!(kind.node, RangeEnd::Excluded)
&& is_incomplete_range(start, end) && is_incomplete_range(start, end)
&& !in_external_macro(cx.sess(), p.span) && !p.span.in_external_macro(cx.sess().source_map())
{ {
span_lint_and_then( span_lint_and_then(
cx, cx,

View file

@ -9,7 +9,6 @@ use rustc_hir::{
Variant, VariantData, Variant, VariantData,
}; };
use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_lint::{LateContext, LateLintPass, LintContext};
use rustc_middle::lint::in_external_macro;
use rustc_session::impl_lint_pass; use rustc_session::impl_lint_pass;
declare_clippy_lint! { declare_clippy_lint! {
@ -248,7 +247,7 @@ impl<'tcx> LateLintPass<'tcx> for ArbitrarySourceItemOrdering {
ItemKind::Enum(enum_def, _generics) if self.enable_ordering_for_enum => { ItemKind::Enum(enum_def, _generics) if self.enable_ordering_for_enum => {
let mut cur_v: Option<&Variant<'_>> = None; let mut cur_v: Option<&Variant<'_>> = None;
for variant in enum_def.variants { for variant in enum_def.variants {
if in_external_macro(cx.sess(), variant.span) { if variant.span.in_external_macro(cx.sess().source_map()) {
continue; continue;
} }
@ -263,7 +262,7 @@ impl<'tcx> LateLintPass<'tcx> for ArbitrarySourceItemOrdering {
ItemKind::Struct(VariantData::Struct { fields, .. }, _generics) if self.enable_ordering_for_struct => { ItemKind::Struct(VariantData::Struct { fields, .. }, _generics) if self.enable_ordering_for_struct => {
let mut cur_f: Option<&FieldDef<'_>> = None; let mut cur_f: Option<&FieldDef<'_>> = None;
for field in *fields { for field in *fields {
if in_external_macro(cx.sess(), field.span) { if field.span.in_external_macro(cx.sess().source_map()) {
continue; continue;
} }
@ -281,7 +280,7 @@ impl<'tcx> LateLintPass<'tcx> for ArbitrarySourceItemOrdering {
let mut cur_t: Option<&TraitItemRef> = None; let mut cur_t: Option<&TraitItemRef> = None;
for item in *item_ref { for item in *item_ref {
if in_external_macro(cx.sess(), item.span) { if item.span.in_external_macro(cx.sess().source_map()) {
continue; continue;
} }
@ -304,7 +303,7 @@ impl<'tcx> LateLintPass<'tcx> for ArbitrarySourceItemOrdering {
let mut cur_t: Option<&ImplItemRef> = None; let mut cur_t: Option<&ImplItemRef> = None;
for item in trait_impl.items { for item in trait_impl.items {
if in_external_macro(cx.sess(), item.span) { if item.span.in_external_macro(cx.sess().source_map()) {
continue; continue;
} }
@ -348,7 +347,7 @@ impl<'tcx> LateLintPass<'tcx> for ArbitrarySourceItemOrdering {
// as no sorting by source map/line of code has to be applied. // as no sorting by source map/line of code has to be applied.
// //
for item in items { for item in items {
if in_external_macro(cx.sess(), item.span) { if item.span.in_external_macro(cx.sess().source_map()) {
continue; continue;
} }

View file

@ -2,7 +2,6 @@ use clippy_utils::diagnostics::span_lint_and_then;
use clippy_utils::is_from_proc_macro; use clippy_utils::is_from_proc_macro;
use rustc_hir::{Expr, ExprKind}; use rustc_hir::{Expr, ExprKind};
use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_lint::{LateContext, LateLintPass, LintContext};
use rustc_middle::lint::in_external_macro;
use rustc_session::declare_lint_pass; use rustc_session::declare_lint_pass;
declare_clippy_lint! { declare_clippy_lint! {
@ -49,7 +48,7 @@ declare_lint_pass!(AsConversions => [AS_CONVERSIONS]);
impl<'tcx> LateLintPass<'tcx> for AsConversions { impl<'tcx> LateLintPass<'tcx> for AsConversions {
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &Expr<'tcx>) { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &Expr<'tcx>) {
if let ExprKind::Cast(_, _) = expr.kind if let ExprKind::Cast(_, _) = expr.kind
&& !in_external_macro(cx.sess(), expr.span) && !expr.span.in_external_macro(cx.sess().source_map())
&& !is_from_proc_macro(cx, expr) && !is_from_proc_macro(cx, expr)
{ {
#[expect(clippy::collapsible_span_lint_calls, reason = "rust-clippy#7797")] #[expect(clippy::collapsible_span_lint_calls, reason = "rust-clippy#7797")]

View file

@ -4,11 +4,10 @@ use clippy_utils::is_from_proc_macro;
use rustc_ast::{AttrStyle, Attribute}; use rustc_ast::{AttrStyle, Attribute};
use rustc_errors::Applicability; use rustc_errors::Applicability;
use rustc_lint::{EarlyContext, LintContext}; use rustc_lint::{EarlyContext, LintContext};
use rustc_middle::lint::in_external_macro;
// Separate each crate's features. // Separate each crate's features.
pub fn check<'cx>(cx: &EarlyContext<'cx>, attr: &'cx Attribute) { pub fn check<'cx>(cx: &EarlyContext<'cx>, attr: &'cx Attribute) {
if !in_external_macro(cx.sess(), attr.span) if !attr.span.in_external_macro(cx.sess().source_map())
&& let AttrStyle::Outer = attr.style && let AttrStyle::Outer = attr.style
&& let Some(ident) = attr.ident() && let Some(ident) = attr.ident()
&& !is_from_proc_macro(cx, attr) && !is_from_proc_macro(cx, attr)

View file

@ -3,7 +3,6 @@ use clippy_utils::diagnostics::span_lint_and_then;
use clippy_utils::is_from_proc_macro; use clippy_utils::is_from_proc_macro;
use rustc_ast::{MetaItemInner, MetaItemKind}; use rustc_ast::{MetaItemInner, MetaItemKind};
use rustc_lint::{EarlyContext, LintContext}; use rustc_lint::{EarlyContext, LintContext};
use rustc_middle::lint::in_external_macro;
use rustc_span::sym; use rustc_span::sym;
use rustc_span::symbol::Symbol; use rustc_span::symbol::Symbol;
@ -17,7 +16,7 @@ pub(super) fn check<'cx>(cx: &EarlyContext<'cx>, name: Symbol, items: &[MetaItem
} }
// Check if the attribute is in an external macro and therefore out of the developer's control // Check if the attribute is in an external macro and therefore out of the developer's control
if in_external_macro(cx.sess(), attr.span) || is_from_proc_macro(cx, attr) { if attr.span.in_external_macro(cx.sess().source_map()) || is_from_proc_macro(cx, attr) {
return; return;
} }

View file

@ -5,14 +5,13 @@ use clippy_utils::source::{SpanRangeExt, first_line_of_span};
use rustc_ast::{Attribute, Item, ItemKind}; use rustc_ast::{Attribute, Item, ItemKind};
use rustc_errors::Applicability; use rustc_errors::Applicability;
use rustc_lint::{EarlyContext, LintContext}; use rustc_lint::{EarlyContext, LintContext};
use rustc_middle::lint::in_external_macro;
use rustc_span::sym; use rustc_span::sym;
pub(super) fn check(cx: &EarlyContext<'_>, item: &Item, attrs: &[Attribute]) { pub(super) fn check(cx: &EarlyContext<'_>, item: &Item, attrs: &[Attribute]) {
let skip_unused_imports = attrs.iter().any(|attr| attr.has_name(sym::macro_use)); let skip_unused_imports = attrs.iter().any(|attr| attr.has_name(sym::macro_use));
for attr in attrs { for attr in attrs {
if in_external_macro(cx.sess(), attr.span) { if attr.span.in_external_macro(cx.sess().source_map()) {
return; return;
} }
if let Some(lint_list) = &attr.meta_item_list() { if let Some(lint_list) = &attr.meta_item_list() {

View file

@ -4,7 +4,6 @@ use clippy_utils::{higher, is_from_proc_macro};
use rustc_errors::Applicability; use rustc_errors::Applicability;
use rustc_hir::{BlockCheckMode, Expr, ExprKind, MatchSource}; use rustc_hir::{BlockCheckMode, Expr, ExprKind, MatchSource};
use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_lint::{LateContext, LateLintPass, LintContext};
use rustc_middle::lint::in_external_macro;
use rustc_session::declare_lint_pass; use rustc_session::declare_lint_pass;
declare_clippy_lint! { declare_clippy_lint! {
@ -54,7 +53,7 @@ const BRACED_EXPR_MESSAGE: &str = "omit braces around single expression conditio
impl<'tcx> LateLintPass<'tcx> for BlocksInConditions { impl<'tcx> LateLintPass<'tcx> for BlocksInConditions {
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
if in_external_macro(cx.sess(), expr.span) { if expr.span.in_external_macro(cx.sess().source_map()) {
return; return;
} }

View file

@ -7,7 +7,6 @@ use rustc_hir::def::Res;
use rustc_hir::intravisit::{InferKind, Visitor, VisitorExt, walk_ty}; use rustc_hir::intravisit::{InferKind, Visitor, VisitorExt, walk_ty};
use rustc_hir::{AmbigArg, Block, Expr, ExprKind, HirId, LetStmt, Node, QPath, Ty, TyKind}; use rustc_hir::{AmbigArg, Block, Expr, ExprKind, HirId, LetStmt, Node, QPath, Ty, TyKind};
use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_lint::{LateContext, LateLintPass, LintContext};
use rustc_middle::lint::in_external_macro;
use rustc_session::declare_lint_pass; use rustc_session::declare_lint_pass;
use rustc_span::{Span, sym}; use rustc_span::{Span, sym};
@ -50,7 +49,7 @@ impl LateLintPass<'_> for BoxDefault {
// This is the `T::default()` (or default equivalent) of `Box::new(T::default())` // This is the `T::default()` (or default equivalent) of `Box::new(T::default())`
&& let ExprKind::Call(arg_path, _) = arg.kind && let ExprKind::Call(arg_path, _) = arg.kind
// And we are not in a foreign crate's macro // And we are not in a foreign crate's macro
&& !in_external_macro(cx.sess(), expr.span) && !expr.span.in_external_macro(cx.sess().source_map())
// And the argument expression has the same context as the outer call expression // And the argument expression has the same context as the outer call expression
// or that we are inside a `vec!` macro expansion // or that we are inside a `vec!` macro expansion
&& (expr.span.eq_ctxt(arg.span) || is_local_vec_expn(cx, arg, expr)) && (expr.span.eq_ctxt(arg.span) || is_local_vec_expn(cx, arg, expr))

View file

@ -29,7 +29,6 @@ use clippy_utils::is_hir_ty_cfg_dependant;
use clippy_utils::msrvs::{self, Msrv}; use clippy_utils::msrvs::{self, Msrv};
use rustc_hir::{Expr, ExprKind}; use rustc_hir::{Expr, ExprKind};
use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_lint::{LateContext, LateLintPass, LintContext};
use rustc_middle::lint::in_external_macro;
use rustc_session::impl_lint_pass; use rustc_session::impl_lint_pass;
declare_clippy_lint! { declare_clippy_lint! {
@ -796,7 +795,7 @@ impl_lint_pass!(Casts => [
impl<'tcx> LateLintPass<'tcx> for Casts { impl<'tcx> LateLintPass<'tcx> for Casts {
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
if in_external_macro(cx.sess(), expr.span) { if expr.span.in_external_macro(cx.sess().source_map()) {
return; return;
} }

View file

@ -8,7 +8,6 @@ use rustc_errors::Applicability;
use rustc_hir::def::{DefKind, Res}; use rustc_hir::def::{DefKind, Res};
use rustc_hir::{Expr, ExprKind, Lit, Node, Path, QPath, TyKind, UnOp}; use rustc_hir::{Expr, ExprKind, Lit, Node, Path, QPath, TyKind, UnOp};
use rustc_lint::{LateContext, LintContext}; use rustc_lint::{LateContext, LintContext};
use rustc_middle::lint::in_external_macro;
use rustc_middle::ty::{self, FloatTy, InferTy, Ty}; use rustc_middle::ty::{self, FloatTy, InferTy, Ty};
use std::ops::ControlFlow; use std::ops::ControlFlow;
@ -142,7 +141,7 @@ pub(super) fn check<'tcx>(
} }
} }
if cast_from.kind() == cast_to.kind() && !in_external_macro(cx.sess(), expr.span) { if cast_from.kind() == cast_to.kind() && !expr.span.in_external_macro(cx.sess().source_map()) {
if let Some(id) = path_to_local(cast_expr) if let Some(id) = path_to_local(cast_expr)
&& !cx.tcx.hir().span(id).eq_ctxt(cast_expr.span) && !cx.tcx.hir().span(id).eq_ctxt(cast_expr.span)
{ {

View file

@ -6,7 +6,6 @@ use clippy_utils::{SpanlessEq, is_in_const_context, is_integer_literal};
use rustc_errors::Applicability; use rustc_errors::Applicability;
use rustc_hir::{BinOpKind, Expr, ExprKind, QPath, TyKind}; use rustc_hir::{BinOpKind, Expr, ExprKind, QPath, TyKind};
use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_lint::{LateContext, LateLintPass, LintContext};
use rustc_middle::lint::in_external_macro;
use rustc_session::impl_lint_pass; use rustc_session::impl_lint_pass;
declare_clippy_lint! { declare_clippy_lint! {
@ -64,7 +63,7 @@ impl LateLintPass<'_> for CheckedConversions {
}, },
_ => return, _ => return,
} }
&& !in_external_macro(cx.sess(), item.span) && !item.span.in_external_macro(cx.sess().source_map())
&& !is_in_const_context(cx) && !is_in_const_context(cx)
&& self.msrv.meets(msrvs::TRY_FROM) && self.msrv.meets(msrvs::TRY_FROM)
&& let Some(cv) = match op2 { && let Some(cv) = match op2 {

View file

@ -7,7 +7,6 @@ use rustc_data_structures::fx::FxHashSet;
use rustc_errors::Applicability; use rustc_errors::Applicability;
use rustc_hir::{Expr, ExprKind, Node}; use rustc_hir::{Expr, ExprKind, Node};
use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_lint::{LateContext, LateLintPass, LintContext};
use rustc_middle::lint::in_external_macro;
use rustc_session::impl_lint_pass; use rustc_session::impl_lint_pass;
use rustc_span::{Span, SyntaxContext, sym}; use rustc_span::{Span, SyntaxContext, sym};
@ -60,7 +59,7 @@ impl LateLintPass<'_> for DbgMacro {
if cur_syntax_ctxt != self.prev_ctxt && if cur_syntax_ctxt != self.prev_ctxt &&
let Some(macro_call) = first_dbg_macro_in_expansion(cx, expr.span) && let Some(macro_call) = first_dbg_macro_in_expansion(cx, expr.span) &&
!in_external_macro(cx.sess(), macro_call.span) && !macro_call.span.in_external_macro(cx.sess().source_map()) &&
self.checked_dbg_call_site.insert(macro_call.span) && self.checked_dbg_call_site.insert(macro_call.span) &&
// allows `dbg!` in test code if allow-dbg-in-test is set to true in clippy.toml // allows `dbg!` in test code if allow-dbg-in-test is set to true in clippy.toml
!(self.allow_dbg_in_tests && is_in_test(cx.tcx, expr.hir_id)) !(self.allow_dbg_in_tests && is_in_test(cx.tcx, expr.hir_id))

View file

@ -9,7 +9,6 @@ use rustc_hir::{
StructTailExpr, StructTailExpr,
}; };
use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_lint::{LateContext, LateLintPass, LintContext};
use rustc_middle::lint::in_external_macro;
use rustc_middle::ty::{self, FloatTy, IntTy, PolyFnSig, Ty}; use rustc_middle::ty::{self, FloatTy, IntTy, PolyFnSig, Ty};
use rustc_session::declare_lint_pass; use rustc_session::declare_lint_pass;
use std::iter; use std::iter;
@ -86,7 +85,7 @@ impl<'a, 'tcx> NumericFallbackVisitor<'a, 'tcx> {
/// Check whether a passed literal has potential to cause fallback or not. /// Check whether a passed literal has potential to cause fallback or not.
fn check_lit(&self, lit: &Lit, lit_ty: Ty<'tcx>, emit_hir_id: HirId) { fn check_lit(&self, lit: &Lit, lit_ty: Ty<'tcx>, emit_hir_id: HirId) {
if !in_external_macro(self.cx.sess(), lit.span) if !lit.span.in_external_macro(self.cx.sess().source_map())
&& matches!(self.ty_bounds.last(), Some(ExplicitTyBound(false))) && matches!(self.ty_bounds.last(), Some(ExplicitTyBound(false)))
&& matches!( && matches!(
lit.node, lit.node,

View file

@ -22,7 +22,6 @@ use rustc_hir::intravisit::{self, Visitor};
use rustc_hir::{AnonConst, Attribute, Expr, ImplItemKind, ItemKind, Node, Safety, TraitItemKind}; use rustc_hir::{AnonConst, Attribute, Expr, ImplItemKind, ItemKind, Node, Safety, TraitItemKind};
use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_lint::{LateContext, LateLintPass, LintContext};
use rustc_middle::hir::nested_filter; use rustc_middle::hir::nested_filter;
use rustc_middle::lint::in_external_macro;
use rustc_middle::ty; use rustc_middle::ty;
use rustc_resolve::rustdoc::{ use rustc_resolve::rustdoc::{
DocFragment, add_doc_fragment, attrs_to_doc_fragments, main_body_opts, source_span_for_markdown_range, DocFragment, add_doc_fragment, attrs_to_doc_fragments, main_body_opts, source_span_for_markdown_range,
@ -675,7 +674,7 @@ impl<'tcx> LateLintPass<'tcx> for Documentation {
match item.kind { match item.kind {
ItemKind::Fn { sig, body: body_id, .. } => { ItemKind::Fn { sig, body: body_id, .. } => {
if !(is_entrypoint_fn(cx, item.owner_id.to_def_id()) if !(is_entrypoint_fn(cx, item.owner_id.to_def_id())
|| in_external_macro(cx.tcx.sess, item.span)) || item.span.in_external_macro(cx.tcx.sess.source_map()))
{ {
let body = cx.tcx.hir().body(body_id); let body = cx.tcx.hir().body(body_id);
@ -711,7 +710,7 @@ impl<'tcx> LateLintPass<'tcx> for Documentation {
}, },
Node::TraitItem(trait_item) => { Node::TraitItem(trait_item) => {
if let TraitItemKind::Fn(sig, ..) = trait_item.kind if let TraitItemKind::Fn(sig, ..) = trait_item.kind
&& !in_external_macro(cx.tcx.sess, trait_item.span) && !trait_item.span.in_external_macro(cx.tcx.sess.source_map())
{ {
missing_headers::check( missing_headers::check(
cx, cx,
@ -726,7 +725,7 @@ impl<'tcx> LateLintPass<'tcx> for Documentation {
}, },
Node::ImplItem(impl_item) => { Node::ImplItem(impl_item) => {
if let ImplItemKind::Fn(sig, body_id) = impl_item.kind if let ImplItemKind::Fn(sig, body_id) = impl_item.kind
&& !in_external_macro(cx.tcx.sess, impl_item.span) && !impl_item.span.in_external_macro(cx.tcx.sess.source_map())
&& !is_trait_impl_item(cx, impl_item.hir_id()) && !is_trait_impl_item(cx, impl_item.hir_id())
{ {
let body = cx.tcx.hir().body(body_id); let body = cx.tcx.hir().body(body_id);
@ -791,7 +790,7 @@ fn check_attrs(cx: &LateContext<'_>, valid_idents: &FxHashSet<String>, attrs: &[
let (fragments, _) = attrs_to_doc_fragments( let (fragments, _) = attrs_to_doc_fragments(
attrs.iter().filter_map(|attr| { attrs.iter().filter_map(|attr| {
if in_external_macro(cx.sess(), attr.span) { if attr.span.in_external_macro(cx.sess().source_map()) {
None None
} else { } else {
Some((attr, None)) Some((attr, None))

View file

@ -1,7 +1,6 @@
use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::diagnostics::span_lint_and_then;
use rustc_ast::ast::{Expr, ExprKind}; use rustc_ast::ast::{Expr, ExprKind};
use rustc_lint::{EarlyContext, EarlyLintPass, LintContext}; use rustc_lint::{EarlyContext, EarlyLintPass, LintContext};
use rustc_middle::lint::in_external_macro;
use rustc_session::declare_lint_pass; use rustc_session::declare_lint_pass;
declare_clippy_lint! { declare_clippy_lint! {
@ -50,7 +49,7 @@ impl EarlyLintPass for ElseIfWithoutElse {
fn check_expr(&mut self, cx: &EarlyContext<'_>, item: &Expr) { fn check_expr(&mut self, cx: &EarlyContext<'_>, item: &Expr) {
if let ExprKind::If(_, _, Some(ref els)) = item.kind if let ExprKind::If(_, _, Some(ref els)) = item.kind
&& let ExprKind::If(_, _, None) = els.kind && let ExprKind::If(_, _, None) = els.kind
&& !in_external_macro(cx.sess(), item.span) && !item.span.in_external_macro(cx.sess().source_map())
{ {
#[expect(clippy::collapsible_span_lint_calls, reason = "rust-clippy#7797")] #[expect(clippy::collapsible_span_lint_calls, reason = "rust-clippy#7797")]
span_lint_and_then( span_lint_and_then(

View file

@ -3,7 +3,6 @@ use clippy_utils::diagnostics::span_lint_and_then;
use clippy_utils::is_lint_allowed; use clippy_utils::is_lint_allowed;
use rustc_hir::{Expr, ExprKind}; use rustc_hir::{Expr, ExprKind};
use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_lint::{LateContext, LateLintPass, LintContext};
use rustc_middle::lint::in_external_macro;
use rustc_middle::ty::Ty; use rustc_middle::ty::Ty;
use rustc_session::declare_lint_pass; use rustc_session::declare_lint_pass;
use rustc_span::Symbol; use rustc_span::Symbol;
@ -119,7 +118,7 @@ impl LateLintPass<'_> for EndianBytes {
}, },
_ => return, _ => return,
}; };
if !in_external_macro(cx.sess(), expr.span) if !expr.span.in_external_macro(cx.sess().source_map())
&& let ty = cx.typeck_results().expr_ty(ty_expr) && let ty = cx.typeck_results().expr_ty(ty_expr)
&& ty.is_primitive_ty() && ty.is_primitive_ty()
{ {

View file

@ -4,7 +4,6 @@ use clippy_utils::ty::implements_trait;
use rustc_errors::Applicability; use rustc_errors::Applicability;
use rustc_hir::{Expr, ExprKind, Pat, PatKind}; use rustc_hir::{Expr, ExprKind, Pat, PatKind};
use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_lint::{LateContext, LateLintPass, LintContext};
use rustc_middle::lint::in_external_macro;
use rustc_middle::ty::Ty; use rustc_middle::ty::Ty;
use rustc_session::declare_lint_pass; use rustc_session::declare_lint_pass;
@ -72,7 +71,7 @@ impl<'tcx> LateLintPass<'tcx> for PatternEquality {
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) {
if let ExprKind::Let(let_expr) = expr.kind if let ExprKind::Let(let_expr) = expr.kind
&& unary_pattern(let_expr.pat) && unary_pattern(let_expr.pat)
&& !in_external_macro(cx.sess(), expr.span) && !expr.span.in_external_macro(cx.sess().source_map())
{ {
let exp_ty = cx.typeck_results().expr_ty(let_expr.init); let exp_ty = cx.typeck_results().expr_ty(let_expr.init);
let pat_ty = cx.typeck_results().pat_ty(let_expr.pat); let pat_ty = cx.typeck_results().pat_ty(let_expr.pat);

View file

@ -5,7 +5,6 @@ use rustc_ast::node_id::NodeSet;
use rustc_ast::visit::{Visitor, walk_block, walk_item}; use rustc_ast::visit::{Visitor, walk_block, walk_item};
use rustc_ast::{Block, Crate, Inline, Item, ItemKind, ModKind, NodeId}; use rustc_ast::{Block, Crate, Inline, Item, ItemKind, ModKind, NodeId};
use rustc_lint::{EarlyContext, EarlyLintPass, LintContext}; use rustc_lint::{EarlyContext, EarlyLintPass, LintContext};
use rustc_middle::lint::in_external_macro;
use rustc_session::impl_lint_pass; use rustc_session::impl_lint_pass;
use rustc_span::Span; use rustc_span::Span;
@ -125,7 +124,7 @@ struct NestingVisitor<'conf, 'cx> {
impl NestingVisitor<'_, '_> { impl NestingVisitor<'_, '_> {
fn check_indent(&mut self, span: Span, id: NodeId) -> bool { fn check_indent(&mut self, span: Span, id: NodeId) -> bool {
if self.nest_level > self.conf.excessive_nesting_threshold && !in_external_macro(self.cx.sess(), span) { if self.nest_level > self.conf.excessive_nesting_threshold && !span.in_external_macro(self.cx.sess().source_map()) {
self.conf.nodes.insert(id); self.conf.nodes.insert(id);
return true; return true;

View file

@ -10,7 +10,6 @@ use rustc_hir::{
}; };
use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_lint::{LateContext, LateLintPass, LintContext};
use rustc_middle::hir::nested_filter; use rustc_middle::hir::nested_filter;
use rustc_middle::lint::in_external_macro;
use rustc_session::impl_lint_pass; use rustc_session::impl_lint_pass;
use rustc_span::Span; use rustc_span::Span;
use rustc_span::def_id::{DefId, LocalDefId}; use rustc_span::def_id::{DefId, LocalDefId};
@ -261,7 +260,7 @@ impl<'tcx> LateLintPass<'tcx> for ExtraUnusedTypeParameters {
&& !generics.params.is_empty() && !generics.params.is_empty()
&& !is_empty_body(cx, body_id) && !is_empty_body(cx, body_id)
&& (!self.avoid_breaking_exported_api || !cx.effective_visibilities.is_exported(item.owner_id.def_id)) && (!self.avoid_breaking_exported_api || !cx.effective_visibilities.is_exported(item.owner_id.def_id))
&& !in_external_macro(cx.sess(), item.span) && !item.span.in_external_macro(cx.sess().source_map())
&& !is_from_proc_macro(cx, item) && !is_from_proc_macro(cx, item)
{ {
let mut walker = TypeWalker::new(cx, generics); let mut walker = TypeWalker::new(cx, generics);
@ -277,7 +276,7 @@ impl<'tcx> LateLintPass<'tcx> for ExtraUnusedTypeParameters {
&& trait_ref_of_method(cx, item.owner_id.def_id).is_none() && trait_ref_of_method(cx, item.owner_id.def_id).is_none()
&& !is_empty_body(cx, body_id) && !is_empty_body(cx, body_id)
&& (!self.avoid_breaking_exported_api || !cx.effective_visibilities.is_exported(item.owner_id.def_id)) && (!self.avoid_breaking_exported_api || !cx.effective_visibilities.is_exported(item.owner_id.def_id))
&& !in_external_macro(cx.sess(), item.span) && !item.span.in_external_macro(cx.sess().source_map())
&& !is_from_proc_macro(cx, item) && !is_from_proc_macro(cx, item)
{ {
let mut walker = TypeWalker::new(cx, item.generics); let mut walker = TypeWalker::new(cx, item.generics);

View file

@ -3,7 +3,6 @@ use clippy_utils::is_span_if;
use clippy_utils::source::snippet_opt; use clippy_utils::source::snippet_opt;
use rustc_ast::ast::{BinOpKind, Block, Expr, ExprKind, StmtKind}; use rustc_ast::ast::{BinOpKind, Block, Expr, ExprKind, StmtKind};
use rustc_lint::{EarlyContext, EarlyLintPass, LintContext}; use rustc_lint::{EarlyContext, EarlyLintPass, LintContext};
use rustc_middle::lint::in_external_macro;
use rustc_session::declare_lint_pass; use rustc_session::declare_lint_pass;
use rustc_span::Span; use rustc_span::Span;
@ -202,7 +201,7 @@ fn check_else(cx: &EarlyContext<'_>, expr: &Expr) {
if let ExprKind::If(_, then, Some(else_)) = &expr.kind if let ExprKind::If(_, then, Some(else_)) = &expr.kind
&& (is_block(else_) || is_if(else_)) && (is_block(else_) || is_if(else_))
&& !then.span.from_expansion() && !else_.span.from_expansion() && !then.span.from_expansion() && !else_.span.from_expansion()
&& !in_external_macro(cx.sess(), expr.span) && !expr.span.in_external_macro(cx.sess().source_map())
// workaround for rust-lang/rust#43081 // workaround for rust-lang/rust#43081
&& expr.span.lo().0 != 0 && expr.span.hi().0 != 0 && expr.span.lo().0 != 0 && expr.span.hi().0 != 0

View file

@ -5,7 +5,6 @@ use rustc_hir::def_id::DefIdSet;
use rustc_hir::{self as hir, Attribute, QPath}; use rustc_hir::{self as hir, Attribute, QPath};
use rustc_infer::infer::TyCtxtInferExt; use rustc_infer::infer::TyCtxtInferExt;
use rustc_lint::{LateContext, LintContext}; use rustc_lint::{LateContext, LintContext};
use rustc_middle::lint::in_external_macro;
use rustc_middle::ty::{self, Ty}; use rustc_middle::ty::{self, Ty};
use rustc_span::{Span, sym}; use rustc_span::{Span, sym};
@ -107,7 +106,7 @@ fn check_needless_must_use(
attrs: &[Attribute], attrs: &[Attribute],
sig: &FnSig<'_>, sig: &FnSig<'_>,
) { ) {
if in_external_macro(cx.sess(), item_span) { if item_span.in_external_macro(cx.sess().source_map()) {
return; return;
} }
if returns_unit(decl) { if returns_unit(decl) {
@ -185,7 +184,7 @@ fn check_must_use_candidate<'tcx>(
) { ) {
if has_mutable_arg(cx, body) if has_mutable_arg(cx, body)
|| mutates_static(cx, body) || mutates_static(cx, body)
|| in_external_macro(cx.sess(), item_span) || item_span.in_external_macro(cx.sess().source_map())
|| returns_unit(decl) || returns_unit(decl)
|| !cx.effective_visibilities.is_exported(item_id.def_id) || !cx.effective_visibilities.is_exported(item_id.def_id)
|| is_must_use_ty(cx, return_ty(cx, item_id)) || is_must_use_ty(cx, return_ty(cx, item_id))

View file

@ -2,7 +2,6 @@ use clippy_utils::msrvs::{self, Msrv};
use rustc_errors::Diag; use rustc_errors::Diag;
use rustc_hir as hir; use rustc_hir as hir;
use rustc_lint::{LateContext, LintContext}; use rustc_lint::{LateContext, LintContext};
use rustc_middle::lint::in_external_macro;
use rustc_middle::ty::{self, Ty}; use rustc_middle::ty::{self, Ty};
use rustc_span::{Span, sym}; use rustc_span::{Span, sym};
@ -20,7 +19,7 @@ fn result_err_ty<'tcx>(
id: hir::def_id::LocalDefId, id: hir::def_id::LocalDefId,
item_span: Span, item_span: Span,
) -> Option<(&'tcx hir::Ty<'tcx>, Ty<'tcx>)> { ) -> Option<(&'tcx hir::Ty<'tcx>, Ty<'tcx>)> {
if !in_external_macro(cx.sess(), item_span) if !item_span.in_external_macro(cx.sess().source_map())
&& let hir::FnRetTy::Return(hir_ty) = decl.output && let hir::FnRetTy::Return(hir_ty) = decl.output
&& let ty = cx && let ty = cx
.tcx .tcx

View file

@ -3,7 +3,6 @@ use clippy_utils::source::SpanRangeExt;
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::intravisit::FnKind; use rustc_hir::intravisit::FnKind;
use rustc_lint::{LateContext, LintContext}; use rustc_lint::{LateContext, LintContext};
use rustc_middle::lint::in_external_macro;
use rustc_span::Span; use rustc_span::Span;
use super::TOO_MANY_LINES; use super::TOO_MANY_LINES;
@ -17,7 +16,7 @@ pub(super) fn check_fn(
) { ) {
// Closures must be contained in a parent body, which will be checked for `too_many_lines`. // Closures must be contained in a parent body, which will be checked for `too_many_lines`.
// Don't check closures for `too_many_lines` to avoid duplicated lints. // Don't check closures for `too_many_lines` to avoid duplicated lints.
if matches!(kind, FnKind::Closure) || in_external_macro(cx.sess(), span) { if matches!(kind, FnKind::Closure) || span.in_external_macro(cx.sess().source_map()) {
return; return;
} }

View file

@ -11,7 +11,6 @@ use rustc_errors::Applicability;
use rustc_hir::LangItem::{OptionNone, OptionSome}; use rustc_hir::LangItem::{OptionNone, OptionSome};
use rustc_hir::{Expr, ExprKind}; use rustc_hir::{Expr, ExprKind};
use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_lint::{LateContext, LateLintPass, LintContext};
use rustc_middle::lint::in_external_macro;
use rustc_session::impl_lint_pass; use rustc_session::impl_lint_pass;
declare_clippy_lint! { declare_clippy_lint! {
@ -79,7 +78,7 @@ impl<'tcx> LateLintPass<'tcx> for IfThenSomeElseNone {
&& is_res_lang_ctor(cx, path_res(cx, peel_blocks(els)), OptionNone) && is_res_lang_ctor(cx, path_res(cx, peel_blocks(els)), OptionNone)
&& !is_else_clause(cx.tcx, expr) && !is_else_clause(cx.tcx, expr)
&& !is_in_const_context(cx) && !is_in_const_context(cx)
&& !in_external_macro(cx.sess(), expr.span) && !expr.span.in_external_macro(cx.sess().source_map())
&& self.msrv.meets(msrvs::BOOL_THEN) && self.msrv.meets(msrvs::BOOL_THEN)
&& !contains_return(then_block.stmts) && !contains_return(then_block.stmts)
{ {

View file

@ -7,7 +7,6 @@ use rustc_errors::Applicability;
use rustc_hir::intravisit::FnKind; use rustc_hir::intravisit::FnKind;
use rustc_hir::{Block, Body, Expr, ExprKind, FnDecl, FnRetTy, HirId}; use rustc_hir::{Block, Body, Expr, ExprKind, FnDecl, FnRetTy, HirId};
use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_lint::{LateContext, LateLintPass, LintContext};
use rustc_middle::lint::in_external_macro;
use rustc_session::declare_lint_pass; use rustc_session::declare_lint_pass;
use rustc_span::def_id::LocalDefId; use rustc_span::def_id::LocalDefId;
use rustc_span::{Span, SyntaxContext}; use rustc_span::{Span, SyntaxContext};
@ -227,7 +226,7 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitReturn {
) { ) {
if (!matches!(kind, FnKind::Closure) && matches!(decl.output, FnRetTy::DefaultReturn(_))) if (!matches!(kind, FnKind::Closure) && matches!(decl.output, FnRetTy::DefaultReturn(_)))
|| !span.eq_ctxt(body.value.span) || !span.eq_ctxt(body.value.span)
|| in_external_macro(cx.sess(), span) || span.in_external_macro(cx.sess().source_map())
{ {
return; return;
} }

View file

@ -1,7 +1,6 @@
use clippy_utils::diagnostics::span_lint_hir; use clippy_utils::diagnostics::span_lint_hir;
use rustc_hir::{Block, ItemKind, StmtKind}; use rustc_hir::{Block, ItemKind, StmtKind};
use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_lint::{LateContext, LateLintPass, LintContext};
use rustc_middle::lint::in_external_macro;
use rustc_session::declare_lint_pass; use rustc_session::declare_lint_pass;
declare_clippy_lint! { declare_clippy_lint! {
@ -70,7 +69,7 @@ impl LateLintPass<'_> for ItemsAfterStatements {
// Don't use `next` due to the complex filter chain. // Don't use `next` due to the complex filter chain.
.for_each(|item| { .for_each(|item| {
// Only do the macro check once, but delay it until it's needed. // Only do the macro check once, but delay it until it's needed.
if !*in_external.get_or_insert_with(|| in_external_macro(cx.sess(), block.span)) { if !*in_external.get_or_insert_with(|| block.span.in_external_macro(cx.sess().source_map())) {
span_lint_hir( span_lint_hir(
cx, cx,
ITEMS_AFTER_STATEMENTS, ITEMS_AFTER_STATEMENTS,

View file

@ -6,7 +6,6 @@ use rustc_ast::Mutability;
use rustc_errors::Applicability; use rustc_errors::Applicability;
use rustc_hir::{FnRetTy, ImplItemKind, ImplicitSelfKind, ItemKind, TyKind}; use rustc_hir::{FnRetTy, ImplItemKind, ImplicitSelfKind, ItemKind, TyKind};
use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_lint::{LateContext, LateLintPass, LintContext};
use rustc_middle::lint::in_external_macro;
use rustc_middle::ty::{self, Ty}; use rustc_middle::ty::{self, Ty};
use rustc_session::declare_lint_pass; use rustc_session::declare_lint_pass;
use rustc_span::sym; use rustc_span::sym;
@ -131,7 +130,7 @@ impl LateLintPass<'_> for IterWithoutIntoIter {
&& trait_ref && trait_ref
.trait_def_id() .trait_def_id()
.is_some_and(|did| cx.tcx.is_diagnostic_item(sym::IntoIterator, did)) .is_some_and(|did| cx.tcx.is_diagnostic_item(sym::IntoIterator, did))
&& !in_external_macro(cx.sess(), item.span) && !item.span.in_external_macro(cx.sess().source_map())
&& let &ty::Ref(_, ty, mtbl) = cx.tcx.type_of(item.owner_id).instantiate_identity().kind() && let &ty::Ref(_, ty, mtbl) = cx.tcx.type_of(item.owner_id).instantiate_identity().kind()
&& let expected_method_name = match mtbl { && let expected_method_name = match mtbl {
Mutability::Mut => sym::iter_mut, Mutability::Mut => sym::iter_mut,
@ -193,7 +192,7 @@ impl {self_ty_without_ref} {{
_ => return, _ => return,
}; };
if !in_external_macro(cx.sess(), item.span) if !item.span.in_external_macro(cx.sess().source_map())
&& let ImplItemKind::Fn(sig, _) = item.kind && let ImplItemKind::Fn(sig, _) = item.kind
&& let FnRetTy::Return(ret) = sig.decl.output && let FnRetTy::Return(ret) = sig.decl.output
&& is_nameable_in_impl_trait(ret) && is_nameable_in_impl_trait(ret)

View file

@ -5,7 +5,6 @@ use clippy_utils::ty::{AdtVariantInfo, approx_ty_size, is_copy};
use rustc_errors::Applicability; use rustc_errors::Applicability;
use rustc_hir::{Item, ItemKind}; use rustc_hir::{Item, ItemKind};
use rustc_lint::{LateContext, LateLintPass}; use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::lint::in_external_macro;
use rustc_middle::ty::{self, Ty}; use rustc_middle::ty::{self, Ty};
use rustc_session::impl_lint_pass; use rustc_session::impl_lint_pass;
use rustc_span::Span; use rustc_span::Span;
@ -78,7 +77,7 @@ impl<'tcx> LateLintPass<'tcx> for LargeEnumVariant {
&& let ty = cx.tcx.type_of(item.owner_id).instantiate_identity() && let ty = cx.tcx.type_of(item.owner_id).instantiate_identity()
&& let ty::Adt(adt, subst) = ty.kind() && let ty::Adt(adt, subst) = ty.kind()
&& adt.variants().len() > 1 && adt.variants().len() > 1
&& !in_external_macro(cx.tcx.sess, item.span) && !item.span.in_external_macro(cx.tcx.sess.source_map())
{ {
let variants_size = AdtVariantInfo::new(cx, *adt, subst); let variants_size = AdtVariantInfo::new(cx, *adt, subst);

View file

@ -7,7 +7,6 @@ use rustc_errors::Applicability;
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::{ExprKind, Item, ItemKind, QPath, UseKind}; use rustc_hir::{ExprKind, Item, ItemKind, QPath, UseKind};
use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_lint::{LateContext, LateLintPass, LintContext};
use rustc_middle::lint::in_external_macro;
use rustc_session::impl_lint_pass; use rustc_session::impl_lint_pass;
use rustc_span::symbol::kw; use rustc_span::symbol::kw;
use rustc_span::{Symbol, sym}; use rustc_span::{Symbol, sym};
@ -54,7 +53,7 @@ impl<'tcx> LateLintPass<'tcx> for LegacyNumericConstants {
// so lint on the `use` statement directly. // so lint on the `use` statement directly.
if let ItemKind::Use(path, kind @ (UseKind::Single | UseKind::Glob)) = item.kind if let ItemKind::Use(path, kind @ (UseKind::Single | UseKind::Glob)) = item.kind
&& self.msrv.meets(msrvs::NUMERIC_ASSOCIATED_CONSTANTS) && self.msrv.meets(msrvs::NUMERIC_ASSOCIATED_CONSTANTS)
&& !in_external_macro(cx.sess(), item.span) && !item.span.in_external_macro(cx.sess().source_map())
&& let Some(def_id) = path.res[0].opt_def_id() && let Some(def_id) = path.res[0].opt_def_id()
{ {
let module = if is_integer_module(cx, def_id) { let module = if is_integer_module(cx, def_id) {
@ -139,7 +138,7 @@ impl<'tcx> LateLintPass<'tcx> for LegacyNumericConstants {
}; };
if self.msrv.meets(msrvs::NUMERIC_ASSOCIATED_CONSTANTS) if self.msrv.meets(msrvs::NUMERIC_ASSOCIATED_CONSTANTS)
&& !in_external_macro(cx.sess(), expr.span) && !expr.span.in_external_macro(cx.sess().source_map())
&& !is_from_proc_macro(cx, expr) && !is_from_proc_macro(cx, expr)
{ {
span_lint_hir_and_then(cx, LEGACY_NUMERIC_CONSTANTS, expr.hir_id, span, msg, |diag| { span_lint_hir_and_then(cx, LEGACY_NUMERIC_CONSTANTS, expr.hir_id, span, msg, |diag| {

View file

@ -3,7 +3,6 @@ use clippy_utils::ty::{implements_trait, is_must_use_ty, match_type};
use clippy_utils::{is_from_proc_macro, is_must_use_func_call, paths}; use clippy_utils::{is_from_proc_macro, is_must_use_func_call, paths};
use rustc_hir::{LetStmt, LocalSource, PatKind}; use rustc_hir::{LetStmt, LocalSource, PatKind};
use rustc_lint::{LateContext, LateLintPass}; use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::lint::in_external_macro;
use rustc_middle::ty::{GenericArgKind, IsSuggestable}; use rustc_middle::ty::{GenericArgKind, IsSuggestable};
use rustc_session::declare_lint_pass; use rustc_session::declare_lint_pass;
use rustc_span::{BytePos, Span}; use rustc_span::{BytePos, Span};
@ -141,7 +140,7 @@ impl<'tcx> LateLintPass<'tcx> for LetUnderscore {
if matches!(local.source, LocalSource::Normal) if matches!(local.source, LocalSource::Normal)
&& let PatKind::Wild = local.pat.kind && let PatKind::Wild = local.pat.kind
&& let Some(init) = local.init && let Some(init) = local.init
&& !in_external_macro(cx.tcx.sess, local.span) && !local.span.in_external_macro(cx.tcx.sess.source_map())
{ {
let init_ty = cx.typeck_results().expr_ty(init); let init_ty = cx.typeck_results().expr_ty(init);
let contains_sync_guard = init_ty.walk().any(|inner| match inner.unpack() { let contains_sync_guard = init_ty.walk().any(|inner| match inner.unpack() {

View file

@ -2,7 +2,6 @@ use clippy_utils::diagnostics::span_lint_and_help;
use clippy_utils::is_from_proc_macro; use clippy_utils::is_from_proc_macro;
use rustc_hir::{LetStmt, TyKind}; use rustc_hir::{LetStmt, TyKind};
use rustc_lint::{LateContext, LateLintPass}; use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::lint::in_external_macro;
use rustc_session::declare_lint_pass; use rustc_session::declare_lint_pass;
declare_clippy_lint! { declare_clippy_lint! {
@ -30,7 +29,7 @@ impl<'tcx> LateLintPass<'tcx> for UnderscoreTyped {
if let Some(ty) = local.ty // Ensure that it has a type defined if let Some(ty) = local.ty // Ensure that it has a type defined
&& let TyKind::Infer(()) = &ty.kind // that type is '_' && let TyKind::Infer(()) = &ty.kind // that type is '_'
&& local.span.eq_ctxt(ty.span) && local.span.eq_ctxt(ty.span)
&& !in_external_macro(cx.tcx.sess, local.span) && !local.span.in_external_macro(cx.tcx.sess.source_map())
&& !is_from_proc_macro(cx, ty) && !is_from_proc_macro(cx, ty)
{ {
span_lint_and_help( span_lint_and_help(

View file

@ -21,7 +21,6 @@ use rustc_hir::{
use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_lint::{LateContext, LateLintPass, LintContext};
use rustc_middle::hir::map::Map; use rustc_middle::hir::map::Map;
use rustc_middle::hir::nested_filter as middle_nested_filter; use rustc_middle::hir::nested_filter as middle_nested_filter;
use rustc_middle::lint::in_external_macro;
use rustc_session::impl_lint_pass; use rustc_session::impl_lint_pass;
use rustc_span::Span; use rustc_span::Span;
use rustc_span::def_id::LocalDefId; use rustc_span::def_id::LocalDefId;
@ -164,7 +163,7 @@ fn check_fn_inner<'tcx>(
report_extra_lifetimes: bool, report_extra_lifetimes: bool,
msrv: &Msrv, msrv: &Msrv,
) { ) {
if in_external_macro(cx.sess(), span) || has_where_lifetimes(cx, generics) { if span.in_external_macro(cx.sess().source_map()) || has_where_lifetimes(cx, generics) {
return; return;
} }

View file

@ -6,7 +6,6 @@ use rustc_ast::ast::{Expr, ExprKind, LitKind};
use rustc_ast::token; use rustc_ast::token;
use rustc_errors::Applicability; use rustc_errors::Applicability;
use rustc_lint::{EarlyContext, EarlyLintPass, Lint, LintContext}; use rustc_lint::{EarlyContext, EarlyLintPass, Lint, LintContext};
use rustc_middle::lint::in_external_macro;
use rustc_session::impl_lint_pass; use rustc_session::impl_lint_pass;
use rustc_span::Span; use rustc_span::Span;
use std::iter; use std::iter;
@ -207,7 +206,7 @@ impl_lint_pass!(LiteralDigitGrouping => [
impl EarlyLintPass for LiteralDigitGrouping { impl EarlyLintPass for LiteralDigitGrouping {
fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &Expr) { fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &Expr) {
if let ExprKind::Lit(lit) = expr.kind if let ExprKind::Lit(lit) = expr.kind
&& !in_external_macro(cx.sess(), expr.span) && !expr.span.in_external_macro(cx.sess().source_map())
{ {
self.check_lit(cx, lit, expr.span); self.check_lit(cx, lit, expr.span);
} }
@ -421,7 +420,7 @@ impl_lint_pass!(DecimalLiteralRepresentation => [DECIMAL_LITERAL_REPRESENTATION]
impl EarlyLintPass for DecimalLiteralRepresentation { impl EarlyLintPass for DecimalLiteralRepresentation {
fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &Expr) { fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &Expr) {
if let ExprKind::Lit(lit) = expr.kind if let ExprKind::Lit(lit) = expr.kind
&& !in_external_macro(cx.sess(), expr.span) && !expr.span.in_external_macro(cx.sess().source_map())
{ {
self.check_lit(cx, lit, expr.span); self.check_lit(cx, lit, expr.span);
} }

View file

@ -6,7 +6,6 @@ use rustc_ast::Label;
use rustc_errors::Applicability; use rustc_errors::Applicability;
use rustc_hir as hir; use rustc_hir as hir;
use rustc_lint::{LateContext, LintContext}; use rustc_lint::{LateContext, LintContext};
use rustc_middle::lint::in_external_macro;
use rustc_span::sym; use rustc_span::sym;
use super::INFINITE_LOOP; use super::INFINITE_LOOP;
@ -30,7 +29,7 @@ pub(super) fn check<'tcx>(
return; return;
} }
if in_external_macro(cx.sess(), expr.span) || is_from_proc_macro(cx, expr) { if expr.span.in_external_macro(cx.sess().source_map()) || is_from_proc_macro(cx, expr) {
return; return;
} }

View file

@ -9,7 +9,6 @@ use rustc_hir::def::DefKind;
use rustc_hir::def_id::DefId; use rustc_hir::def_id::DefId;
use rustc_hir::{BinOpKind, Constness, Expr, ExprKind}; use rustc_hir::{BinOpKind, Constness, Expr, ExprKind};
use rustc_lint::{LateContext, LateLintPass, Lint, LintContext}; use rustc_lint::{LateContext, LateLintPass, Lint, LintContext};
use rustc_middle::lint::in_external_macro;
use rustc_middle::ty::TyCtxt; use rustc_middle::ty::TyCtxt;
use rustc_session::impl_lint_pass; use rustc_session::impl_lint_pass;
@ -142,7 +141,7 @@ impl<'tcx> LateLintPass<'tcx> for ManualFloatMethods {
// 16 possible alignments of constants/operands. For now, let's use `partition`. // 16 possible alignments of constants/operands. For now, let's use `partition`.
&& let mut exprs = [lhs_lhs, lhs_rhs, rhs_lhs, rhs_rhs] && let mut exprs = [lhs_lhs, lhs_rhs, rhs_lhs, rhs_rhs]
&& exprs.iter_mut().partition_in_place(|i| path_to_local(i).is_some()) == 2 && exprs.iter_mut().partition_in_place(|i| path_to_local(i).is_some()) == 2
&& !in_external_macro(cx.sess(), expr.span) && !expr.span.in_external_macro(cx.sess().source_map())
&& ( && (
is_not_const(cx.tcx, cx.tcx.hir().enclosing_body_owner(expr.hir_id).into()) is_not_const(cx.tcx, cx.tcx.hir().enclosing_body_owner(expr.hir_id).into())
|| self.msrv.meets(msrvs::CONST_FLOAT_CLASSIFY) || self.msrv.meets(msrvs::CONST_FLOAT_CLASSIFY)

View file

@ -9,7 +9,6 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_errors::Applicability; use rustc_errors::Applicability;
use rustc_hir::{Expr, ExprKind, MatchSource, Pat, PatExpr, PatExprKind, PatKind, QPath, Stmt, StmtKind}; use rustc_hir::{Expr, ExprKind, MatchSource, Pat, PatExpr, PatExprKind, PatKind, QPath, Stmt, StmtKind};
use rustc_lint::{LateContext, LintContext}; use rustc_lint::{LateContext, LintContext};
use rustc_middle::lint::in_external_macro;
use rustc_span::Span; use rustc_span::Span;
use rustc_span::symbol::{Symbol, sym}; use rustc_span::symbol::{Symbol, sym};
@ -55,7 +54,7 @@ impl<'tcx> QuestionMark {
&& init.span.eq_ctxt(stmt.span) && init.span.eq_ctxt(stmt.span)
&& let Some(if_let_or_match) = IfLetOrMatch::parse(cx, init) && let Some(if_let_or_match) = IfLetOrMatch::parse(cx, init)
&& self.msrv.meets(msrvs::LET_ELSE) && self.msrv.meets(msrvs::LET_ELSE)
&& !in_external_macro(cx.sess(), stmt.span) && !stmt.span.in_external_macro(cx.sess().source_map())
{ {
match if_let_or_match { match if_let_or_match {
IfLetOrMatch::IfLet(if_let_expr, let_pat, if_then, if_else, ..) => { IfLetOrMatch::IfLet(if_let_expr, let_pat, if_then, if_else, ..) => {

View file

@ -5,7 +5,6 @@ use rustc_data_structures::fx::FxHashSet;
use rustc_errors::Applicability; use rustc_errors::Applicability;
use rustc_hir::{PatExpr, PatExprKind, PatKind, RangeEnd}; use rustc_hir::{PatExpr, PatExprKind, PatKind, RangeEnd};
use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_lint::{LateContext, LateLintPass, LintContext};
use rustc_middle::lint::in_external_macro;
use rustc_session::declare_lint_pass; use rustc_session::declare_lint_pass;
use rustc_span::{DUMMY_SP, Span}; use rustc_span::{DUMMY_SP, Span};
@ -80,7 +79,7 @@ impl LateLintPass<'_> for ManualRangePatterns {
// like described https://github.com/rust-lang/rust-clippy/issues/11825) // like described https://github.com/rust-lang/rust-clippy/issues/11825)
if let PatKind::Or(pats) = pat.kind if let PatKind::Or(pats) = pat.kind
&& (pats.len() >= 3 || (pats.len() > 1 && pats.iter().any(|p| matches!(p.kind, PatKind::Range(..))))) && (pats.len() >= 3 || (pats.len() > 1 && pats.iter().any(|p| matches!(p.kind, PatKind::Range(..)))))
&& !in_external_macro(cx.sess(), pat.span) && !pat.span.in_external_macro(cx.sess().source_map())
{ {
let mut min = Num::dummy(i128::MAX); let mut min = Num::dummy(i128::MAX);
let mut max = Num::dummy(i128::MIN); let mut max = Num::dummy(i128::MIN);

View file

@ -7,7 +7,6 @@ use clippy_utils::{is_in_const_context, path_to_local};
use rustc_errors::Applicability; use rustc_errors::Applicability;
use rustc_hir::{BinOpKind, Expr, ExprKind, Node, TyKind}; use rustc_hir::{BinOpKind, Expr, ExprKind, Node, TyKind};
use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_lint::{LateContext, LateLintPass, LintContext};
use rustc_middle::lint::in_external_macro;
use rustc_session::impl_lint_pass; use rustc_session::impl_lint_pass;
declare_clippy_lint! { declare_clippy_lint! {
@ -60,7 +59,7 @@ impl<'tcx> LateLintPass<'tcx> for ManualRemEuclid {
&& rem_rhs.span.ctxt() == ctxt && rem_rhs.span.ctxt() == ctxt
&& add_lhs.span.ctxt() == ctxt && add_lhs.span.ctxt() == ctxt
&& add_rhs.span.ctxt() == ctxt && add_rhs.span.ctxt() == ctxt
&& !in_external_macro(cx.sess(), expr.span) && !expr.span.in_external_macro(cx.sess().source_map())
&& self.msrv.meets(msrvs::REM_EUCLID) && self.msrv.meets(msrvs::REM_EUCLID)
&& (self.msrv.meets(msrvs::REM_EUCLID_CONST) || !is_in_const_context(cx)) && (self.msrv.meets(msrvs::REM_EUCLID_CONST) || !is_in_const_context(cx))
&& let Some(const1) = check_for_unsigned_int_constant(cx, rem_rhs) && let Some(const1) = check_for_unsigned_int_constant(cx, rem_rhs)

View file

@ -33,7 +33,6 @@ use clippy_utils::{
}; };
use rustc_hir::{Arm, Expr, ExprKind, LetStmt, MatchSource, Pat, PatKind}; use rustc_hir::{Arm, Expr, ExprKind, LetStmt, MatchSource, Pat, PatKind};
use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_lint::{LateContext, LateLintPass, LintContext};
use rustc_middle::lint::in_external_macro;
use rustc_session::impl_lint_pass; use rustc_session::impl_lint_pass;
use rustc_span::{SpanData, SyntaxContext}; use rustc_span::{SpanData, SyntaxContext};
@ -1054,7 +1053,7 @@ impl_lint_pass!(Matches => [
impl<'tcx> LateLintPass<'tcx> for Matches { impl<'tcx> LateLintPass<'tcx> for Matches {
#[expect(clippy::too_many_lines)] #[expect(clippy::too_many_lines)]
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
if is_direct_expn_of(expr.span, "matches").is_none() && in_external_macro(cx.sess(), expr.span) { if is_direct_expn_of(expr.span, "matches").is_none() && expr.span.in_external_macro(cx.sess().source_map()) {
return; return;
} }
let from_expansion = expr.span.from_expansion(); let from_expansion = expr.span.from_expansion();

View file

@ -11,7 +11,6 @@ use rustc_errors::Applicability;
use rustc_hir::LangItem::OptionNone; use rustc_hir::LangItem::OptionNone;
use rustc_hir::{Expr, ExprKind}; use rustc_hir::{Expr, ExprKind};
use rustc_lint::{LateContext, LateLintPass}; use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::lint::in_external_macro;
use rustc_session::impl_lint_pass; use rustc_session::impl_lint_pass;
use rustc_span::Span; use rustc_span::Span;
use rustc_span::symbol::sym; use rustc_span::symbol::sym;
@ -188,7 +187,7 @@ fn check_replace_with_default(cx: &LateContext<'_>, src: &Expr<'_>, dest: &Expr<
if is_non_aggregate_primitive_type(expr_type) { if is_non_aggregate_primitive_type(expr_type) {
return; return;
} }
if is_default_equivalent(cx, src) && !in_external_macro(cx.tcx.sess, expr_span) { if is_default_equivalent(cx, src) && !expr_span.in_external_macro(cx.tcx.sess.source_map()) {
let Some(top_crate) = std_or_core(cx) else { return }; let Some(top_crate) = std_or_core(cx) else { return };
span_lint_and_then( span_lint_and_then(
cx, cx,

View file

@ -6,13 +6,12 @@ use clippy_utils::{is_from_proc_macro, is_trait_method, peel_blocks};
use rustc_errors::Applicability; use rustc_errors::Applicability;
use rustc_hir::{Expr, ExprKind}; use rustc_hir::{Expr, ExprKind};
use rustc_lint::{LateContext, LintContext}; use rustc_lint::{LateContext, LintContext};
use rustc_middle::lint::in_external_macro;
use rustc_middle::ty::Binder; use rustc_middle::ty::Binder;
use rustc_middle::ty::adjustment::Adjust; use rustc_middle::ty::adjustment::Adjust;
use rustc_span::{Span, sym}; use rustc_span::{Span, sym};
pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>, arg: &Expr<'_>, call_span: Span) { pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>, arg: &Expr<'_>, call_span: Span) {
if !in_external_macro(cx.sess(), expr.span) if !expr.span.in_external_macro(cx.sess().source_map())
&& is_trait_method(cx, expr, sym::Iterator) && is_trait_method(cx, expr, sym::Iterator)
&& let ExprKind::Closure(closure) = arg.kind && let ExprKind::Closure(closure) = arg.kind
&& let body = cx.tcx.hir().body(closure.body) && let body = cx.tcx.hir().body(closure.body)

View file

@ -4,7 +4,6 @@ use clippy_utils::macros::{is_assert_macro, root_macro_call};
use clippy_utils::{find_binding_init, get_parent_expr, is_inside_always_const_context, path_to_local}; use clippy_utils::{find_binding_init, get_parent_expr, is_inside_always_const_context, path_to_local};
use rustc_hir::{Expr, HirId}; use rustc_hir::{Expr, HirId};
use rustc_lint::{LateContext, LintContext}; use rustc_lint::{LateContext, LintContext};
use rustc_middle::lint::in_external_macro;
use rustc_span::sym; use rustc_span::sym;
use super::CONST_IS_EMPTY; use super::CONST_IS_EMPTY;
@ -12,7 +11,7 @@ use super::CONST_IS_EMPTY;
/// Expression whose initialization depend on a constant conditioned by a `#[cfg(…)]` directive will /// Expression whose initialization depend on a constant conditioned by a `#[cfg(…)]` directive will
/// not trigger the lint. /// not trigger the lint.
pub(super) fn check(cx: &LateContext<'_>, expr: &'_ Expr<'_>, receiver: &Expr<'_>) { pub(super) fn check(cx: &LateContext<'_>, expr: &'_ Expr<'_>, receiver: &Expr<'_>) {
if in_external_macro(cx.sess(), expr.span) || !receiver.span.eq_ctxt(expr.span) { if expr.span.in_external_macro(cx.sess().source_map()) || !receiver.span.eq_ctxt(expr.span) {
return; return;
} }
if let Some(parent) = get_parent_expr(cx, expr) { if let Some(parent) = get_parent_expr(cx, expr) {

View file

@ -7,7 +7,6 @@ use rustc_errors::Applicability;
use rustc_hir::def::{DefKind, Res}; use rustc_hir::def::{DefKind, Res};
use rustc_hir::{Expr, ExprKind}; use rustc_hir::{Expr, ExprKind};
use rustc_lint::{LateContext, LintContext}; use rustc_lint::{LateContext, LintContext};
use rustc_middle::lint::in_external_macro;
use rustc_span::{Span, sym}; use rustc_span::{Span, sym};
use super::MANUAL_TRY_FOLD; use super::MANUAL_TRY_FOLD;
@ -20,7 +19,7 @@ pub(super) fn check<'tcx>(
fold_span: Span, fold_span: Span,
msrv: &Msrv, msrv: &Msrv,
) { ) {
if !in_external_macro(cx.sess(), fold_span) if !fold_span.in_external_macro(cx.sess().source_map())
&& msrv.meets(msrvs::ITERATOR_TRY_FOLD) && msrv.meets(msrvs::ITERATOR_TRY_FOLD)
&& is_trait_method(cx, expr, sym::Iterator) && is_trait_method(cx, expr, sym::Iterator)
&& let init_ty = cx.typeck_results().expr_ty(init) && let init_ty = cx.typeck_results().expr_ty(init)

View file

@ -152,7 +152,6 @@ use rustc_data_structures::fx::FxHashSet;
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::{Expr, ExprKind, Node, Stmt, StmtKind, TraitItem, TraitItemKind}; use rustc_hir::{Expr, ExprKind, Node, Stmt, StmtKind, TraitItem, TraitItemKind};
use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_lint::{LateContext, LateLintPass, LintContext};
use rustc_middle::lint::in_external_macro;
use rustc_middle::ty::{self, TraitRef, Ty}; use rustc_middle::ty::{self, TraitRef, Ty};
use rustc_session::impl_lint_pass; use rustc_session::impl_lint_pass;
use rustc_span::{Span, sym}; use rustc_span::{Span, sym};
@ -4625,7 +4624,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
#[allow(clippy::too_many_lines)] #[allow(clippy::too_many_lines)]
fn check_impl_item(&mut self, cx: &LateContext<'tcx>, impl_item: &'tcx hir::ImplItem<'_>) { fn check_impl_item(&mut self, cx: &LateContext<'tcx>, impl_item: &'tcx hir::ImplItem<'_>) {
if in_external_macro(cx.sess(), impl_item.span) { if impl_item.span.in_external_macro(cx.sess().source_map()) {
return; return;
} }
let name = impl_item.ident.name.as_str(); let name = impl_item.ident.name.as_str();
@ -4713,7 +4712,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
} }
fn check_trait_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx TraitItem<'_>) { fn check_trait_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx TraitItem<'_>) {
if in_external_macro(cx.tcx.sess, item.span) { if item.span.in_external_macro(cx.tcx.sess.source_map()) {
return; return;
} }

View file

@ -6,7 +6,6 @@ use rustc_hir::def::{DefKind, Res};
use rustc_hir::intravisit::{Visitor, walk_item, walk_trait_item}; use rustc_hir::intravisit::{Visitor, walk_item, walk_trait_item};
use rustc_hir::{GenericParamKind, HirId, Item, ItemKind, ItemLocalId, Node, Pat, PatKind, TraitItem, UsePath}; use rustc_hir::{GenericParamKind, HirId, Item, ItemKind, ItemLocalId, Node, Pat, PatKind, TraitItem, UsePath};
use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_lint::{LateContext, LateLintPass, LintContext};
use rustc_middle::lint::in_external_macro;
use rustc_session::impl_lint_pass; use rustc_session::impl_lint_pass;
use rustc_span::Span; use rustc_span::Span;
use std::borrow::Cow; use std::borrow::Cow;
@ -55,7 +54,7 @@ impl MinIdentChars {
#[expect(clippy::cast_possible_truncation)] #[expect(clippy::cast_possible_truncation)]
fn is_ident_too_short(&self, cx: &LateContext<'_>, str: &str, span: Span) -> bool { fn is_ident_too_short(&self, cx: &LateContext<'_>, str: &str, span: Span) -> bool {
!in_external_macro(cx.sess(), span) !span.in_external_macro(cx.sess().source_map())
&& str.len() <= self.min_ident_chars_threshold as usize && str.len() <= self.min_ident_chars_threshold as usize
&& !str.starts_with('_') && !str.starts_with('_')
&& !str.is_empty() && !str.is_empty()

View file

@ -13,7 +13,6 @@ use rustc_hir::{
BinOpKind, BindingMode, Body, ByRef, Expr, ExprKind, FnDecl, Mutability, PatKind, QPath, Stmt, StmtKind, BinOpKind, BindingMode, Body, ByRef, Expr, ExprKind, FnDecl, Mutability, PatKind, QPath, Stmt, StmtKind,
}; };
use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_lint::{LateContext, LateLintPass, LintContext};
use rustc_middle::lint::in_external_macro;
use rustc_session::declare_lint_pass; use rustc_session::declare_lint_pass;
use rustc_span::Span; use rustc_span::Span;
use rustc_span::def_id::LocalDefId; use rustc_span::def_id::LocalDefId;
@ -162,7 +161,7 @@ impl<'tcx> LateLintPass<'tcx> for LintPass {
for arg in iter_input_pats(decl, body) { for arg in iter_input_pats(decl, body) {
if let PatKind::Binding(BindingMode(ByRef::Yes(_), _), ..) = arg.pat.kind if let PatKind::Binding(BindingMode(ByRef::Yes(_), _), ..) = arg.pat.kind
&& is_lint_allowed(cx, REF_PATTERNS, arg.pat.hir_id) && is_lint_allowed(cx, REF_PATTERNS, arg.pat.hir_id)
&& !in_external_macro(cx.tcx.sess, arg.span) && !arg.span.in_external_macro(cx.tcx.sess.source_map())
{ {
span_lint_hir( span_lint_hir(
cx, cx,
@ -183,7 +182,7 @@ impl<'tcx> LateLintPass<'tcx> for LintPass {
&& let Some(init) = local.init && let Some(init) = local.init
// Do not emit if clippy::ref_patterns is not allowed to avoid having two lints for the same issue. // Do not emit if clippy::ref_patterns is not allowed to avoid having two lints for the same issue.
&& is_lint_allowed(cx, REF_PATTERNS, local.pat.hir_id) && is_lint_allowed(cx, REF_PATTERNS, local.pat.hir_id)
&& !in_external_macro(cx.tcx.sess, stmt.span) && !stmt.span.in_external_macro(cx.tcx.sess.source_map())
{ {
let ctxt = local.span.ctxt(); let ctxt = local.span.ctxt();
let mut app = Applicability::MachineApplicable; let mut app = Applicability::MachineApplicable;
@ -239,7 +238,7 @@ impl<'tcx> LateLintPass<'tcx> for LintPass {
} }
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
if in_external_macro(cx.sess(), expr.span) if expr.span.in_external_macro(cx.sess().source_map())
|| expr.span.desugaring_kind().is_some() || expr.span.desugaring_kind().is_some()
|| in_automatically_derived(cx.tcx, expr.hir_id) || in_automatically_derived(cx.tcx, expr.hir_id)
{ {

View file

@ -14,7 +14,6 @@ use rustc_ast::token;
use rustc_ast::visit::FnKind; use rustc_ast::visit::FnKind;
use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::fx::FxHashMap;
use rustc_lint::{EarlyContext, EarlyLintPass, LintContext}; use rustc_lint::{EarlyContext, EarlyLintPass, LintContext};
use rustc_middle::lint::in_external_macro;
use rustc_session::declare_lint_pass; use rustc_session::declare_lint_pass;
use rustc_span::Span; use rustc_span::Span;
@ -350,7 +349,7 @@ impl EarlyLintPass for MiscEarlyLints {
} }
fn check_pat(&mut self, cx: &EarlyContext<'_>, pat: &Pat) { fn check_pat(&mut self, cx: &EarlyContext<'_>, pat: &Pat) {
if in_external_macro(cx.sess(), pat.span) { if pat.span.in_external_macro(cx.sess().source_map()) {
return; return;
} }
@ -387,7 +386,7 @@ impl EarlyLintPass for MiscEarlyLints {
} }
fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &Expr) { fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &Expr) {
if in_external_macro(cx.sess(), expr.span) { if expr.span.in_external_macro(cx.sess().source_map()) {
return; return;
} }

View file

@ -2,12 +2,11 @@ use clippy_utils::diagnostics::span_lint_and_sugg;
use rustc_ast::{Pat, PatKind}; use rustc_ast::{Pat, PatKind};
use rustc_errors::Applicability; use rustc_errors::Applicability;
use rustc_lint::{EarlyContext, LintContext}; use rustc_lint::{EarlyContext, LintContext};
use rustc_middle::lint::in_external_macro;
use super::REDUNDANT_AT_REST_PATTERN; use super::REDUNDANT_AT_REST_PATTERN;
pub(super) fn check(cx: &EarlyContext<'_>, pat: &Pat) { pub(super) fn check(cx: &EarlyContext<'_>, pat: &Pat) {
if !in_external_macro(cx.sess(), pat.span) if !pat.span.in_external_macro(cx.sess().source_map())
&& let PatKind::Slice(slice) = &pat.kind && let PatKind::Slice(slice) = &pat.kind
&& let [one] = &**slice && let [one] = &**slice
&& let PatKind::Ident(annotation, ident, Some(rest)) = &one.kind && let PatKind::Ident(annotation, ident, Some(rest)) = &one.kind

View file

@ -8,7 +8,6 @@ use rustc_hir::def_id::CRATE_DEF_ID;
use rustc_hir::intravisit::FnKind; use rustc_hir::intravisit::FnKind;
use rustc_hir::{self as hir, Body, Constness, FnDecl, GenericParamKind}; use rustc_hir::{self as hir, Body, Constness, FnDecl, GenericParamKind};
use rustc_lint::{LateContext, LateLintPass}; use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::lint::in_external_macro;
use rustc_middle::ty; use rustc_middle::ty;
use rustc_session::impl_lint_pass; use rustc_session::impl_lint_pass;
use rustc_span::Span; use rustc_span::Span;
@ -106,7 +105,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingConstForFn {
return; return;
} }
if in_external_macro(cx.tcx.sess, span) || is_entrypoint_fn(cx, def_id.to_def_id()) { if span.in_external_macro(cx.tcx.sess.source_map()) || is_entrypoint_fn(cx, def_id.to_def_id()) {
return; return;
} }

View file

@ -88,7 +88,7 @@ declare_lint_pass!(MissingInline => [MISSING_INLINE_IN_PUBLIC_ITEMS]);
impl<'tcx> LateLintPass<'tcx> for MissingInline { impl<'tcx> LateLintPass<'tcx> for MissingInline {
fn check_item(&mut self, cx: &LateContext<'tcx>, it: &'tcx hir::Item<'_>) { fn check_item(&mut self, cx: &LateContext<'tcx>, it: &'tcx hir::Item<'_>) {
if rustc_middle::lint::in_external_macro(cx.sess(), it.span) || is_executable_or_proc_macro(cx) { if it.span.in_external_macro(cx.sess().source_map()) || is_executable_or_proc_macro(cx) {
return; return;
} }
@ -139,7 +139,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingInline {
} }
fn check_impl_item(&mut self, cx: &LateContext<'tcx>, impl_item: &'tcx hir::ImplItem<'_>) { fn check_impl_item(&mut self, cx: &LateContext<'tcx>, impl_item: &'tcx hir::ImplItem<'_>) {
if rustc_middle::lint::in_external_macro(cx.sess(), impl_item.span) || is_executable_or_proc_macro(cx) { if impl_item.span.in_external_macro(cx.sess().source_map()) || is_executable_or_proc_macro(cx) {
return; return;
} }

View file

@ -6,7 +6,6 @@ use hir::{BlockCheckMode, ExprKind, QPath, UnOp};
use rustc_ast::Mutability; use rustc_ast::Mutability;
use rustc_hir as hir; use rustc_hir as hir;
use rustc_lint::{LateContext, LateLintPass}; use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::lint::in_external_macro;
use rustc_middle::ty; use rustc_middle::ty;
use rustc_session::declare_lint_pass; use rustc_session::declare_lint_pass;
use rustc_span::{DesugaringKind, Span}; use rustc_span::{DesugaringKind, Span};
@ -65,7 +64,7 @@ declare_lint_pass!(MultipleUnsafeOpsPerBlock => [MULTIPLE_UNSAFE_OPS_PER_BLOCK])
impl<'tcx> LateLintPass<'tcx> for MultipleUnsafeOpsPerBlock { impl<'tcx> LateLintPass<'tcx> for MultipleUnsafeOpsPerBlock {
fn check_block(&mut self, cx: &LateContext<'tcx>, block: &'tcx hir::Block<'_>) { fn check_block(&mut self, cx: &LateContext<'tcx>, block: &'tcx hir::Block<'_>) {
if !matches!(block.rules, BlockCheckMode::UnsafeBlock(_)) if !matches!(block.rules, BlockCheckMode::UnsafeBlock(_))
|| in_external_macro(cx.tcx.sess, block.span) || block.span.in_external_macro(cx.tcx.sess.source_map())
|| block.span.is_desugaring(DesugaringKind::Await) || block.span.is_desugaring(DesugaringKind::Await)
{ {
return; return;

View file

@ -2,7 +2,6 @@ use clippy_utils::diagnostics::{span_lint, span_lint_hir};
use clippy_utils::higher; use clippy_utils::higher;
use rustc_hir::{self as hir, AmbigArg, intravisit}; use rustc_hir::{self as hir, AmbigArg, intravisit};
use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_lint::{LateContext, LateLintPass, LintContext};
use rustc_middle::lint::in_external_macro;
use rustc_middle::ty; use rustc_middle::ty;
use rustc_session::declare_lint_pass; use rustc_session::declare_lint_pass;
@ -38,7 +37,7 @@ impl<'tcx> LateLintPass<'tcx> for MutMut {
&& mty.mutbl == hir::Mutability::Mut && mty.mutbl == hir::Mutability::Mut
&& let hir::TyKind::Ref(_, mty) = mty.ty.kind && let hir::TyKind::Ref(_, mty) = mty.ty.kind
&& mty.mutbl == hir::Mutability::Mut && mty.mutbl == hir::Mutability::Mut
&& !in_external_macro(cx.sess(), ty.span) && !ty.span.in_external_macro(cx.sess().source_map())
{ {
span_lint( span_lint(
cx, cx,
@ -56,7 +55,7 @@ pub struct MutVisitor<'a, 'tcx> {
impl<'tcx> intravisit::Visitor<'tcx> for MutVisitor<'_, 'tcx> { impl<'tcx> intravisit::Visitor<'tcx> for MutVisitor<'_, 'tcx> {
fn visit_expr(&mut self, expr: &'tcx hir::Expr<'_>) { fn visit_expr(&mut self, expr: &'tcx hir::Expr<'_>) {
if in_external_macro(self.cx.sess(), expr.span) { if expr.span.in_external_macro(self.cx.sess().source_map()) {
return; return;
} }

View file

@ -5,7 +5,6 @@ use clippy_utils::source::SpanRangeExt;
use rustc_errors::Applicability; use rustc_errors::Applicability;
use rustc_hir::{ExprKind, Stmt, StmtKind}; use rustc_hir::{ExprKind, Stmt, StmtKind};
use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_lint::{LateContext, LateLintPass, LintContext};
use rustc_middle::lint::in_external_macro;
use rustc_session::declare_lint_pass; use rustc_session::declare_lint_pass;
declare_clippy_lint! { declare_clippy_lint! {
@ -47,7 +46,7 @@ impl LateLintPass<'_> for NeedlessIf {
&& let ExprKind::Block(block, ..) = then.kind && let ExprKind::Block(block, ..) = then.kind
&& block.stmts.is_empty() && block.stmts.is_empty()
&& block.expr.is_none() && block.expr.is_none()
&& !in_external_macro(cx.sess(), expr.span) && !expr.span.in_external_macro(cx.sess().source_map())
&& then.span.check_source_text(cx, |src| { && then.span.check_source_text(cx, |src| {
// Ignore // Ignore
// - empty macro expansions // - empty macro expansions

View file

@ -2,7 +2,6 @@ use clippy_utils::diagnostics::span_lint;
use clippy_utils::ty::implements_trait; use clippy_utils::ty::implements_trait;
use rustc_hir::{BinOpKind, Expr, ExprKind, UnOp}; use rustc_hir::{BinOpKind, Expr, ExprKind, UnOp};
use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_lint::{LateContext, LateLintPass, LintContext};
use rustc_middle::lint::in_external_macro;
use rustc_session::declare_lint_pass; use rustc_session::declare_lint_pass;
use rustc_span::sym; use rustc_span::sym;
@ -48,7 +47,7 @@ impl<'tcx> LateLintPass<'tcx> for NoNegCompOpForPartialOrd {
if let ExprKind::Unary(UnOp::Not, inner) = expr.kind if let ExprKind::Unary(UnOp::Not, inner) = expr.kind
&& let ExprKind::Binary(ref op, left, _) = inner.kind && let ExprKind::Binary(ref op, left, _) = inner.kind
&& let BinOpKind::Le | BinOpKind::Ge | BinOpKind::Lt | BinOpKind::Gt = op.node && let BinOpKind::Le | BinOpKind::Ge | BinOpKind::Lt | BinOpKind::Gt = op.node
&& !in_external_macro(cx.sess(), expr.span) && !expr.span.in_external_macro(cx.sess().source_map())
{ {
let ty = cx.typeck_results().expr_ty(left); let ty = cx.typeck_results().expr_ty(left);

View file

@ -6,7 +6,6 @@ use rustc_errors::Applicability;
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::HirIdSet; use rustc_hir::HirIdSet;
use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_lint::{LateContext, LateLintPass, LintContext};
use rustc_middle::lint::in_external_macro;
use rustc_session::impl_lint_pass; use rustc_session::impl_lint_pass;
use rustc_span::sym; use rustc_span::sym;
@ -69,7 +68,7 @@ impl<'tcx> LateLintPass<'tcx> for NewWithoutDefault {
for assoc_item in *items { for assoc_item in *items {
if assoc_item.kind == (hir::AssocItemKind::Fn { has_self: false }) { if assoc_item.kind == (hir::AssocItemKind::Fn { has_self: false }) {
let impl_item = cx.tcx.hir().impl_item(assoc_item.id); let impl_item = cx.tcx.hir().impl_item(assoc_item.id);
if in_external_macro(cx.sess(), impl_item.span) { if impl_item.span.in_external_macro(cx.sess().source_map()) {
return; return;
} }
if let hir::ImplItemKind::Fn(ref sig, _) = impl_item.kind { if let hir::ImplItemKind::Fn(ref sig, _) = impl_item.kind {

View file

@ -12,7 +12,6 @@ use rustc_hir::{
}; };
use rustc_infer::infer::TyCtxtInferExt as _; use rustc_infer::infer::TyCtxtInferExt as _;
use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_lint::{LateContext, LateLintPass, LintContext};
use rustc_middle::lint::in_external_macro;
use rustc_session::impl_lint_pass; use rustc_session::impl_lint_pass;
use rustc_span::Span; use rustc_span::Span;
use rustc_trait_selection::error_reporting::InferCtxtErrorExt; use rustc_trait_selection::error_reporting::InferCtxtErrorExt;
@ -268,7 +267,7 @@ fn has_no_effect(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
fn check_unnecessary_operation(cx: &LateContext<'_>, stmt: &Stmt<'_>) { fn check_unnecessary_operation(cx: &LateContext<'_>, stmt: &Stmt<'_>) {
if let StmtKind::Semi(expr) = stmt.kind if let StmtKind::Semi(expr) = stmt.kind
&& !in_external_macro(cx.sess(), stmt.span) && !stmt.span.in_external_macro(cx.sess().source_map())
&& let ctxt = stmt.span.ctxt() && let ctxt = stmt.span.ctxt()
&& expr.span.ctxt() == ctxt && expr.span.ctxt() == ctxt
&& let Some(reduced) = reduce_expression(cx, expr) && let Some(reduced) = reduce_expression(cx, expr)

View file

@ -5,7 +5,6 @@ use rustc_errors::Applicability;
use rustc_hir::def_id::LocalDefId; use rustc_hir::def_id::LocalDefId;
use rustc_hir::{Expr, ExprKind, ImplItem, ImplItemKind, LangItem, Node, UnOp}; use rustc_hir::{Expr, ExprKind, ImplItem, ImplItemKind, LangItem, Node, UnOp};
use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_lint::{LateContext, LateLintPass, LintContext};
use rustc_middle::lint::in_external_macro;
use rustc_middle::ty::EarlyBinder; use rustc_middle::ty::EarlyBinder;
use rustc_session::declare_lint_pass; use rustc_session::declare_lint_pass;
use rustc_span::sym; use rustc_span::sym;
@ -129,7 +128,7 @@ impl LateLintPass<'_> for NonCanonicalImpls {
let ExprKind::Block(block, ..) = body.value.kind else { let ExprKind::Block(block, ..) = body.value.kind else {
return; return;
}; };
if in_external_macro(cx.sess(), block.span) || is_from_proc_macro(cx, impl_item) { if block.span.in_external_macro(cx.sess().source_map()) || is_from_proc_macro(cx, impl_item) {
return; return;
} }

View file

@ -5,7 +5,6 @@ use rustc_ast::ast::{
}; };
use rustc_ast::visit::{Visitor, walk_block, walk_expr, walk_pat}; use rustc_ast::visit::{Visitor, walk_block, walk_expr, walk_pat};
use rustc_lint::{EarlyContext, EarlyLintPass, LintContext}; use rustc_lint::{EarlyContext, EarlyLintPass, LintContext};
use rustc_middle::lint::in_external_macro;
use rustc_session::impl_lint_pass; use rustc_session::impl_lint_pass;
use rustc_span::symbol::{Ident, Symbol}; use rustc_span::symbol::{Ident, Symbol};
use rustc_span::{Span, sym}; use rustc_span::{Span, sym};
@ -381,7 +380,7 @@ impl<'tcx> Visitor<'tcx> for SimilarNamesLocalVisitor<'_, 'tcx> {
impl EarlyLintPass for NonExpressiveNames { impl EarlyLintPass for NonExpressiveNames {
fn check_item(&mut self, cx: &EarlyContext<'_>, item: &Item) { fn check_item(&mut self, cx: &EarlyContext<'_>, item: &Item) {
if in_external_macro(cx.sess(), item.span) { if item.span.in_external_macro(cx.sess().source_map()) {
return; return;
} }
@ -396,7 +395,7 @@ impl EarlyLintPass for NonExpressiveNames {
} }
fn check_impl_item(&mut self, cx: &EarlyContext<'_>, item: &AssocItem) { fn check_impl_item(&mut self, cx: &EarlyContext<'_>, item: &AssocItem) {
if in_external_macro(cx.sess(), item.span) { if item.span.in_external_macro(cx.sess().source_map()) {
return; return;
} }

View file

@ -7,7 +7,6 @@ use rustc_ast::ImplPolarity;
use rustc_hir::def_id::DefId; use rustc_hir::def_id::DefId;
use rustc_hir::{FieldDef, Item, ItemKind, Node}; use rustc_hir::{FieldDef, Item, ItemKind, Node};
use rustc_lint::{LateContext, LateLintPass}; use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::lint::in_external_macro;
use rustc_middle::ty::{self, GenericArgKind, Ty}; use rustc_middle::ty::{self, GenericArgKind, Ty};
use rustc_session::impl_lint_pass; use rustc_session::impl_lint_pass;
use rustc_span::sym; use rustc_span::sym;
@ -81,7 +80,7 @@ impl<'tcx> LateLintPass<'tcx> for NonSendFieldInSendTy {
// We start from `Send` impl instead of `check_field_def()` because // We start from `Send` impl instead of `check_field_def()` because
// single `AdtDef` may have multiple `Send` impls due to generic // single `AdtDef` may have multiple `Send` impls due to generic
// parameters, and the lint is much easier to implement in this way. // parameters, and the lint is much easier to implement in this way.
if !in_external_macro(cx.tcx.sess, item.span) if !item.span.in_external_macro(cx.tcx.sess.source_map())
&& let Some(send_trait) = cx.tcx.get_diagnostic_item(sym::Send) && let Some(send_trait) = cx.tcx.get_diagnostic_item(sym::Send)
&& let ItemKind::Impl(hir_impl) = &item.kind && let ItemKind::Impl(hir_impl) = &item.kind
&& let Some(trait_ref) = &hir_impl.of_trait && let Some(trait_ref) = &hir_impl.of_trait

View file

@ -9,7 +9,6 @@ use rustc_hir::def::{DefKind, Res};
use rustc_hir::def_id::{CrateNum, DefId}; use rustc_hir::def_id::{CrateNum, DefId};
use rustc_hir::{self as hir, BodyId, Expr, ExprKind, Item, ItemKind}; use rustc_hir::{self as hir, BodyId, Expr, ExprKind, Item, ItemKind};
use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_lint::{LateContext, LateLintPass, LintContext};
use rustc_middle::lint::in_external_macro;
use rustc_session::impl_lint_pass; use rustc_session::impl_lint_pass;
use rustc_span::Span; use rustc_span::Span;
@ -139,7 +138,7 @@ impl<'hir> LateLintPass<'hir> for NonStdLazyStatic {
return; return;
} }
if in_external_macro(cx.sess(), item.span) { if item.span.in_external_macro(cx.sess().source_map()) {
return; return;
} }

View file

@ -4,7 +4,6 @@ use rustc_ast::token::LitKind;
use rustc_ast::{Expr, ExprKind}; use rustc_ast::{Expr, ExprKind};
use rustc_errors::Applicability; use rustc_errors::Applicability;
use rustc_lint::{EarlyContext, EarlyLintPass, LintContext}; use rustc_lint::{EarlyContext, EarlyLintPass, LintContext};
use rustc_middle::lint::in_external_macro;
use rustc_session::declare_lint_pass; use rustc_session::declare_lint_pass;
use rustc_span::{BytePos, Pos, SpanData}; use rustc_span::{BytePos, Pos, SpanData};
@ -59,7 +58,7 @@ impl EarlyLintPass for OctalEscapes {
LitKind::ByteStr | LitKind::CStr => 2, LitKind::ByteStr | LitKind::CStr => 2,
_ => return, _ => return,
}) })
&& !in_external_macro(cx.sess(), expr.span) && !expr.span.in_external_macro(cx.sess().source_map())
{ {
let s = lit.symbol.as_str(); let s = lit.symbol.as_str();
let mut iter = s.as_bytes().iter(); let mut iter = s.as_bytes().iter();

View file

@ -2,7 +2,6 @@ use clippy_utils::diagnostics::span_lint;
use clippy_utils::eq_expr_value; use clippy_utils::eq_expr_value;
use rustc_hir::{BinOpKind, Expr, ExprKind}; use rustc_hir::{BinOpKind, Expr, ExprKind};
use rustc_lint::{LateContext, LateLintPass}; use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::lint::in_external_macro;
use rustc_middle::ty; use rustc_middle::ty;
use rustc_session::declare_lint_pass; use rustc_session::declare_lint_pass;
@ -72,7 +71,7 @@ impl<'tcx> LateLintPass<'tcx> for PanickingOverflowChecks {
&& matches!(ty.kind(), ty::Uint(_)) && matches!(ty.kind(), ty::Uint(_))
&& ty == typeck.expr_ty(op_rhs) && ty == typeck.expr_ty(op_rhs)
&& ty == typeck.expr_ty(other) && ty == typeck.expr_ty(other)
&& !in_external_macro(cx.tcx.sess, expr.span) && !expr.span.in_external_macro(cx.tcx.sess.source_map())
&& (eq_expr_value(cx, op_lhs, other) || (commutative && eq_expr_value(cx, op_rhs, other))) && (eq_expr_value(cx, op_lhs, other) || (commutative && eq_expr_value(cx, op_rhs, other)))
{ {
span_lint( span_lint(

View file

@ -7,7 +7,6 @@ use rustc_errors::Applicability;
use rustc_hir::def::Res; use rustc_hir::def::Res;
use rustc_hir::{BindingMode, Block, Expr, ExprKind, HirId, LetStmt, PatKind, QPath, Stmt, StmtKind, TyKind}; use rustc_hir::{BindingMode, Block, Expr, ExprKind, HirId, LetStmt, PatKind, QPath, Stmt, StmtKind, TyKind};
use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_lint::{LateContext, LateLintPass, LintContext};
use rustc_middle::lint::in_external_macro;
use rustc_session::impl_lint_pass; use rustc_session::impl_lint_pass;
use rustc_span::{Span, Symbol, sym}; use rustc_span::{Span, Symbol, sym};
@ -136,7 +135,7 @@ impl<'tcx> LateLintPass<'tcx> for PathbufThenPush<'tcx> {
fn check_local(&mut self, cx: &LateContext<'tcx>, local: &'tcx LetStmt<'tcx>) { fn check_local(&mut self, cx: &LateContext<'tcx>, local: &'tcx LetStmt<'tcx>) {
if let Some(init_expr) = local.init if let Some(init_expr) = local.init
&& let PatKind::Binding(BindingMode::MUT, id, name, None) = local.pat.kind && let PatKind::Binding(BindingMode::MUT, id, name, None) = local.pat.kind
&& !in_external_macro(cx.sess(), local.span) && !local.span.in_external_macro(cx.sess().source_map())
&& let ty = cx.typeck_results().pat_ty(local.pat) && let ty = cx.typeck_results().pat_ty(local.pat)
&& is_type_diagnostic_item(cx, ty, sym::PathBuf) && is_type_diagnostic_item(cx, ty, sym::PathBuf)
{ {
@ -157,7 +156,7 @@ impl<'tcx> LateLintPass<'tcx> for PathbufThenPush<'tcx> {
&& let ExprKind::Path(QPath::Resolved(None, path)) = left.kind && let ExprKind::Path(QPath::Resolved(None, path)) = left.kind
&& let [name] = &path.segments && let [name] = &path.segments
&& let Res::Local(id) = path.res && let Res::Local(id) = path.res
&& !in_external_macro(cx.sess(), expr.span) && !expr.span.in_external_macro(cx.sess().source_map())
&& let ty = cx.typeck_results().expr_ty(left) && let ty = cx.typeck_results().expr_ty(left)
&& is_type_diagnostic_item(cx, ty, sym::PathBuf) && is_type_diagnostic_item(cx, ty, sym::PathBuf)
{ {

View file

@ -3,7 +3,6 @@ use rustc_hir::{
Body, Expr, ExprKind, FnDecl, LetExpr, LocalSource, Mutability, Pat, PatKind, Stmt, StmtKind, intravisit, Body, Expr, ExprKind, FnDecl, LetExpr, LocalSource, Mutability, Pat, PatKind, Stmt, StmtKind, intravisit,
}; };
use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_lint::{LateContext, LateLintPass, LintContext};
use rustc_middle::lint::in_external_macro;
use rustc_middle::ty; use rustc_middle::ty;
use rustc_session::declare_lint_pass; use rustc_session::declare_lint_pass;
use rustc_span::Span; use rustc_span::Span;
@ -84,7 +83,7 @@ declare_lint_pass!(PatternTypeMismatch => [PATTERN_TYPE_MISMATCH]);
impl<'tcx> LateLintPass<'tcx> for PatternTypeMismatch { impl<'tcx> LateLintPass<'tcx> for PatternTypeMismatch {
fn check_stmt(&mut self, cx: &LateContext<'tcx>, stmt: &'tcx Stmt<'_>) { fn check_stmt(&mut self, cx: &LateContext<'tcx>, stmt: &'tcx Stmt<'_>) {
if let StmtKind::Let(local) = stmt.kind { if let StmtKind::Let(local) = stmt.kind {
if in_external_macro(cx.sess(), local.pat.span) { if local.pat.span.in_external_macro(cx.sess().source_map()) {
return; return;
} }
let deref_possible = match local.source { let deref_possible = match local.source {
@ -171,7 +170,7 @@ fn find_first_mismatch(cx: &LateContext<'_>, pat: &Pat<'_>) -> Option<(Span, Mut
if result.is_some() { if result.is_some() {
return false; return false;
} }
if in_external_macro(cx.sess(), p.span) { if p.span.in_external_macro(cx.sess().source_map()) {
return true; return true;
} }
let adjust_pat = match p.kind { let adjust_pat = match p.kind {

View file

@ -5,7 +5,6 @@ use rustc_ast::ast::{Expr, ExprKind};
use rustc_ast::token::LitKind; use rustc_ast::token::LitKind;
use rustc_errors::Applicability; use rustc_errors::Applicability;
use rustc_lint::{EarlyContext, EarlyLintPass, LintContext}; use rustc_lint::{EarlyContext, EarlyLintPass, LintContext};
use rustc_middle::lint::in_external_macro;
use rustc_session::impl_lint_pass; use rustc_session::impl_lint_pass;
use rustc_span::{BytePos, Pos, Span}; use rustc_span::{BytePos, Pos, Span};
use std::iter::once; use std::iter::once;
@ -72,7 +71,7 @@ impl RawStrings {
impl EarlyLintPass for RawStrings { impl EarlyLintPass for RawStrings {
fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &Expr) { fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &Expr) {
if let ExprKind::FormatArgs(format_args) = &expr.kind if let ExprKind::FormatArgs(format_args) = &expr.kind
&& !in_external_macro(cx.sess(), format_args.span) && !format_args.span.in_external_macro(cx.sess().source_map())
&& format_args.span.check_source_text(cx, |src| src.starts_with('r')) && format_args.span.check_source_text(cx, |src| src.starts_with('r'))
&& let Some(str) = snippet_opt(cx.sess(), format_args.span) && let Some(str) = snippet_opt(cx.sess(), format_args.span)
&& let count_hash = str.bytes().skip(1).take_while(|b| *b == b'#').count() && let count_hash = str.bytes().skip(1).take_while(|b| *b == b'#').count()
@ -95,7 +94,7 @@ impl EarlyLintPass for RawStrings {
LitKind::CStrRaw(max) => ("cr", max), LitKind::CStrRaw(max) => ("cr", max),
_ => return, _ => return,
} }
&& !in_external_macro(cx.sess(), expr.span) && !expr.span.in_external_macro(cx.sess().source_map())
&& expr.span.check_source_text(cx, |src| src.starts_with(prefix)) && expr.span.check_source_text(cx, |src| src.starts_with(prefix))
{ {
self.check_raw_string(cx, lit.symbol.as_str(), expr.span, prefix, max, lit.kind.descr()); self.check_raw_string(cx, lit.symbol.as_str(), expr.span, prefix, max, lit.kind.descr());

View file

@ -10,7 +10,6 @@ use rustc_hir::{
Closure, ClosureKind, CoroutineDesugaring, CoroutineKind, CoroutineSource, Expr, ExprKind, MatchSource, Closure, ClosureKind, CoroutineDesugaring, CoroutineKind, CoroutineSource, Expr, ExprKind, MatchSource,
}; };
use rustc_lint::{LateContext, LateLintPass}; use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::lint::in_external_macro;
use rustc_middle::ty::UpvarCapture; use rustc_middle::ty::UpvarCapture;
use rustc_session::declare_lint_pass; use rustc_session::declare_lint_pass;
@ -47,7 +46,7 @@ declare_lint_pass!(RedundantAsyncBlock => [REDUNDANT_ASYNC_BLOCK]);
impl<'tcx> LateLintPass<'tcx> for RedundantAsyncBlock { impl<'tcx> LateLintPass<'tcx> for RedundantAsyncBlock {
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
let span = expr.span; let span = expr.span;
if !in_external_macro(cx.tcx.sess, span) && if !span.in_external_macro(cx.tcx.sess.source_map()) &&
let Some(body_expr) = desugar_async_block(cx, expr) && let Some(body_expr) = desugar_async_block(cx, expr) &&
let Some(expr) = desugar_await(peel_blocks(body_expr)) && let Some(expr) = desugar_await(peel_blocks(body_expr)) &&
// The await prefix must not come from a macro as its content could change in the future. // The await prefix must not come from a macro as its content could change in the future.

View file

@ -10,7 +10,6 @@ use rustc_hir::{
}; };
use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_lint::{LateContext, LateLintPass, LintContext};
use rustc_middle::hir::nested_filter; use rustc_middle::hir::nested_filter;
use rustc_middle::lint::in_external_macro;
use rustc_middle::ty; use rustc_middle::ty;
use rustc_session::declare_lint_pass; use rustc_session::declare_lint_pass;
use rustc_span::ExpnKind; use rustc_span::ExpnKind;
@ -138,7 +137,7 @@ fn get_parent_call_exprs<'tcx>(
impl<'tcx> LateLintPass<'tcx> for RedundantClosureCall { impl<'tcx> LateLintPass<'tcx> for RedundantClosureCall {
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'tcx>) { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'tcx>) {
if in_external_macro(cx.sess(), expr.span) { if expr.span.in_external_macro(cx.sess().source_map()) {
return; return;
} }

View file

@ -2,7 +2,6 @@ use clippy_utils::diagnostics::span_lint_and_help;
use rustc_ast::ast::{Block, Expr, ExprKind, Stmt, StmtKind}; use rustc_ast::ast::{Block, Expr, ExprKind, Stmt, StmtKind};
use rustc_ast::visit::{Visitor, walk_expr}; use rustc_ast::visit::{Visitor, walk_expr};
use rustc_lint::{EarlyContext, EarlyLintPass, LintContext}; use rustc_lint::{EarlyContext, EarlyLintPass, LintContext};
use rustc_middle::lint::in_external_macro;
use rustc_session::declare_lint_pass; use rustc_session::declare_lint_pass;
declare_clippy_lint! { declare_clippy_lint! {
@ -46,7 +45,7 @@ declare_lint_pass!(RedundantElse => [REDUNDANT_ELSE]);
impl EarlyLintPass for RedundantElse { impl EarlyLintPass for RedundantElse {
fn check_stmt(&mut self, cx: &EarlyContext<'_>, stmt: &Stmt) { fn check_stmt(&mut self, cx: &EarlyContext<'_>, stmt: &Stmt) {
if in_external_macro(cx.sess(), stmt.span) { if stmt.span.in_external_macro(cx.sess().source_map()) {
return; return;
} }
// Only look at expressions that are a whole statement // Only look at expressions that are a whole statement

View file

@ -4,7 +4,6 @@ use clippy_utils::msrvs::{self, Msrv};
use rustc_ast::ast::{Expr, ExprKind}; use rustc_ast::ast::{Expr, ExprKind};
use rustc_errors::Applicability; use rustc_errors::Applicability;
use rustc_lint::{EarlyContext, EarlyLintPass, LintContext}; use rustc_lint::{EarlyContext, EarlyLintPass, LintContext};
use rustc_middle::lint::in_external_macro;
use rustc_session::impl_lint_pass; use rustc_session::impl_lint_pass;
declare_clippy_lint! { declare_clippy_lint! {
@ -56,7 +55,7 @@ impl EarlyLintPass for RedundantFieldNames {
return; return;
} }
if in_external_macro(cx.sess(), expr.span) { if expr.span.in_external_macro(cx.sess().source_map()) {
return; return;
} }
if let ExprKind::Struct(ref se) = expr.kind { if let ExprKind::Struct(ref se) = expr.kind {

View file

@ -6,7 +6,6 @@ use rustc_hir::def::Res;
use rustc_hir::{BindingMode, ByRef, ExprKind, HirId, LetStmt, Node, Pat, PatKind, QPath}; use rustc_hir::{BindingMode, ByRef, ExprKind, HirId, LetStmt, Node, Pat, PatKind, QPath};
use rustc_hir_typeck::expr_use_visitor::PlaceBase; use rustc_hir_typeck::expr_use_visitor::PlaceBase;
use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_lint::{LateContext, LateLintPass, LintContext};
use rustc_middle::lint::in_external_macro;
use rustc_middle::ty::UpvarCapture; use rustc_middle::ty::UpvarCapture;
use rustc_session::declare_lint_pass; use rustc_session::declare_lint_pass;
use rustc_span::DesugaringKind; use rustc_span::DesugaringKind;
@ -69,7 +68,7 @@ impl<'tcx> LateLintPass<'tcx> for RedundantLocals {
// the local does not affect the code's drop behavior // the local does not affect the code's drop behavior
&& !needs_ordered_drop(cx, cx.typeck_results().expr_ty(expr)) && !needs_ordered_drop(cx, cx.typeck_results().expr_ty(expr))
// the local is user-controlled // the local is user-controlled
&& !in_external_macro(cx.sess(), local.span) && !local.span.in_external_macro(cx.sess().source_map())
&& !is_from_proc_macro(cx, expr) && !is_from_proc_macro(cx, expr)
&& !is_by_value_closure_capture(cx, local.hir_id, binding_id) && !is_by_value_closure_capture(cx, local.hir_id, binding_id)
{ {

View file

@ -4,7 +4,6 @@ use rustc_errors::Applicability;
use rustc_hir::def::{DefKind, Res}; use rustc_hir::def::{DefKind, Res};
use rustc_hir::{Item, ItemKind}; use rustc_hir::{Item, ItemKind};
use rustc_lint::{LateContext, LateLintPass}; use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::lint::in_external_macro;
use rustc_middle::ty; use rustc_middle::ty;
use rustc_session::impl_lint_pass; use rustc_session::impl_lint_pass;
use rustc_span::def_id::CRATE_DEF_ID; use rustc_span::def_id::CRATE_DEF_ID;
@ -51,7 +50,7 @@ impl<'tcx> LateLintPass<'tcx> for RedundantPubCrate {
&& !cx.effective_visibilities.is_exported(item.owner_id.def_id) && !cx.effective_visibilities.is_exported(item.owner_id.def_id)
&& self.is_exported.last() == Some(&false) && self.is_exported.last() == Some(&false)
&& is_not_macro_export(item) && is_not_macro_export(item)
&& !in_external_macro(cx.sess(), item.span) && !item.span.in_external_macro(cx.sess().source_map())
{ {
let span = item.span.with_hi(item.ident.span.hi()); let span = item.span.with_hi(item.ident.span.hi());
let descr = cx.tcx.def_kind(item.owner_id).descr(item.owner_id.to_def_id()); let descr = cx.tcx.def_kind(item.owner_id).descr(item.owner_id.to_def_id());

View file

@ -6,7 +6,6 @@ use rustc_errors::Applicability;
use rustc_hir::def::Res; use rustc_hir::def::Res;
use rustc_hir::{BindingMode, Block, Expr, ExprKind, HirId, LetStmt, PatKind, QPath, Stmt, StmtKind}; use rustc_hir::{BindingMode, Block, Expr, ExprKind, HirId, LetStmt, PatKind, QPath, Stmt, StmtKind};
use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_lint::{LateContext, LateLintPass, LintContext};
use rustc_middle::lint::in_external_macro;
use rustc_session::impl_lint_pass; use rustc_session::impl_lint_pass;
use rustc_span::Span; use rustc_span::Span;
@ -72,7 +71,7 @@ impl<'tcx> LateLintPass<'tcx> for ReserveAfterInitialization {
fn check_local(&mut self, cx: &LateContext<'tcx>, local: &'tcx LetStmt<'tcx>) { fn check_local(&mut self, cx: &LateContext<'tcx>, local: &'tcx LetStmt<'tcx>) {
if let Some(init_expr) = local.init if let Some(init_expr) = local.init
&& let PatKind::Binding(BindingMode::MUT, id, _, None) = local.pat.kind && let PatKind::Binding(BindingMode::MUT, id, _, None) = local.pat.kind
&& !in_external_macro(cx.sess(), local.span) && !local.span.in_external_macro(cx.sess().source_map())
&& let Some(init) = get_vec_init_kind(cx, init_expr) && let Some(init) = get_vec_init_kind(cx, init_expr)
&& !matches!( && !matches!(
init, init,
@ -101,7 +100,7 @@ impl<'tcx> LateLintPass<'tcx> for ReserveAfterInitialization {
&& let ExprKind::Assign(left, right, _) = expr.kind && let ExprKind::Assign(left, right, _) = expr.kind
&& let ExprKind::Path(QPath::Resolved(None, path)) = left.kind && let ExprKind::Path(QPath::Resolved(None, path)) = left.kind
&& let Res::Local(id) = path.res && let Res::Local(id) = path.res
&& !in_external_macro(cx.sess(), expr.span) && !expr.span.in_external_macro(cx.sess().source_map())
&& let Some(init) = get_vec_init_kind(cx, right) && let Some(init) = get_vec_init_kind(cx, right)
&& !matches!( && !matches!(
init, init,

View file

@ -5,7 +5,6 @@ use rustc_hir::def_id::LocalDefId;
use rustc_hir::intravisit::FnKind; use rustc_hir::intravisit::FnKind;
use rustc_hir::{Body, FnDecl, OwnerId, TraitItem, TraitItemKind}; use rustc_hir::{Body, FnDecl, OwnerId, TraitItem, TraitItemKind};
use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_lint::{LateContext, LateLintPass, LintContext};
use rustc_middle::lint::in_external_macro;
use rustc_session::declare_lint_pass; use rustc_session::declare_lint_pass;
use rustc_span::{Span, sym}; use rustc_span::{Span, sym};
@ -69,7 +68,7 @@ declare_clippy_lint! {
declare_lint_pass!(ReturnSelfNotMustUse => [RETURN_SELF_NOT_MUST_USE]); declare_lint_pass!(ReturnSelfNotMustUse => [RETURN_SELF_NOT_MUST_USE]);
fn check_method(cx: &LateContext<'_>, decl: &FnDecl<'_>, fn_def: LocalDefId, span: Span, owner_id: OwnerId) { fn check_method(cx: &LateContext<'_>, decl: &FnDecl<'_>, fn_def: LocalDefId, span: Span, owner_id: OwnerId) {
if !in_external_macro(cx.sess(), span) if !span.in_external_macro(cx.sess().source_map())
// If it comes from an external macro, better ignore it. // If it comes from an external macro, better ignore it.
&& decl.implicit_self.has_implicit_self() && decl.implicit_self.has_implicit_self()
// We only show this warning for public exported methods. // We only show this warning for public exported methods.

View file

@ -17,7 +17,6 @@ use rustc_hir::{
StmtKind, StmtKind,
}; };
use rustc_lint::{LateContext, LateLintPass, Level, LintContext}; use rustc_lint::{LateContext, LateLintPass, Level, LintContext};
use rustc_middle::lint::in_external_macro;
use rustc_middle::ty::adjustment::Adjust; use rustc_middle::ty::adjustment::Adjust;
use rustc_middle::ty::{self, GenericArgKind, Ty}; use rustc_middle::ty::{self, GenericArgKind, Ty};
use rustc_session::declare_lint_pass; use rustc_session::declare_lint_pass;
@ -191,7 +190,7 @@ fn stmt_needs_never_type(cx: &LateContext<'_>, stmt_hir_id: HirId) -> bool {
impl<'tcx> LateLintPass<'tcx> for Return { impl<'tcx> LateLintPass<'tcx> for Return {
fn check_stmt(&mut self, cx: &LateContext<'tcx>, stmt: &'tcx Stmt<'_>) { fn check_stmt(&mut self, cx: &LateContext<'tcx>, stmt: &'tcx Stmt<'_>) {
if !in_external_macro(cx.sess(), stmt.span) if !stmt.span.in_external_macro(cx.sess().source_map())
&& let StmtKind::Semi(expr) = stmt.kind && let StmtKind::Semi(expr) = stmt.kind
&& let ExprKind::Ret(Some(ret)) = expr.kind && let ExprKind::Ret(Some(ret)) = expr.kind
// return Err(...)? desugars to a match // return Err(...)? desugars to a match
@ -237,8 +236,8 @@ impl<'tcx> LateLintPass<'tcx> for Return {
&& let PatKind::Binding(_, local_id, _, _) = local.pat.kind && let PatKind::Binding(_, local_id, _, _) = local.pat.kind
&& path_to_local_id(retexpr, local_id) && path_to_local_id(retexpr, local_id)
&& !last_statement_borrows(cx, initexpr) && !last_statement_borrows(cx, initexpr)
&& !in_external_macro(cx.sess(), initexpr.span) && !initexpr.span.in_external_macro(cx.sess().source_map())
&& !in_external_macro(cx.sess(), retexpr.span) && !retexpr.span.in_external_macro(cx.sess().source_map())
&& !local.span.from_expansion() && !local.span.from_expansion()
&& !span_contains_cfg(cx, stmt.span.between(retexpr.span)) && !span_contains_cfg(cx, stmt.span.between(retexpr.span))
{ {

View file

@ -6,7 +6,6 @@ use rustc_hir::def::DefKind;
use rustc_hir::def_id::LocalDefId; use rustc_hir::def_id::LocalDefId;
use rustc_hir::{Expr, ExprKind, HirId, Node}; use rustc_hir::{Expr, ExprKind, HirId, Node};
use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_lint::{LateContext, LateLintPass, LintContext};
use rustc_middle::lint::in_external_macro;
use rustc_session::impl_lint_pass; use rustc_session::impl_lint_pass;
use rustc_span::Span; use rustc_span::Span;
@ -88,7 +87,7 @@ impl SingleCallFn {
fn_span: Span, fn_span: Span,
) -> bool { ) -> bool {
(self.avoid_breaking_exported_api && cx.effective_visibilities.is_exported(fn_def_id)) (self.avoid_breaking_exported_api && cx.effective_visibilities.is_exported(fn_def_id))
|| in_external_macro(cx.sess(), fn_span) || fn_span.in_external_macro(cx.sess().source_map())
|| cx || cx
.tcx .tcx
.hir() .hir()

View file

@ -1,7 +1,6 @@
use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::diagnostics::span_lint_and_then;
use rustc_ast::ast::{GenericParam, GenericParamKind}; use rustc_ast::ast::{GenericParam, GenericParamKind};
use rustc_lint::{EarlyContext, EarlyLintPass, LintContext}; use rustc_lint::{EarlyContext, EarlyLintPass, LintContext};
use rustc_middle::lint::in_external_macro;
use rustc_session::declare_lint_pass; use rustc_session::declare_lint_pass;
declare_clippy_lint! { declare_clippy_lint! {
@ -42,7 +41,7 @@ declare_lint_pass!(SingleCharLifetimeNames => [SINGLE_CHAR_LIFETIME_NAMES]);
impl EarlyLintPass for SingleCharLifetimeNames { impl EarlyLintPass for SingleCharLifetimeNames {
fn check_generic_param(&mut self, ctx: &EarlyContext<'_>, param: &GenericParam) { fn check_generic_param(&mut self, ctx: &EarlyContext<'_>, param: &GenericParam) {
if in_external_macro(ctx.sess(), param.ident.span) { if param.ident.span.in_external_macro(ctx.sess().source_map()) {
return; return;
} }

View file

@ -8,7 +8,6 @@ use rustc_hir::def::Res;
use rustc_hir::def_id::DefId; use rustc_hir::def_id::DefId;
use rustc_hir::{HirId, Path, PathSegment}; use rustc_hir::{HirId, Path, PathSegment};
use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_lint::{LateContext, LateLintPass, LintContext};
use rustc_middle::lint::in_external_macro;
use rustc_session::impl_lint_pass; use rustc_session::impl_lint_pass;
use rustc_span::symbol::kw; use rustc_span::symbol::kw;
use rustc_span::{Span, sym}; use rustc_span::{Span, sym};
@ -112,7 +111,7 @@ impl<'tcx> LateLintPass<'tcx> for StdReexports {
if let Res::Def(_, def_id) = path.res if let Res::Def(_, def_id) = path.res
&& let Some(first_segment) = get_first_segment(path) && let Some(first_segment) = get_first_segment(path)
&& is_stable(cx, def_id, &self.msrv) && is_stable(cx, def_id, &self.msrv)
&& !in_external_macro(cx.sess(), path.span) && !path.span.in_external_macro(cx.sess().source_map())
&& !is_from_proc_macro(cx, &first_segment.ident) && !is_from_proc_macro(cx, &first_segment.ident)
{ {
let (lint, used_mod, replace_with) = match first_segment.ident.name { let (lint, used_mod, replace_with) = match first_segment.ident.name {

View file

@ -9,7 +9,6 @@ use rustc_errors::Applicability;
use rustc_hir::def_id::DefId; use rustc_hir::def_id::DefId;
use rustc_hir::{BinOpKind, BorrowKind, Expr, ExprKind, LangItem, Node, QPath}; use rustc_hir::{BinOpKind, BorrowKind, Expr, ExprKind, LangItem, Node, QPath};
use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_lint::{LateContext, LateLintPass, LintContext};
use rustc_middle::lint::in_external_macro;
use rustc_middle::ty; use rustc_middle::ty;
use rustc_session::declare_lint_pass; use rustc_session::declare_lint_pass;
use rustc_span::source_map::Spanned; use rustc_span::source_map::Spanned;
@ -147,7 +146,7 @@ declare_lint_pass!(StringAdd => [STRING_ADD, STRING_ADD_ASSIGN, STRING_SLICE]);
impl<'tcx> LateLintPass<'tcx> for StringAdd { impl<'tcx> LateLintPass<'tcx> for StringAdd {
fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) { fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) {
if in_external_macro(cx.sess(), e.span) { if e.span.in_external_macro(cx.sess().source_map()) {
return; return;
} }
match e.kind { match e.kind {
@ -284,7 +283,7 @@ impl<'tcx> LateLintPass<'tcx> for StringLitAsBytes {
); );
} }
if !in_external_macro(cx.sess(), e.span) if !e.span.in_external_macro(cx.sess().source_map())
&& let ExprKind::MethodCall(path, receiver, ..) = &e.kind && let ExprKind::MethodCall(path, receiver, ..) = &e.kind
&& path.ident.name.as_str() == "as_bytes" && path.ident.name.as_str() == "as_bytes"
&& let ExprKind::Lit(lit) = &receiver.kind && let ExprKind::Lit(lit) = &receiver.kind

View file

@ -5,7 +5,6 @@ use rustc_ast::LitKind;
use rustc_errors::Applicability; use rustc_errors::Applicability;
use rustc_hir::{BinOpKind, Expr, ExprKind}; use rustc_hir::{BinOpKind, Expr, ExprKind};
use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_lint::{LateContext, LateLintPass, LintContext};
use rustc_middle::lint::in_external_macro;
use rustc_session::declare_lint_pass; use rustc_session::declare_lint_pass;
declare_clippy_lint! { declare_clippy_lint! {
@ -32,7 +31,7 @@ declare_lint_pass!(ConfusingXorAndPow => [SUSPICIOUS_XOR_USED_AS_POW]);
impl LateLintPass<'_> for ConfusingXorAndPow { impl LateLintPass<'_> for ConfusingXorAndPow {
fn check_expr(&mut self, cx: &LateContext<'_>, expr: &Expr<'_>) { fn check_expr(&mut self, cx: &LateContext<'_>, expr: &Expr<'_>) {
if !in_external_macro(cx.sess(), expr.span) if !expr.span.in_external_macro(cx.sess().source_map())
&& let ExprKind::Binary(op, left, right) = &expr.kind && let ExprKind::Binary(op, left, right) = &expr.kind
&& op.node == BinOpKind::BitXor && op.node == BinOpKind::BitXor
&& left.span.eq_ctxt(right.span) && left.span.eq_ctxt(right.span)

View file

@ -12,7 +12,6 @@ use rustc_hir::intravisit::{Visitor, walk_expr};
use rustc_errors::Applicability; use rustc_errors::Applicability;
use rustc_hir::{BinOpKind, Block, Expr, ExprKind, LetStmt, PatKind, QPath, Stmt, StmtKind}; use rustc_hir::{BinOpKind, Block, Expr, ExprKind, LetStmt, PatKind, QPath, Stmt, StmtKind};
use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_lint::{LateContext, LateLintPass, LintContext};
use rustc_middle::lint::in_external_macro;
use rustc_middle::ty; use rustc_middle::ty;
use rustc_session::declare_lint_pass; use rustc_session::declare_lint_pass;
use rustc_span::source_map::Spanned; use rustc_span::source_map::Spanned;
@ -212,7 +211,7 @@ fn check_suspicious_swap(cx: &LateContext<'_>, block: &Block<'_>) {
if let Some((lhs0, rhs0)) = parse(first) if let Some((lhs0, rhs0)) = parse(first)
&& let Some((lhs1, rhs1)) = parse(second) && let Some((lhs1, rhs1)) = parse(second)
&& first.span.eq_ctxt(second.span) && first.span.eq_ctxt(second.span)
&& !in_external_macro(cx.sess(), first.span) && !first.span.in_external_macro(cx.sess().source_map())
&& is_same(cx, lhs0, rhs1) && is_same(cx, lhs0, rhs1)
&& is_same(cx, lhs1, rhs0) && is_same(cx, lhs1, rhs0)
&& !is_same(cx, lhs1, rhs1) // Ignore a = b; a = a (#10421) && !is_same(cx, lhs1, rhs1) // Ignore a = b; a = a (#10421)

View file

@ -2,7 +2,6 @@ use clippy_utils::diagnostics::span_lint_and_sugg;
use rustc_errors::Applicability; use rustc_errors::Applicability;
use rustc_hir::{GenericArg, HirId, LetStmt, Node, Path, TyKind}; use rustc_hir::{GenericArg, HirId, LetStmt, Node, Path, TyKind};
use rustc_lint::LateContext; use rustc_lint::LateContext;
use rustc_middle::lint::in_external_macro;
use rustc_middle::ty::Ty; use rustc_middle::ty::Ty;
use crate::transmute::MISSING_TRANSMUTE_ANNOTATIONS; use crate::transmute::MISSING_TRANSMUTE_ANNOTATIONS;
@ -44,7 +43,7 @@ pub(super) fn check<'tcx>(
expr_hir_id: HirId, expr_hir_id: HirId,
) -> bool { ) -> bool {
let last = path.segments.last().unwrap(); let last = path.segments.last().unwrap();
if in_external_macro(cx.tcx.sess, last.ident.span) { if last.ident.span.in_external_macro(cx.tcx.sess.source_map()) {
// If it comes from a non-local macro, we ignore it. // If it comes from a non-local macro, we ignore it.
return false; return false;
} }

View file

@ -7,7 +7,6 @@ use itertools::Itertools;
use rustc_ast::LitKind; use rustc_ast::LitKind;
use rustc_hir::{Expr, ExprKind, Node, PatKind}; use rustc_hir::{Expr, ExprKind, Node, PatKind};
use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_lint::{LateContext, LateLintPass, LintContext};
use rustc_middle::lint::in_external_macro;
use rustc_middle::ty::{self, Ty}; use rustc_middle::ty::{self, Ty};
use rustc_session::impl_lint_pass; use rustc_session::impl_lint_pass;
use std::iter::once; use std::iter::once;
@ -56,7 +55,7 @@ impl TupleArrayConversions {
impl LateLintPass<'_> for TupleArrayConversions { impl LateLintPass<'_> for TupleArrayConversions {
fn check_expr<'tcx>(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) { fn check_expr<'tcx>(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) {
if in_external_macro(cx.sess(), expr.span) || !self.msrv.meets(msrvs::TUPLE_ARRAY_CONVERSIONS) { if expr.span.in_external_macro(cx.sess().source_map()) || !self.msrv.meets(msrvs::TUPLE_ARRAY_CONVERSIONS) {
return; return;
} }

View file

@ -11,7 +11,6 @@ use rustc_hir as hir;
use rustc_hir::{Block, BlockCheckMode, ItemKind, Node, UnsafeSource}; use rustc_hir::{Block, BlockCheckMode, ItemKind, Node, UnsafeSource};
use rustc_lexer::{TokenKind, tokenize}; use rustc_lexer::{TokenKind, tokenize};
use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_lint::{LateContext, LateLintPass, LintContext};
use rustc_middle::lint::in_external_macro;
use rustc_session::impl_lint_pass; use rustc_session::impl_lint_pass;
use rustc_span::{BytePos, Pos, RelativeBytePos, Span, SyntaxContext}; use rustc_span::{BytePos, Pos, RelativeBytePos, Span, SyntaxContext};
@ -111,7 +110,7 @@ impl_lint_pass!(UndocumentedUnsafeBlocks => [UNDOCUMENTED_UNSAFE_BLOCKS, UNNECES
impl<'tcx> LateLintPass<'tcx> for UndocumentedUnsafeBlocks { impl<'tcx> LateLintPass<'tcx> for UndocumentedUnsafeBlocks {
fn check_block(&mut self, cx: &LateContext<'tcx>, block: &'tcx Block<'tcx>) { fn check_block(&mut self, cx: &LateContext<'tcx>, block: &'tcx Block<'tcx>) {
if block.rules == BlockCheckMode::UnsafeBlock(UnsafeSource::UserProvided) if block.rules == BlockCheckMode::UnsafeBlock(UnsafeSource::UserProvided)
&& !in_external_macro(cx.tcx.sess, block.span) && !block.span.in_external_macro(cx.tcx.sess.source_map())
&& !is_lint_allowed(cx, UNDOCUMENTED_UNSAFE_BLOCKS, block.hir_id) && !is_lint_allowed(cx, UNDOCUMENTED_UNSAFE_BLOCKS, block.hir_id)
&& !is_unsafe_from_proc_macro(cx, block.span) && !is_unsafe_from_proc_macro(cx, block.span)
&& !block_has_safety_comment(cx, block.span) && !block_has_safety_comment(cx, block.span)
@ -143,7 +142,7 @@ impl<'tcx> LateLintPass<'tcx> for UndocumentedUnsafeBlocks {
if let Some(tail) = block.expr if let Some(tail) = block.expr
&& !is_lint_allowed(cx, UNNECESSARY_SAFETY_COMMENT, tail.hir_id) && !is_lint_allowed(cx, UNNECESSARY_SAFETY_COMMENT, tail.hir_id)
&& !in_external_macro(cx.tcx.sess, tail.span) && !tail.span.in_external_macro(cx.tcx.sess.source_map())
&& let HasSafetyComment::Yes(pos) = stmt_has_safety_comment(cx, tail.span, tail.hir_id) && let HasSafetyComment::Yes(pos) = stmt_has_safety_comment(cx, tail.span, tail.hir_id)
&& let Some(help_span) = expr_has_unnecessary_safety_comment(cx, tail, pos) && let Some(help_span) = expr_has_unnecessary_safety_comment(cx, tail, pos)
{ {
@ -167,7 +166,7 @@ impl<'tcx> LateLintPass<'tcx> for UndocumentedUnsafeBlocks {
return; return;
}; };
if !is_lint_allowed(cx, UNNECESSARY_SAFETY_COMMENT, stmt.hir_id) if !is_lint_allowed(cx, UNNECESSARY_SAFETY_COMMENT, stmt.hir_id)
&& !in_external_macro(cx.tcx.sess, stmt.span) && !stmt.span.in_external_macro(cx.tcx.sess.source_map())
&& let HasSafetyComment::Yes(pos) = stmt_has_safety_comment(cx, stmt.span, stmt.hir_id) && let HasSafetyComment::Yes(pos) = stmt_has_safety_comment(cx, stmt.span, stmt.hir_id)
&& let Some(help_span) = expr_has_unnecessary_safety_comment(cx, expr, pos) && let Some(help_span) = expr_has_unnecessary_safety_comment(cx, expr, pos)
{ {
@ -184,7 +183,7 @@ impl<'tcx> LateLintPass<'tcx> for UndocumentedUnsafeBlocks {
} }
fn check_item(&mut self, cx: &LateContext<'_>, item: &hir::Item<'_>) { fn check_item(&mut self, cx: &LateContext<'_>, item: &hir::Item<'_>) {
if in_external_macro(cx.tcx.sess, item.span) { if item.span.in_external_macro(cx.tcx.sess.source_map()) {
return; return;
} }

View file

@ -3,7 +3,6 @@ use rustc_hir::intravisit::FnKind;
use rustc_hir::{Body, Expr, ExprKind, FnDecl, FnRetTy, TyKind, UnOp}; use rustc_hir::{Body, Expr, ExprKind, FnDecl, FnRetTy, TyKind, UnOp};
use rustc_hir_analysis::lower_ty; use rustc_hir_analysis::lower_ty;
use rustc_lint::{LateContext, LateLintPass}; use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::lint::in_external_macro;
use rustc_session::declare_lint_pass; use rustc_session::declare_lint_pass;
use rustc_span::Span; use rustc_span::Span;
use rustc_span::def_id::LocalDefId; use rustc_span::def_id::LocalDefId;
@ -40,7 +39,7 @@ declare_lint_pass!(UninhabitedReferences => [UNINHABITED_REFERENCES]);
impl LateLintPass<'_> for UninhabitedReferences { impl LateLintPass<'_> for UninhabitedReferences {
fn check_expr(&mut self, cx: &LateContext<'_>, expr: &'_ Expr<'_>) { fn check_expr(&mut self, cx: &LateContext<'_>, expr: &'_ Expr<'_>) {
if in_external_macro(cx.tcx.sess, expr.span) { if expr.span.in_external_macro(cx.tcx.sess.source_map()) {
return; return;
} }
@ -66,7 +65,7 @@ impl LateLintPass<'_> for UninhabitedReferences {
span: Span, span: Span,
_: LocalDefId, _: LocalDefId,
) { ) {
if in_external_macro(cx.tcx.sess, span) || matches!(kind, FnKind::Closure) { if span.in_external_macro(cx.tcx.sess.source_map()) || matches!(kind, FnKind::Closure) {
return; return;
} }
if let FnRetTy::Return(hir_ty) = fndecl.output if let FnRetTy::Return(hir_ty) = fndecl.output

View file

@ -4,7 +4,6 @@ use clippy_utils::ty::{is_type_diagnostic_item, is_uninit_value_valid_for_ty};
use clippy_utils::{SpanlessEq, is_integer_literal, is_lint_allowed, path_to_local_id, peel_hir_expr_while}; use clippy_utils::{SpanlessEq, is_integer_literal, is_lint_allowed, path_to_local_id, peel_hir_expr_while};
use rustc_hir::{Block, Expr, ExprKind, HirId, PatKind, PathSegment, Stmt, StmtKind}; use rustc_hir::{Block, Expr, ExprKind, HirId, PatKind, PathSegment, Stmt, StmtKind};
use rustc_lint::{LateContext, LateLintPass}; use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::lint::in_external_macro;
use rustc_middle::ty; use rustc_middle::ty;
use rustc_session::declare_lint_pass; use rustc_session::declare_lint_pass;
use rustc_span::{Span, sym}; use rustc_span::{Span, sym};
@ -64,7 +63,7 @@ declare_lint_pass!(UninitVec => [UNINIT_VEC]);
// Threads: https://github.com/rust-lang/rust-clippy/pull/7682#discussion_r710998368 // Threads: https://github.com/rust-lang/rust-clippy/pull/7682#discussion_r710998368
impl<'tcx> LateLintPass<'tcx> for UninitVec { impl<'tcx> LateLintPass<'tcx> for UninitVec {
fn check_block(&mut self, cx: &LateContext<'tcx>, block: &'tcx Block<'_>) { fn check_block(&mut self, cx: &LateContext<'tcx>, block: &'tcx Block<'_>) {
if !in_external_macro(cx.tcx.sess, block.span) { if !block.span.in_external_macro(cx.tcx.sess.source_map()) {
for w in block.stmts.windows(2) { for w in block.stmts.windows(2) {
if let StmtKind::Expr(expr) | StmtKind::Semi(expr) = w[1].kind { if let StmtKind::Expr(expr) | StmtKind::Semi(expr) = w[1].kind {
handle_uninit_vec_pair(cx, &w[0], expr); handle_uninit_vec_pair(cx, &w[0], expr);

View file

@ -7,7 +7,6 @@ use rustc_hir::def::{DefKind, Res};
use rustc_hir::intravisit::{Visitor, walk_body}; use rustc_hir::intravisit::{Visitor, walk_body};
use rustc_hir::{Expr, ExprKind, HirId, HirIdSet, LetStmt, MatchSource, Node, PatKind, QPath, TyKind}; use rustc_hir::{Expr, ExprKind, HirId, HirIdSet, LetStmt, MatchSource, Node, PatKind, QPath, TyKind};
use rustc_lint::{LateContext, LintContext}; use rustc_lint::{LateContext, LintContext};
use rustc_middle::lint::{in_external_macro, is_from_async_await};
use rustc_middle::ty; use rustc_middle::ty;
use super::LET_UNIT_VALUE; use super::LET_UNIT_VALUE;
@ -22,8 +21,8 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, local: &'tcx LetStmt<'_>) {
if let Some(init) = local.init if let Some(init) = local.init
&& !local.pat.span.from_expansion() && !local.pat.span.from_expansion()
&& !in_external_macro(cx.sess(), local.span) && !local.span.in_external_macro(cx.sess().source_map())
&& !is_from_async_await(local.span) && !local.span.is_from_async_await()
&& cx.typeck_results().pat_ty(local.pat).is_unit() && cx.typeck_results().pat_ty(local.pat).is_unit()
{ {
// skip `let awa = ()` // skip `let awa = ()`

View file

@ -4,7 +4,6 @@ use clippy_utils::ty::is_type_diagnostic_item;
use rustc_errors::Applicability; use rustc_errors::Applicability;
use rustc_hir::{ExprKind, Stmt, StmtKind}; use rustc_hir::{ExprKind, Stmt, StmtKind};
use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_lint::{LateContext, LateLintPass, LintContext};
use rustc_middle::lint::in_external_macro;
use rustc_session::declare_lint_pass; use rustc_session::declare_lint_pass;
use rustc_span::sym; use rustc_span::sym;
@ -39,7 +38,7 @@ impl LateLintPass<'_> for UnusedResultOk {
&& let ExprKind::MethodCall(ok_path, recv, [], ..) = expr.kind //check is expr.ok() has type Result<T,E>.ok(, _) && let ExprKind::MethodCall(ok_path, recv, [], ..) = expr.kind //check is expr.ok() has type Result<T,E>.ok(, _)
&& ok_path.ident.as_str() == "ok" && ok_path.ident.as_str() == "ok"
&& is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(recv), sym::Result) && is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(recv), sym::Result)
&& !in_external_macro(cx.sess(), stmt.span) && !stmt.span.in_external_macro(cx.sess().source_map())
{ {
let ctxt = expr.span.ctxt(); let ctxt = expr.span.ctxt();
let mut applicability = Applicability::MaybeIncorrect; let mut applicability = Applicability::MaybeIncorrect;

View file

@ -7,7 +7,6 @@ use rustc_errors::Applicability;
use rustc_hir::def::{DefKind, Res}; use rustc_hir::def::{DefKind, Res};
use rustc_hir::{Item, ItemKind, UseKind}; use rustc_hir::{Item, ItemKind, UseKind};
use rustc_lint::{LateContext, LateLintPass, LintContext as _}; use rustc_lint::{LateContext, LateLintPass, LintContext as _};
use rustc_middle::lint::in_external_macro;
use rustc_middle::ty::Visibility; use rustc_middle::ty::Visibility;
use rustc_session::impl_lint_pass; use rustc_session::impl_lint_pass;
use rustc_span::symbol::kw; use rustc_span::symbol::kw;
@ -63,7 +62,7 @@ impl_lint_pass!(UnusedTraitNames => [UNUSED_TRAIT_NAMES]);
impl<'tcx> LateLintPass<'tcx> for UnusedTraitNames { impl<'tcx> LateLintPass<'tcx> for UnusedTraitNames {
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'tcx>) { fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'tcx>) {
if self.msrv.meets(msrvs::UNDERSCORE_IMPORTS) if self.msrv.meets(msrvs::UNDERSCORE_IMPORTS)
&& !in_external_macro(cx.sess(), item.span) && !item.span.in_external_macro(cx.sess().source_map())
&& let ItemKind::Use(path, UseKind::Single) = item.kind && let ItemKind::Use(path, UseKind::Single) = item.kind
// Ignore imports that already use Underscore // Ignore imports that already use Underscore
&& item.ident.name != kw::Underscore && item.ident.name != kw::Underscore

View file

@ -8,7 +8,6 @@ use rustc_hir::{BinOpKind, Body, Expr, ExprKind, FnDecl, HirId, Node, PathSegmen
use rustc_hir_typeck::expr_use_visitor::{Delegate, ExprUseVisitor, PlaceWithHirId}; use rustc_hir_typeck::expr_use_visitor::{Delegate, ExprUseVisitor, PlaceWithHirId};
use rustc_lint::{LateContext, LateLintPass}; use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::hir::nested_filter; use rustc_middle::hir::nested_filter;
use rustc_middle::lint::in_external_macro;
use rustc_middle::mir::FakeReadCause; use rustc_middle::mir::FakeReadCause;
use rustc_middle::ty::{self, Ty, TyCtxt}; use rustc_middle::ty::{self, Ty, TyCtxt};
use rustc_session::declare_lint_pass; use rustc_session::declare_lint_pass;
@ -292,7 +291,7 @@ impl<'tcx> Visitor<'tcx> for UnwrappableVariablesVisitor<'_, 'tcx> {
fn visit_expr(&mut self, expr: &'tcx Expr<'_>) { fn visit_expr(&mut self, expr: &'tcx Expr<'_>) {
// Shouldn't lint when `expr` is in macro. // Shouldn't lint when `expr` is in macro.
if in_external_macro(self.cx.tcx.sess, expr.span) { if expr.span.in_external_macro(self.cx.tcx.sess.source_map()) {
return; return;
} }
if let Some(higher::If { cond, then, r#else }) = higher::If::hir(expr) { if let Some(higher::If { cond, then, r#else }) = higher::If::hir(expr) {

View file

@ -4,7 +4,6 @@ use core::mem::replace;
use rustc_errors::Applicability; use rustc_errors::Applicability;
use rustc_hir::{HirId, Item, ItemKind}; use rustc_hir::{HirId, Item, ItemKind};
use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_lint::{LateContext, LateLintPass, LintContext};
use rustc_middle::lint::in_external_macro;
use rustc_session::impl_lint_pass; use rustc_session::impl_lint_pass;
use rustc_span::symbol::Ident; use rustc_span::symbol::Ident;
@ -126,7 +125,7 @@ fn check_ident(cx: &LateContext<'_>, ident: &Ident, hir_id: HirId, be_aggressive
impl LateLintPass<'_> for UpperCaseAcronyms { impl LateLintPass<'_> for UpperCaseAcronyms {
fn check_item(&mut self, cx: &LateContext<'_>, it: &Item<'_>) { fn check_item(&mut self, cx: &LateContext<'_>, it: &Item<'_>) {
// do not lint public items or in macros // do not lint public items or in macros
if in_external_macro(cx.sess(), it.span) if it.span.in_external_macro(cx.sess().source_map())
|| (self.avoid_breaking_exported_api && cx.effective_visibilities.is_exported(it.owner_id.def_id)) || (self.avoid_breaking_exported_api && cx.effective_visibilities.is_exported(it.owner_id.def_id))
{ {
return; return;

Some files were not shown because too many files have changed in this diff Show more