Skip to content

Commit 8584e93

Browse files
authored
Rollup merge of rust-lang#149790 - JonathanBrouwer:attr-path-perf, r=jdonszelmann
Remove `Span` from segments of `AttrPath` r? jdonszelmann
2 parents a767bf7 + 4d0dbee commit 8584e93

9 files changed

Lines changed: 29 additions & 27 deletions

File tree

clippy_lints/src/attrs/allow_attributes.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,19 @@ use clippy_utils::is_from_proc_macro;
44
use rustc_ast::{AttrStyle, Attribute};
55
use rustc_errors::Applicability;
66
use rustc_lint::{EarlyContext, LintContext};
7+
use rustc_ast::attr::AttributeExt;
78

89
// Separate each crate's features.
910
pub fn check<'cx>(cx: &EarlyContext<'cx>, attr: &'cx Attribute) {
1011
if !attr.span.in_external_macro(cx.sess().source_map())
1112
&& let AttrStyle::Outer = attr.style
12-
&& let Some(ident) = attr.ident()
13+
&& let Some(path_span) = attr.path_span()
1314
&& !is_from_proc_macro(cx, attr)
1415
{
1516
#[expect(clippy::collapsible_span_lint_calls, reason = "rust-clippy#7797")]
16-
span_lint_and_then(cx, ALLOW_ATTRIBUTES, ident.span, "#[allow] attribute found", |diag| {
17+
span_lint_and_then(cx, ALLOW_ATTRIBUTES, path_span, "#[allow] attribute found", |diag| {
1718
diag.span_suggestion(
18-
ident.span,
19+
path_span,
1920
"replace it with",
2021
"expect",
2122
Applicability::MachineApplicable,

clippy_lints/src/attrs/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -574,16 +574,16 @@ impl EarlyLintPass for PostExpansionEarlyAttributes {
574574

575575
fn check_attribute(&mut self, cx: &EarlyContext<'_>, attr: &Attribute) {
576576
if let Some(items) = &attr.meta_item_list()
577-
&& let Some(ident) = attr.ident()
577+
&& let Some(name) = attr.name()
578578
{
579-
if matches!(ident.name, sym::allow) && self.msrv.meets(msrvs::LINT_REASONS_STABILIZATION) {
579+
if matches!(name, sym::allow) && self.msrv.meets(msrvs::LINT_REASONS_STABILIZATION) {
580580
allow_attributes::check(cx, attr);
581581
}
582-
if matches!(ident.name, sym::allow | sym::expect) && self.msrv.meets(msrvs::LINT_REASONS_STABILIZATION) {
583-
allow_attributes_without_reason::check(cx, ident.name, items, attr);
582+
if matches!(name, sym::allow | sym::expect) && self.msrv.meets(msrvs::LINT_REASONS_STABILIZATION) {
583+
allow_attributes_without_reason::check(cx, name, items, attr);
584584
}
585-
if is_lint_level(ident.name, attr.id) {
586-
blanket_clippy_restriction_lints::check(cx, ident.name, items);
585+
if is_lint_level(name, attr.id) {
586+
blanket_clippy_restriction_lints::check(cx, name, items);
587587
}
588588
if items.is_empty() || !attr.has_name(sym::deprecated) {
589589
return;

clippy_lints/src/attrs/useless_attribute.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub(super) fn check(cx: &EarlyContext<'_>, item: &Item, attrs: &[Attribute]) {
1515
return;
1616
}
1717
if let Some(lint_list) = &attr.meta_item_list()
18-
&& attr.ident().is_some_and(|ident| is_lint_level(ident.name, attr.id))
18+
&& attr.name().is_some_and(|name| is_lint_level(name, attr.id))
1919
{
2020
for lint in lint_list {
2121
match item.kind {

clippy_lints/src/incompatible_msrv.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ fn is_under_cfg_attribute(cx: &LateContext<'_>, hir_id: HirId) -> bool {
270270
cx.tcx.hir_parent_id_iter(hir_id).any(|id| {
271271
cx.tcx.hir_attrs(id).iter().any(|attr| {
272272
matches!(
273-
attr.ident().map(|ident| ident.name),
273+
attr.name(),
274274
Some(sym::cfg_trace | sym::cfg_attr_trace)
275275
)
276276
})

clippy_lints/src/missing_doc.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,8 +287,8 @@ fn is_doc_attr(attr: &Attribute) -> bool {
287287
match attr {
288288
Attribute::Parsed(AttributeKind::DocComment { .. }) => true,
289289
Attribute::Unparsed(attr)
290-
if let [ident] = &*attr.path.segments
291-
&& ident.name == sym::doc =>
290+
if let [name] = &*attr.path.segments
291+
&& *name == sym::doc =>
292292
{
293293
matches!(attr.args, AttrArgs::Eq { .. })
294294
},

clippy_utils/src/attrs.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@ pub fn get_builtin_attr<'a, A: AttributeExt + 'a>(
2020
name: Symbol,
2121
) -> impl Iterator<Item = &'a A> {
2222
attrs.iter().filter(move |attr| {
23-
if let Some([clippy, segment2]) = attr.ident_path().as_deref()
24-
&& clippy.name == sym::clippy
23+
if let [clippy, segment2] = &*attr.path()
24+
&& *clippy == sym::clippy
2525
{
26-
let new_name = match segment2.name {
26+
let path_span = attr.path_span().expect("Clippy attributes are unparsed and have a span");
27+
let new_name = match *segment2 {
2728
sym::cyclomatic_complexity => Some("cognitive_complexity"),
2829
sym::author
2930
| sym::version
@@ -35,25 +36,25 @@ pub fn get_builtin_attr<'a, A: AttributeExt + 'a>(
3536
| sym::has_significant_drop
3637
| sym::format_args => None,
3738
_ => {
38-
sess.dcx().span_err(segment2.span, "usage of unknown attribute");
39+
sess.dcx().span_err(path_span, "usage of unknown attribute");
3940
return false;
4041
},
4142
};
4243

4344
match new_name {
4445
Some(new_name) => {
4546
sess.dcx()
46-
.struct_span_err(segment2.span, "usage of deprecated attribute")
47+
.struct_span_err(path_span, "usage of deprecated attribute")
4748
.with_span_suggestion(
48-
segment2.span,
49+
path_span,
4950
"consider using",
50-
new_name,
51+
format!("clippy::{}", new_name),
5152
Applicability::MachineApplicable,
5253
)
5354
.emit();
5455
false
5556
},
56-
None => segment2.name == name,
57+
None => *segment2 == name,
5758
}
5859
} else {
5960
false

clippy_utils/src/check_proc_macro.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,9 +348,9 @@ fn fn_kind_pat(tcx: TyCtxt<'_>, kind: &FnKind<'_>, body: &Body<'_>, hir_id: HirI
348348
fn attr_search_pat(attr: &Attribute) -> (Pat, Pat) {
349349
match attr.kind {
350350
AttrKind::Normal(..) => {
351-
if let Some(ident) = attr.ident() {
351+
if let Some(name) = attr.name() {
352352
// NOTE: This will likely have false positives, like `allow = 1`
353-
let ident_string = ident.to_string();
353+
let ident_string = name.to_string();
354354
if attr.style == AttrStyle::Outer {
355355
(
356356
Pat::OwnedMultiStr(vec!["#[".to_owned() + &ident_string, ident_string]),
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error: usage of deprecated attribute
2-
--> tests/ui/renamed_builtin_attr.rs:3:11
2+
--> tests/ui/renamed_builtin_attr.rs:3:3
33
|
44
LL | #[clippy::cyclomatic_complexity = "1"]
5-
| ^^^^^^^^^^^^^^^^^^^^^ help: consider using: `cognitive_complexity`
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `clippy::cognitive_complexity`
66

77
error: aborting due to 1 previous error
88

tests/ui/unknown_attribute.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error: usage of unknown attribute
2-
--> tests/ui/unknown_attribute.rs:3:11
2+
--> tests/ui/unknown_attribute.rs:3:3
33
|
44
LL | #[clippy::unknown]
5-
| ^^^^^^^
5+
| ^^^^^^^^^^^^^^^
66

77
error: aborting due to 1 previous error
88

0 commit comments

Comments
 (0)