Skip to content

Make HasTokens a sub-trait of HasAttrs.#159160

Merged
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
nnethercote:HasAttrs-HasTokens
Jul 15, 2026
Merged

Make HasTokens a sub-trait of HasAttrs.#159160
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
nnethercote:HasAttrs-HasTokens

Conversation

@nnethercote

Copy link
Copy Markdown
Contributor

Because that's what it is: any type with tokens must also have attrs. This simplifies some trait bounds.

r? @petrochenkov

Because that's what it is: any type with tokens must also have attrs.
This simplifies some trait bounds.
@rustbot

rustbot commented Jul 12, 2026

Copy link
Copy Markdown
Collaborator

The parser was modified, potentially altering the grammar of (stable) Rust
which would be a breaking change.

cc @fmease

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jul 12, 2026
@petrochenkov

Copy link
Copy Markdown
Contributor

any type with tokens must also have attrs

For context, this wasn't the case until #158942 got merged.
Before that AST fragments supported in declarative macro matchers (e.g. vis) had tokens, but didn't have attributes.

Even now we have things like WithTokens<Box<ast::Visibility>> that clearly have tokens, and don't have attributes.
With this PR this type doesn't implement HasTokens and I'm actually surprised that it's never used in contexts where implementing HasTokens is required.
So the HasTokens: HasAttrs relationship holding for the current code in the compiler is rather an accident, than true sub-typingtraiting.
@nnethercote What do you think?

@petrochenkov petrochenkov added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 13, 2026
@nnethercote

Copy link
Copy Markdown
Contributor Author

Even now we have things like WithTokens<Box<ast::Visibility>> that clearly have tokens, and don't have attributes. With this PR this type doesn't implement HasTokens and I'm actually surprised that it's never used in contexts where implementing HasTokens is required.

WithTokens<Box<ast::Visibility>> impls both HasAttrs and HasTokens. The HasAttrs impl always returns None.

@petrochenkov petrochenkov added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jul 14, 2026
@petrochenkov

Copy link
Copy Markdown
Contributor

Ah, I see, HasAttrs is actually implemented for ast::Visibility despite it having no attributes.
This is surprising, but pre-existing.
@bors r+

@rust-bors

rust-bors Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 4d0b593 has been approved by petrochenkov

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 14, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jul 14, 2026
…petrochenkov

Make `HasTokens` a sub-trait of `HasAttrs`.

Because that's what it is: any type with tokens must also have attrs. This simplifies some trait bounds.

r? @petrochenkov
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jul 14, 2026
…petrochenkov

Make `HasTokens` a sub-trait of `HasAttrs`.

Because that's what it is: any type with tokens must also have attrs. This simplifies some trait bounds.

r? @petrochenkov
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jul 14, 2026
…petrochenkov

Make `HasTokens` a sub-trait of `HasAttrs`.

Because that's what it is: any type with tokens must also have attrs. This simplifies some trait bounds.

r? @petrochenkov
rust-bors Bot pushed a commit that referenced this pull request Jul 14, 2026
…uwer

Rollup of 22 pull requests

Successful merges:

 - #156047 (Fix trait method resolution on an adjusted never type)
 - #157824 (Comptime inherent impls)
 - #158235 (Store `DefId` instead of `EiiDecl` in `EiiImplResolution::Known`)
 - #158723 (Support EII on Windows MSVC)
 - #158993 (rerun in original typing mode if we meet any opaques in post analysis)
 - #159160 (Make `HasTokens` a sub-trait of `HasAttrs`.)
 - #159183 (Introduce InstanceKind::LlvmIntrinsic)
 - #159251 (Bump rustc-perf submodule)
 - #155013 (Suggest the `[const] Destruct` bound for type parameters in const functions when missing)
 - #159155 (unstable book: Document `diagnostic_on_unknown` feature)
 - #159235 (Add regression test for #95719)
 - #159243 (inline Once wait and wait_force)
 - #159255 (Replace shortened type with `_` instead of `...` as placeholder)
 - #159259 (Add regression test for #144033)
 - #159265 (bootstrap: skip intrinsic-test when rustfmt is unavailable)
 - #159269 (disable range-len-try-from.rs on s390x)
 - #159272 (slice: make swap delegate to swap_unchecked)
 - #159274 (bootstrap: Rename `std_crates_for_run_make` to `std_crates_for_make_run`)
 - #159275 (remove obsolete comment)
 - #159277 (Construct `tokens` for attrs made by `mk_attr_word` and other variants)
 - #159283 (Remove obsolete verbose flag from deref/ref suggestions)
 - #159290 (rustc-dev-guide subtree update)
rust-bors Bot pushed a commit that referenced this pull request Jul 15, 2026
…uwer

Rollup of 22 pull requests

Successful merges:

 - #156047 (Fix trait method resolution on an adjusted never type)
 - #157824 (Comptime inherent impls)
 - #158235 (Store `DefId` instead of `EiiDecl` in `EiiImplResolution::Known`)
 - #158723 (Support EII on Windows MSVC)
 - #158993 (rerun in original typing mode if we meet any opaques in post analysis)
 - #159160 (Make `HasTokens` a sub-trait of `HasAttrs`.)
 - #159183 (Introduce InstanceKind::LlvmIntrinsic)
 - #159251 (Bump rustc-perf submodule)
 - #155013 (Suggest the `[const] Destruct` bound for type parameters in const functions when missing)
 - #159155 (unstable book: Document `diagnostic_on_unknown` feature)
 - #159235 (Add regression test for #95719)
 - #159243 (inline Once wait and wait_force)
 - #159255 (Replace shortened type with `_` instead of `...` as placeholder)
 - #159259 (Add regression test for #144033)
 - #159265 (bootstrap: skip intrinsic-test when rustfmt is unavailable)
 - #159269 (disable range-len-try-from.rs on s390x)
 - #159272 (slice: make swap delegate to swap_unchecked)
 - #159274 (bootstrap: Rename `std_crates_for_run_make` to `std_crates_for_make_run`)
 - #159275 (remove obsolete comment)
 - #159277 (Construct `tokens` for attrs made by `mk_attr_word` and other variants)
 - #159283 (Remove obsolete verbose flag from deref/ref suggestions)
 - #159290 (rustc-dev-guide subtree update)
@rust-bors rust-bors Bot merged commit 9897495 into rust-lang:main Jul 15, 2026
13 checks passed
@rustbot rustbot added this to the 1.99.0 milestone Jul 15, 2026
rust-timer added a commit that referenced this pull request Jul 15, 2026
Rollup merge of #159160 - nnethercote:HasAttrs-HasTokens, r=petrochenkov

Make `HasTokens` a sub-trait of `HasAttrs`.

Because that's what it is: any type with tokens must also have attrs. This simplifies some trait bounds.

r? @petrochenkov
@nnethercote nnethercote deleted the HasAttrs-HasTokens branch July 15, 2026 04:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants