Skip to content

Commit 519799f

Browse files
committed
Auto merge of rust-lang#75800 - Aaron1011:feature/full-nt-tokens, r=petrochenkov
Attach tokens to all AST types used in `Nonterminal` We perform token capturing when we have outer attributes (for nonterminals that support attributes - e.g. `Stmt`), or when we parse a `Nonterminal` for a `macro_rules!` argument. The full list of `Nonterminals` affected by this PR is: * `NtBlock` * `NtStmt` * `NtTy` * `NtMeta` * `NtPath` * `NtVis` * `NtLiteral` Of these nonterminals, only `NtStmt` and `NtLiteral` (which is actually just an `Expr`), support outer attributes - the rest only ever have token capturing perform when they match a `macro_rules!` argument. This makes progress towards solving rust-lang#43081 - we now collect tokens for everything that might need them. However, we still need to handle `#[cfg]`, inner attributes, and misc pretty-printing issues (e.g. rust-lang#75734) I've separated the changes into (mostly) independent commits, which could be split into individual PRs for each `Nonterminal` variant. The purpose of having them all in one PR is to do a single Crater run for all of them. Most of the changes in this PR are trivial (adding `tokens: None` everywhere we construct the various AST structs). The significant changes are: * `ast::Visibility` is changed from `type Visibility = Spanned<VisibilityKind>` to a `struct Visibility { kind, span, tokens }`. * `maybe_collect_tokens` is made generic, and used for both `ast::Expr` and `ast::Stmt`. * Some of the statement-parsing functions are refactored so that we can capture the trailing semicolon. * `Nonterminal` and `Expr` both grew by 8 bytes, as some of the structs which are stored inline (rather than behind a `P`) now have an `Option<TokenStream>` field. Hopefully the performance impact of doing this is negligible.
2 parents a12828a + 8808dc6 commit 519799f

File tree

4 files changed

+6
-6
lines changed

4 files changed

+6
-6
lines changed

clippy_lints/src/enum_variants.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ impl EarlyLintPass for EnumVariantNames {
285285
);
286286
}
287287
}
288-
if item.vis.node.is_pub() {
288+
if item.vis.kind.is_pub() {
289289
let matching = partial_match(mod_camel, &item_camel);
290290
let rmatching = partial_rmatch(mod_camel, &item_camel);
291291
let nchars = mod_camel.chars().count();
@@ -316,7 +316,7 @@ impl EarlyLintPass for EnumVariantNames {
316316
}
317317
}
318318
if let ItemKind::Enum(ref def, _) = item.kind {
319-
let lint = match item.vis.node {
319+
let lint = match item.vis.kind {
320320
VisibilityKind::Public => PUB_ENUM_VARIANT_NAMES,
321321
_ => ENUM_VARIANT_NAMES,
322322
};

clippy_lints/src/manual_non_exhaustive.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ fn check_manual_non_exhaustive_enum(cx: &EarlyContext<'_>, item: &Item, variants
122122

123123
fn check_manual_non_exhaustive_struct(cx: &EarlyContext<'_>, item: &Item, data: &VariantData) {
124124
fn is_private(field: &StructField) -> bool {
125-
matches!(field.vis.node, VisibilityKind::Inherited)
125+
matches!(field.vis.kind, VisibilityKind::Inherited)
126126
}
127127

128128
fn is_non_exhaustive_marker(field: &StructField) -> bool {
@@ -141,7 +141,7 @@ fn check_manual_non_exhaustive_struct(cx: &EarlyContext<'_>, item: &Item, data:
141141

142142
let fields = data.fields();
143143
let private_fields = fields.iter().filter(|f| is_private(f)).count();
144-
let public_fields = fields.iter().filter(|f| f.vis.node.is_pub()).count();
144+
let public_fields = fields.iter().filter(|f| f.vis.kind.is_pub()).count();
145145

146146
if_chain! {
147147
if private_fields == 1 && public_fields >= 1 && public_fields == fields.len() - 1;

clippy_lints/src/single_component_path_imports.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ impl EarlyLintPass for SingleComponentPathImports {
4141
if_chain! {
4242
if !in_macro(item.span);
4343
if cx.sess.opts.edition == Edition::Edition2018;
44-
if !item.vis.node.is_pub();
44+
if !item.vis.kind.is_pub();
4545
if let ItemKind::Use(use_tree) = &item.kind;
4646
if let segments = &use_tree.prefix.segments;
4747
if segments.len() == 1;

clippy_lints/src/utils/ast_utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ pub fn eq_defaultness(l: Defaultness, r: Defaultness) -> bool {
394394

395395
pub fn eq_vis(l: &Visibility, r: &Visibility) -> bool {
396396
use VisibilityKind::*;
397-
match (&l.node, &r.node) {
397+
match (&l.kind, &r.kind) {
398398
(Public, Public) | (Inherited, Inherited) | (Crate(_), Crate(_)) => true,
399399
(Restricted { path: l, .. }, Restricted { path: r, .. }) => eq_path(l, r),
400400
_ => false,

0 commit comments

Comments
 (0)