Skip to content

Commit 93d0885

Browse files
committed
Auto merge of rust-lang#138740 - nnethercote:ast-ItemKind-idents, r=fmease
Move `ast::Item::ident` into `ast::ItemKind` The follow-up to rust-lang#138384, which did the same thing for `hir::ItemKind`. r? `@fmease`
2 parents a50fb22 + 3f752b4 commit 93d0885

10 files changed

+101
-48
lines changed

clippy_lints/src/crate_in_macro_def.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ declare_lint_pass!(CrateInMacroDef => [CRATE_IN_MACRO_DEF]);
5353

5454
impl EarlyLintPass for CrateInMacroDef {
5555
fn check_item(&mut self, cx: &EarlyContext<'_>, item: &Item) {
56-
if let ItemKind::MacroDef(macro_def) = &item.kind
56+
if let ItemKind::MacroDef(_, macro_def) = &item.kind
5757
&& item.attrs.iter().any(is_macro_export)
5858
&& let Some(span) = contains_unhygienic_crate_reference(&macro_def.body.tokens)
5959
{

clippy_lints/src/doc/needless_doctest_main.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@ use rustc_parse::parser::ForceCollect;
1313
use rustc_session::parse::ParseSess;
1414
use rustc_span::edition::Edition;
1515
use rustc_span::source_map::{FilePathMapping, SourceMap};
16-
use rustc_span::{FileName, Pos, sym};
16+
use rustc_span::{FileName, Ident, Pos, sym};
1717

1818
use super::Fragments;
1919

20-
fn get_test_spans(item: &Item, test_attr_spans: &mut Vec<Range<usize>>) {
20+
fn get_test_spans(item: &Item, ident: Ident, test_attr_spans: &mut Vec<Range<usize>>) {
2121
test_attr_spans.extend(
2222
item.attrs
2323
.iter()
2424
.find(|attr| attr.has_name(sym::test))
25-
.map(|attr| attr.span.lo().to_usize()..item.ident.span.hi().to_usize()),
25+
.map(|attr| attr.span.lo().to_usize()..ident.span.hi().to_usize()),
2626
);
2727
}
2828

@@ -64,10 +64,10 @@ pub fn check(
6464
match parser.parse_item(ForceCollect::No) {
6565
Ok(Some(item)) => match &item.kind {
6666
ItemKind::Fn(box Fn {
67-
sig, body: Some(block), ..
68-
}) if item.ident.name == sym::main => {
67+
ident, sig, body: Some(block), ..
68+
}) if ident.name == sym::main => {
6969
if !ignore {
70-
get_test_spans(&item, &mut test_attr_spans);
70+
get_test_spans(&item, *ident, &mut test_attr_spans);
7171
}
7272
let is_async = matches!(sig.header.coroutine_kind, Some(CoroutineKind::Async { .. }));
7373
let returns_nothing = match &sig.decl.output {
@@ -85,10 +85,10 @@ pub fn check(
8585
}
8686
},
8787
// Another function was found; this case is ignored for needless_doctest_main
88-
ItemKind::Fn(box Fn { .. }) => {
88+
ItemKind::Fn(fn_) => {
8989
eligible = false;
9090
if !ignore {
91-
get_test_spans(&item, &mut test_attr_spans);
91+
get_test_spans(&item, fn_.ident, &mut test_attr_spans);
9292
}
9393
},
9494
// Tests with one of these items are ignored

clippy_lints/src/duplicate_mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ impl_lint_pass!(DuplicateMod => [DUPLICATE_MOD]);
6363

6464
impl EarlyLintPass for DuplicateMod {
6565
fn check_item(&mut self, cx: &EarlyContext<'_>, item: &Item) {
66-
if let ItemKind::Mod(_, ModKind::Loaded(_, Inline::No, mod_spans, _)) = &item.kind
66+
if let ItemKind::Mod(_, _, ModKind::Loaded(_, Inline::No, mod_spans, _)) = &item.kind
6767
&& let FileName::Real(real) = cx.sess().source_map().span_to_filename(mod_spans.inner_span)
6868
&& let Some(local_path) = real.into_local_path()
6969
&& let Ok(absolute_path) = local_path.canonicalize()

clippy_lints/src/empty_line_after.rs

+10-9
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ use rustc_errors::{Applicability, Diag, SuggestionStyle};
88
use rustc_lexer::TokenKind;
99
use rustc_lint::{EarlyContext, EarlyLintPass, LintContext};
1010
use rustc_session::impl_lint_pass;
11-
use rustc_span::symbol::kw;
12-
use rustc_span::{BytePos, ExpnKind, Ident, InnerSpan, Span, SpanData, Symbol};
11+
use rustc_span::{BytePos, ExpnKind, Ident, InnerSpan, Span, SpanData, Symbol, kw};
1312

1413
declare_clippy_lint! {
1514
/// ### What it does
@@ -375,21 +374,23 @@ impl EmptyLineAfter {
375374
&mut self,
376375
cx: &EarlyContext<'_>,
377376
kind: &ItemKind,
378-
ident: &Ident,
377+
ident: Option<Ident>,
379378
span: Span,
380379
attrs: &[Attribute],
381380
id: NodeId,
382381
) {
383382
self.items.push(ItemInfo {
384383
kind: kind.descr(),
385-
name: ident.name,
386-
span: if span.contains(ident.span) {
384+
// FIXME: this `sym::empty` can be leaked, see
385+
// https://github.com/rust-lang/rust/pull/138740#discussion_r2021979899
386+
name: if let Some(ident) = ident { ident.name } else { kw::Empty },
387+
span: if let Some(ident) = ident {
387388
span.with_hi(ident.span.hi())
388389
} else {
389390
span.with_hi(span.lo())
390391
},
391392
mod_items: match kind {
392-
ItemKind::Mod(_, ModKind::Loaded(items, _, _, _)) => items
393+
ItemKind::Mod(_, _, ModKind::Loaded(items, _, _, _)) => items
393394
.iter()
394395
.filter(|i| !matches!(i.span.ctxt().outer_expn_data().kind, ExpnKind::AstPass(_)))
395396
.map(|i| i.id)
@@ -471,7 +472,7 @@ impl EarlyLintPass for EmptyLineAfter {
471472
self.check_item_kind(
472473
cx,
473474
&item.kind.clone().into(),
474-
&item.ident,
475+
item.kind.ident(),
475476
item.span,
476477
&item.attrs,
477478
item.id,
@@ -482,14 +483,14 @@ impl EarlyLintPass for EmptyLineAfter {
482483
self.check_item_kind(
483484
cx,
484485
&item.kind.clone().into(),
485-
&item.ident,
486+
item.kind.ident(),
486487
item.span,
487488
&item.attrs,
488489
item.id,
489490
);
490491
}
491492

492493
fn check_item(&mut self, cx: &EarlyContext<'_>, item: &Item) {
493-
self.check_item_kind(cx, &item.kind, &item.ident, item.span, &item.attrs, item.id);
494+
self.check_item_kind(cx, &item.kind, item.kind.ident(), item.span, &item.attrs, item.id);
494495
}
495496
}

clippy_lints/src/empty_with_brackets.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,9 @@ declare_lint_pass!(EmptyWithBrackets => [EMPTY_STRUCTS_WITH_BRACKETS, EMPTY_ENUM
7474

7575
impl EarlyLintPass for EmptyWithBrackets {
7676
fn check_item(&mut self, cx: &EarlyContext<'_>, item: &Item) {
77-
let span_after_ident = item.span.with_lo(item.ident.span.hi());
78-
79-
if let ItemKind::Struct(var_data, _) = &item.kind
77+
if let ItemKind::Struct(ident, var_data, _) = &item.kind
8078
&& has_brackets(var_data)
79+
&& let span_after_ident = item.span.with_lo(ident.span.hi())
8180
&& has_no_fields(cx, var_data, span_after_ident)
8281
{
8382
span_lint_and_then(

clippy_lints/src/field_scoped_visibility_modifiers.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ declare_lint_pass!(FieldScopedVisibilityModifiers => [FIELD_SCOPED_VISIBILITY_MO
5151

5252
impl EarlyLintPass for FieldScopedVisibilityModifiers {
5353
fn check_item(&mut self, cx: &EarlyContext<'_>, item: &Item) {
54-
let ItemKind::Struct(ref st, _) = item.kind else {
54+
let ItemKind::Struct(_, ref st, _) = item.kind else {
5555
return;
5656
};
5757
for field in st.fields() {

clippy_lints/src/multiple_bound_locations.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ declare_lint_pass!(MultipleBoundLocations => [MULTIPLE_BOUND_LOCATIONS]);
3939

4040
impl EarlyLintPass for MultipleBoundLocations {
4141
fn check_fn(&mut self, cx: &EarlyContext<'_>, kind: FnKind<'_>, _: Span, _: NodeId) {
42-
if let FnKind::Fn(_, _, _, Fn { generics, .. }) = kind
42+
if let FnKind::Fn(_, _, Fn { generics, .. }) = kind
4343
&& !generics.params.is_empty()
4444
&& !generics.where_clause.predicates.is_empty()
4545
{

clippy_lints/src/partial_pub_fields.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ declare_lint_pass!(PartialPubFields => [PARTIAL_PUB_FIELDS]);
4141

4242
impl EarlyLintPass for PartialPubFields {
4343
fn check_item(&mut self, cx: &EarlyContext<'_>, item: &Item) {
44-
let ItemKind::Struct(ref st, _) = item.kind else {
44+
let ItemKind::Struct(_, ref st, _) = item.kind else {
4545
return;
4646
};
4747

clippy_lints/src/single_component_path_imports.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -174,11 +174,11 @@ impl SingleComponentPathImports {
174174
}
175175

176176
match &item.kind {
177-
ItemKind::Mod(_, ModKind::Loaded(items, ..)) => {
177+
ItemKind::Mod(_, _, ModKind::Loaded(items, ..)) => {
178178
self.check_mod(items);
179179
},
180-
ItemKind::MacroDef(MacroDef { macro_rules: true, .. }) => {
181-
macros.push(item.ident.name);
180+
ItemKind::MacroDef(ident, MacroDef { macro_rules: true, .. }) => {
181+
macros.push(ident.name);
182182
},
183183
ItemKind::Use(use_tree) => {
184184
let segments = &use_tree.prefix.segments;

0 commit comments

Comments
 (0)