Skip to content

reflection: enable tool attributes to be reflectable - #166037

Merged
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
Tess4552:reflection-register-reflecting-tools
Nov 18, 2026
Merged

rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
Tess4552:reflection-register-reflecting-tools

Conversation

@Tess4552

@Tess4552 Tess4552 commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

View all comments

Adds an option to the register_tool crate level attribute to allow the option to be reflective. Tool attributes of these registered tools are queryable from a TypeId object. Encoded the reflectivity of an attribute in Attribute::Tool because the attributes can come from another crate and tools are reflective at the crate level.

Addresses the FIXME introduced in #165810

Maybe we should run a perf run for it, not sure if the change to Attribute::Tool would impact it.

r? @oli-obk
cc @mejrs

@rustbot

rustbot commented Nov 16, 2026

Copy link
Copy Markdown
Collaborator

Some changes occurred in compiler/rustc_attr_parsing

cc @jdonszelmann, @JonathanBrouwer

The reflection data structures are tied exactly to the implementation
in the compiler. Make sure to also adjust rustc_const_eval/src/const_eval/type_info.rs

cc @oli-obk

Some changes occurred in compiler/rustc_attr_ir

cc @jdonszelmann, @JonathanBrouwer

These commits modify the Cargo.lock file. Unintentional changes to Cargo.lock can be introduced when switching branches and rebasing PRs.

If this was unintentional then you should revert the changes before this PR is merged.
Otherwise, you can ignore this comment.

Some changes occurred in compiler/rustc_passes/src/check_attr.rs

cc @jdonszelmann, @JonathanBrouwer

Some changes occurred to the CTFE machinery

cc @RalfJung, @oli-obk, @lcnr

@rustbot rustbot added A-attributes Area: Attributes (`#[…]`, `#![…]`) A-rustdoc-json Area: Rustdoc JSON backend S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 16, 2026
@rustbot rustbot added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels Nov 16, 2026
@rustbot

rustbot commented Nov 16, 2026

Copy link
Copy Markdown
Collaborator

r? @chenyukang

rustbot has assigned @chenyukang.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 79 candidates
  • Random selection from 19 candidates

@rustbot rustbot assigned oli-obk and unassigned chenyukang Nov 16, 2026
@JonathanBrouwer

Copy link
Copy Markdown
Member

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Nov 16, 2026
rust-bors Bot pushed a commit that referenced this pull request Nov 16, 2026
…, r=<try>

reflection: enable tool attributes to be reflectable
@rust-bors

This comment has been minimized.

///
/// Tool attributes, with the exception of diagnostic attributes, are not converted into a
/// parsed form.
Tool(Box<AttrItem>),

@JonathanBrouwer JonathanBrouwer Nov 16, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer if this was implemented by looking up the tool options in the RegisteredTools when needed, rather than re-storing it in every attribute. Is that implementable?

View changes since the review

@JonathanBrouwer JonathanBrouwer Nov 16, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tess explained to me that because tool options might differ between crates, it's kinda annoying to find the right ToolOptions that correspond to this attribute, so the implementation in this PR is fine for now

rustc_ast_pretty = { path = "../rustc_ast_pretty" }
rustc_data_structures = { path = "../rustc_data_structures" }
rustc_error_messages = { path = "../rustc_error_messages" }
rustc_lint_defs = { path = "../rustc_lint_defs" }

@JonathanBrouwer JonathanBrouwer Nov 16, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is already a transitive dependency through rustc_errors, so this is fine and won't regress bootstrap times :)

View changes since the review

@JonathanBrouwer JonathanBrouwer self-assigned this Nov 16, 2026
@rust-log-analyzer

This comment has been minimized.

@mejrs mejrs self-assigned this Nov 16, 2026
@Tess4552
Tess4552 force-pushed the reflection-register-reflecting-tools branch from 304cc46 to e0ac4cc Compare November 16, 2026 09:56
@rustbot

rustbot commented Nov 16, 2026

Copy link
Copy Markdown
Collaborator

clippy is developed in its own repository. If possible, consider making this change to rust-lang/rust-clippy instead.

cc @rust-lang/clippy

@rustbot rustbot added the T-clippy Relevant to the Clippy team. label Nov 16, 2026
@Tess4552
Tess4552 force-pushed the reflection-register-reflecting-tools branch from e0ac4cc to e40ff07 Compare November 16, 2026 10:08
@rust-bors

rust-bors Bot commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: befcd13 (befcd13a14cb6cb670405b9311741d16f68b3d93)
Base parent: 5fb8a16 (5fb8a16f5f8244f9fbfe696487a9da223168a6c7)

@rust-timer

This comment has been minimized.

@JonathanBrouwer JonathanBrouwer left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Attribute part is fine with me now, I'll let Oli review the rest
(I'll unsubscribe from this PR, ping me if you need me)

View changes since this review

@Tess4552
Tess4552 force-pushed the reflection-register-reflecting-tools branch 2 times, most recently from 2a06740 to 1f1599d Compare November 16, 2026 11:49
@rustbot

rustbot commented Nov 16, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@rust-log-analyzer

This comment has been minimized.

@Tess4552
Tess4552 force-pushed the reflection-register-reflecting-tools branch from 1f1599d to cc11ed1 Compare November 16, 2026 12:14

@mejrs mejrs left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I do #![register_tool(rustfmt(reflect))] is is possible to reflect on it? Since it's already implicitly registered?

Similarly, #![register_tool(diagnostic(reflect))] cannot work since diagnostic attributes are parsed, and do not show up as tool attributes.

Can you also add tests for reflect tools being registered via -Zcrate-attr over command line?

View changes since this review

Comment thread compiler/rustc_lint_defs/src/lib.rs Resolved
@Tess4552
Tess4552 force-pushed the reflection-register-reflecting-tools branch from cc11ed1 to 73a18dd Compare November 17, 2026 10:21
@Tess4552

Tess4552 commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor Author

Made it an error when someone reflects on a predefined attribute. If we want to be able to reflect on these attribute later, we would have to plan on dealing with parsed tool attributes like diagnostic.

Also added a test for tools registered via -Zcrate-attr.

@oli-obk oli-obk left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adjust diagnostic phrasing as discussed in sync meeting

@bors delegate+

r=me with the above

View changes since this review

@rust-bors

rust-bors Bot commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

✌️ @Tess4552, you can now approve this pull request!

If @oli-obk told you to "r=me" after making some further change, then please make that change and post @bors r=oli-obk.

View changes since this delegation.

@rustbot rustbot 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 Nov 17, 2026
@rustbot

rustbot commented Nov 17, 2026

Copy link
Copy Markdown
Collaborator

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@Tess4552
Tess4552 force-pushed the reflection-register-reflecting-tools branch from 73a18dd to 48e98b4 Compare November 17, 2026 20:06
@Tess4552

Copy link
Copy Markdown
Contributor Author

@bors r=oli-obk

@rust-bors

rust-bors Bot commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 48e98b4 has been approved by oli-obk

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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Nov 17, 2026
Zalathar added a commit to Zalathar/rust that referenced this pull request Nov 18, 2026
…cting-tools, r=oli-obk

reflection: enable tool attributes to be reflectable

Adds an option to the `register_tool` crate level attribute to allow the option to be reflective. Tool attributes of these registered tools are queryable from a `TypeId` object. Encoded the reflectivity of an attribute in `Attribute::Tool` because the attributes can come from another crate and tools are reflective at the crate level.

Addresses the FIXME introduced in rust-lang#165810

Maybe we should run a perf run for it, not sure if the change to `Attribute::Tool` would impact it.

r? @oli-obk
cc @mejrs
rust-bors Bot pushed a commit that referenced this pull request Nov 18, 2026
Rollup of 16 pull requests

Successful merges:

 - #166037 (reflection: enable tool attributes to be reflectable)
 - #165008 (Support `NonNull` pointers as `asm!` input operands)
 - #165465 (Use `emit_ptr_va_arg` for `va_arg` on M68k)
 - #166042 (Fix out of scope method suggestion)
 - #166090 (bootstrap: rebuild LLD when LLVM changes)
 - #159795 (Introduce `-Z pack-coroutine-layout` flag)
 - #163556 (arm: only f32 and f64 are valid HFA bases)
 - #164665 (Add Reference annotations for inline assembly)
 - #165725 (change target modifier errors to use the diagnostic APIs instead of structs)
 - #165912 (simplify `fluent_value_from_str_list_sep_by_and`)
 - #165982 (compiler: Stop special-casing `report_in_external_macro` in `declare_tool_lint!`)
 - #166006 (Detect method shadowed by another when accessing a field or calling method that isn't found in method chain)
 - #166083 (Record seeds in the appropriate order)
 - #166104 (abi/bad-custom.rs: make test run on all editions)
 - #166124 (platform-support: add amaanq as powerpc64-unknown-linux-gnuelfv2 maintainer)
 - #166127 (Add tests from failed attempt at implementing `hir::Param` move)

Failed merges:

 - #165094 (reflection: doc attributes from adts, fields, and variants)
rust-bors Bot pushed a commit that referenced this pull request Nov 18, 2026
…uwer

Rollup of 15 pull requests

Successful merges:

 - #166037 (reflection: enable tool attributes to be reflectable)
 - #165465 (Use `emit_ptr_va_arg` for `va_arg` on M68k)
 - #166042 (Fix out of scope method suggestion)
 - #166090 (bootstrap: rebuild LLD when LLVM changes)
 - #159795 (Introduce `-Z pack-coroutine-layout` flag)
 - #163556 (arm: only f32 and f64 are valid HFA bases)
 - #164665 (Add Reference annotations for inline assembly)
 - #165725 (change target modifier errors to use the diagnostic APIs instead of structs)
 - #165912 (simplify `fluent_value_from_str_list_sep_by_and`)
 - #165982 (compiler: Stop special-casing `report_in_external_macro` in `declare_tool_lint!`)
 - #166006 (Detect method shadowed by another when accessing a field or calling method that isn't found in method chain)
 - #166083 (Record seeds in the appropriate order)
 - #166104 (abi/bad-custom.rs: make test run on all editions)
 - #166124 (platform-support: add amaanq as powerpc64-unknown-linux-gnuelfv2 maintainer)
 - #166127 (Add tests from failed attempt at implementing `hir::Param` move)

Failed merges:

 - #165094 (reflection: doc attributes from adts, fields, and variants)
@rust-bors
rust-bors Bot merged commit a10a9da into rust-lang:main Nov 18, 2026
14 checks passed
@rustbot rustbot added this to the 1.102.0 milestone Nov 18, 2026
rust-bors Bot pushed a commit that referenced this pull request Nov 18, 2026
Rollup merge of #166037 - Tess4552:reflection-register-reflecting-tools, r=oli-obk

reflection: enable tool attributes to be reflectable

Adds an option to the `register_tool` crate level attribute to allow the option to be reflective. Tool attributes of these registered tools are queryable from a `TypeId` object. Encoded the reflectivity of an attribute in `Attribute::Tool` because the attributes can come from another crate and tools are reflective at the crate level.

Addresses the FIXME introduced in #165810

Maybe we should run a perf run for it, not sure if the change to `Attribute::Tool` would impact it.

r? @oli-obk
cc @mejrs
feliperodri added a commit to Tiramisu-Cake/kani that referenced this pull request Nov 19, 2026
Upgrades the Rust toolchain from nightly-2026-11-18 to
nightly-2026-11-19. The automated upgrade failed in `cargo build-dev`
because of two rustc API changes in this range:

- rust-lang/rust#166037 ("reflection: enable tool attributes to be
reflectable"): `Attribute::Tool(Box<AttrItem>)` became `Attribute::Tool
{ item, opts }`. The four matches in `kani_middle/attributes.rs` now
bind the `item` field.
- rust-lang/rust#164544 (`rustc_intrinsic(llvm = "...")`):
`IntrinsicDef::name` is now `Intrinsic::{Rustc(Symbol), Backend { llvm
}}`. The `simd_bitmask` check in `kani_middle/intrinsics.rs` now
compares against `Intrinsic::Rustc(sym::simd_bitmask)`. Nothing in
core/std uses the new `Backend` variant in this nightly, so there is no
new handling for it.

- `TargetDataLayout::i8_align` was removed: the alignment of `i8` is no
longer part of the data layout (`Integer::I8.align` is always 1). The
LLBC backend (`codegen_aeneas_llbc/mir_to_ullbc/mod.rs`) now uses
`rustc_abi::Integer::I8.align` for the `Bool`, `I8` and `U8` alignments
it reports to Charon.

No tests change.

### Testing
Locally, with CBMC 6.11.0:
- `cargo build-dev`, `cargo build-dev -- --features cprover --features
llbc`, `./scripts/kani-fmt.sh` and `cargo clippy -p kani-compiler`
succeed; `./scripts/kani-llbc-regression.sh` passes.
- These suites have no failures: `expected` (562 passed), `cargo-kani`
(72), `cargo-ui` (30) and `script-based-pre` (102).
- `kani` (655 passed, 2 failed) and `ui` (170 passed, 2 failed) have
failures that also occur on `main` in the same local environment:
`Quantifiers/typed_variables.rs` and `Quantifiers/arbitrary_range.rs`,
and `loop-contracts-synthesis/main_{signed,unsigned}`, which need a
`goto-synthesizer` binary that isn't installed locally.
- Unit tests for `kani-compiler`, `kani-driver`, `kani_metadata` and
`cprover_bindings` pass.

Resolves model-checking#5200

By submitting this pull request, I confirm that my contribution is made
under the terms of the Apache 2.0 and MIT licenses.

---------

Signed-off-by: Felipe Monteiro <[email protected]>
yermakoffivan pushed a commit to yermakoffivan/rust-clippy that referenced this pull request Nov 20, 2026
…uwer

Rollup of 15 pull requests

Successful merges:

 - rust-lang/rust#166037 (reflection: enable tool attributes to be reflectable)
 - rust-lang/rust#165465 (Use `emit_ptr_va_arg` for `va_arg` on M68k)
 - rust-lang/rust#166042 (Fix out of scope method suggestion)
 - rust-lang/rust#166090 (bootstrap: rebuild LLD when LLVM changes)
 - rust-lang/rust#159795 (Introduce `-Z pack-coroutine-layout` flag)
 - rust-lang/rust#163556 (arm: only f32 and f64 are valid HFA bases)
 - rust-lang/rust#164665 (Add Reference annotations for inline assembly)
 - rust-lang/rust#165725 (change target modifier errors to use the diagnostic APIs instead of structs)
 - rust-lang/rust#165912 (simplify `fluent_value_from_str_list_sep_by_and`)
 - rust-lang/rust#165982 (compiler: Stop special-casing `report_in_external_macro` in `declare_tool_lint!`)
 - rust-lang/rust#166006 (Detect method shadowed by another when accessing a field or calling method that isn't found in method chain)
 - rust-lang/rust#166083 (Record seeds in the appropriate order)
 - rust-lang/rust#166104 (abi/bad-custom.rs: make test run on all editions)
 - rust-lang/rust#166124 (platform-support: add amaanq as powerpc64-unknown-linux-gnuelfv2 maintainer)
 - rust-lang/rust#166127 (Add tests from failed attempt at implementing `hir::Param` move)

Failed merges:

 - rust-lang/rust#165094 (reflection: doc attributes from adts, fields, and variants)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-attributes Area: Attributes (`#[…]`, `#![…]`) A-rustdoc-json Area: Rustdoc JSON backend S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-clippy Relevant to the Clippy team. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants