Skip to content

Tweak some of our internal #[rustc_*] TEST attributes#153300

Merged
rust-bors[bot] merged 7 commits intorust-lang:mainfrom
fmease:test-attrs-tweaks
Mar 5, 2026
Merged

Tweak some of our internal #[rustc_*] TEST attributes#153300
rust-bors[bot] merged 7 commits intorust-lang:mainfrom
fmease:test-attrs-tweaks

Conversation

@fmease
Copy link
Member

@fmease fmease commented Mar 2, 2026

I think I might be the one who's used the internal TEST attrs #[rustc_{dump_predicates,object_lifetime_default,outlives,variance}] the most in recent times, I might even be the only one. As such I've noticed some recent-ish issues that haven't been fixed so far and which keep bothering me. Moreover I have a longstanding urge to rename several of these attributes which I couldn't contain anymore.

#[rustc_*] TEST attributes are internal attributes that basically allow you to dump the output of specific queries for use in UI tests or for debugging purposes.

  1. When some of these attributes were ported over to the new parsing API, their targets were unnecessarily restricted. I've kept encountering these incorrect "attribute cannot be used" errors all the while HIR analysis happily & correctly dumped the requested data below it. I've now relaxed their targets.
  2. Since we now have target checking for the internal attributes I figured that it's unhelpful if we still intentionally crashed on invalid targets, so I've got rid of that.
  3. I've always been annoyed that most of these (very old) attributes don't contain the word dump in their name (rendering their purpose non-obvious) and that some of their names diverge quite a bit from the corresponding query name. I've now rectified that. The new names take longer to type but it's still absolutely acceptable imo.

I haven't renamed all of the TEST attributes to follow the rustc_dump_ scheme since that's quite tedious. If it's okay with you I'd like to postpone that (e.g., rustc_{def_path,hidden_type…,layout,regions,symbol_name}).

I've noticed that the parsers for TEST attrs are spread across rustc_dump.rs, rustc_internal.rs & test_attrs.rs which is a bit confusing. Since the new names are prefixed with rustc_dump_ I've moved their parsers into rustc_dump.rs but of course they are still TEST attrs. IIRC, test_attrs.rs also contains non-rustc_-TEST attrs, so we can't just merge these two files. I guess that'll sort itself out in the future when I tackle the other internal TEST attrs.

r? Jana || Jonathan

@rustbot
Copy link
Collaborator

rustbot commented Mar 2, 2026

Some changes occurred in compiler/rustc_attr_parsing

cc @jdonszelmann, @JonathanBrouwer

Some changes occurred in compiler/rustc_hir/src/attrs

cc @jdonszelmann, @JonathanBrouwer

The rustc-dev-guide subtree was changed. If this PR only touches the dev guide consider submitting a PR directly to rust-lang/rustc-dev-guide otherwise thank you for updating the dev guide with your changes.

cc @BoxyUwU, @jieyouxu, @Kobzol, @tshepang

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

cc @jdonszelmann, @JonathanBrouwer

@rustbot rustbot added A-attributes Area: Attributes (`#[…]`, `#![…]`) A-rustc-dev-guide Area: rustc-dev-guide 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 Mar 2, 2026
@fmease fmease changed the title Test attrs tweaks Tweak some of our internal #[rustc_*] TEST attributes Mar 2, 2026
@fmease fmease force-pushed the test-attrs-tweaks branch from 36414b9 to 4de4b61 Compare March 2, 2026 18:25
fmease added 7 commits March 2, 2026 19:31
…iance}]`

* `#[dump_predicates]` works on any definition for which query `predicates_of` returns a useful (!) result
* `#[rustc_object_lifetime_default]` works on any definition for which query `object_lifetime_default`
  returns a useful (!) result for type parameters
* `#[rustc_variance]` works on any definition for which query `variances_of` returns a useful (!) result

When these attributes were ported to the new attribute parsing API,
their targets were unnecessarily restricted.
…the wrong item kind

Attr parsing already reports an error for this, an subsequent ICE isn't really helpful.

Side note: We certainly don't want convert the `bug!(…)`s in the respective queries to
delayed bugs! It's imperative that these queries eagerly complain about misuse to prevent
dormant bugs!
@fmease fmease force-pushed the test-attrs-tweaks branch from 4de4b61 to 722fcbb Compare March 2, 2026 18:31
@JonathanBrouwer
Copy link
Contributor

@bors r+ rollup

@rust-bors
Copy link
Contributor

rust-bors bot commented Mar 4, 2026

📌 Commit 722fcbb has been approved by JonathanBrouwer

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 Mar 4, 2026
rust-bors bot pushed a commit that referenced this pull request Mar 4, 2026
…uwer

Rollup of 12 pull requests

Successful merges:

 - #153402 (miri subtree update)
 - #152164 (Lint unused features)
 - #152801 (Refactor WriteBackendMethods a bit)
 - #153196 (Update path separators to be available in const context)
 - #153204 (Add `#[must_use]` attribute to `HashMap` and `HashSet` constructors)
 - #153317 (Abort after `representability` errors)
 - #153276 (Remove `cycle_fatal` query modifier)
 - #153300 (Tweak some of our internal `#[rustc_*]` TEST attributes)
 - #153396 (use `minicore` in some `run-make` tests)
 - #153401 (Migrationg of `LintDiagnostic` - part 7)
 - #153406 (Remove a ping for myself)
 - #153414 (Rename translation -> formatting)
rust-bors bot pushed a commit that referenced this pull request Mar 4, 2026
…uwer

Rollup of 12 pull requests

Successful merges:

 - #153402 (miri subtree update)
 - #152164 (Lint unused features)
 - #152801 (Refactor WriteBackendMethods a bit)
 - #153196 (Update path separators to be available in const context)
 - #153204 (Add `#[must_use]` attribute to `HashMap` and `HashSet` constructors)
 - #153317 (Abort after `representability` errors)
 - #153276 (Remove `cycle_fatal` query modifier)
 - #153300 (Tweak some of our internal `#[rustc_*]` TEST attributes)
 - #153396 (use `minicore` in some `run-make` tests)
 - #153401 (Migrationg of `LintDiagnostic` - part 7)
 - #153406 (Remove a ping for myself)
 - #153414 (Rename translation -> formatting)
rust-bors bot pushed a commit that referenced this pull request Mar 4, 2026
…uwer

Rollup of 12 pull requests

Successful merges:

 - #153402 (miri subtree update)
 - #152164 (Lint unused features)
 - #152801 (Refactor WriteBackendMethods a bit)
 - #153196 (Update path separators to be available in const context)
 - #153204 (Add `#[must_use]` attribute to `HashMap` and `HashSet` constructors)
 - #153317 (Abort after `representability` errors)
 - #153276 (Remove `cycle_fatal` query modifier)
 - #153300 (Tweak some of our internal `#[rustc_*]` TEST attributes)
 - #153396 (use `minicore` in some `run-make` tests)
 - #153401 (Migrationg of `LintDiagnostic` - part 7)
 - #153406 (Remove a ping for myself)
 - #153414 (Rename translation -> formatting)
rust-bors bot pushed a commit that referenced this pull request Mar 5, 2026
…uwer

Rollup of 12 pull requests



Successful merges:

 - #153402 (miri subtree update)
 - #152164 (Lint unused features)
 - #152801 (Refactor WriteBackendMethods a bit)
 - #153196 (Update path separators to be available in const context)
 - #153204 (Add `#[must_use]` attribute to `HashMap` and `HashSet` constructors)
 - #153317 (Abort after `representability` errors)
 - #153276 (Remove `cycle_fatal` query modifier)
 - #153300 (Tweak some of our internal `#[rustc_*]` TEST attributes)
 - #153396 (use `minicore` in some `run-make` tests)
 - #153401 (Migrationg of `LintDiagnostic` - part 7)
 - #153406 (Remove a ping for myself)
 - #153414 (Rename translation -> formatting)
@rust-bors rust-bors bot merged commit 23e2734 into rust-lang:main Mar 5, 2026
11 checks passed
@rustbot rustbot added this to the 1.96.0 milestone Mar 5, 2026
rust-timer added a commit that referenced this pull request Mar 5, 2026
Rollup merge of #153300 - fmease:test-attrs-tweaks, r=JonathanBrouwer

Tweak some of our internal `#[rustc_*]` TEST attributes

I think I might be the one who's used the internal TEST attrs `#[rustc_{dump_predicates,object_lifetime_default,outlives,variance}]` the most in recent times, I might even be the only one. As such I've noticed some recent-ish issues that haven't been fixed so far and which keep bothering me. Moreover I have a longstanding urge to rename several of these attributes which I couldn't contain anymore.

[`#[rustc_*]` TEST attributes](https://rustc-dev-guide.rust-lang.org/compiler-debugging.html#rustc_-test-attributes) are internal attributes that basically allow you to dump the output of specific queries for use in UI tests or for debugging purposes.

1. When some of these attributes were ported over to the new parsing API, their targets were unnecessarily restricted. I've kept encountering these incorrect "attribute cannot be used" errors all the while HIR analysis happily & correctly dumped the requested data below it. I've now relaxed their targets.
2. Since we now have target checking for the internal attributes I figured that it's unhelpful if we still intentionally crashed on invalid targets, so I've got rid of that.
3. I've always been annoyed that most of these (very old) attributes don't contain the word `dump` in their name (rendering their purpose non-obvious) and that some of their names diverge quite a bit from the corresponding query name. I've now rectified that. The new names take longer to type but it's still absolutely acceptable imo.

---

I haven't renamed all of the TEST attributes to follow the `rustc_dump_` scheme since that's quite tedious. If it's okay with you I'd like to postpone that (e.g., `rustc_{def_path,hidden_type…,layout,regions,symbol_name}`).

I've noticed that the parsers for TEST attrs are spread across `rustc_dump.rs`, `rustc_internal.rs` & `test_attrs.rs` which is a bit confusing. Since the new names are prefixed with `rustc_dump_` I've moved their parsers into `rustc_dump.rs` but of course they are still TEST attrs. IIRC, `test_attrs.rs` also contains non-`rustc_`-TEST attrs, so we can't just merge these two files. I guess that'll sort itself out in the future when I tackle the other internal TEST attrs.

r\? Jana || Jonathan
github-actions bot pushed a commit to rust-lang/rust-analyzer that referenced this pull request Mar 5, 2026
…uwer

Rollup of 12 pull requests



Successful merges:

 - rust-lang/rust#153402 (miri subtree update)
 - rust-lang/rust#152164 (Lint unused features)
 - rust-lang/rust#152801 (Refactor WriteBackendMethods a bit)
 - rust-lang/rust#153196 (Update path separators to be available in const context)
 - rust-lang/rust#153204 (Add `#[must_use]` attribute to `HashMap` and `HashSet` constructors)
 - rust-lang/rust#153317 (Abort after `representability` errors)
 - rust-lang/rust#153276 (Remove `cycle_fatal` query modifier)
 - rust-lang/rust#153300 (Tweak some of our internal `#[rustc_*]` TEST attributes)
 - rust-lang/rust#153396 (use `minicore` in some `run-make` tests)
 - rust-lang/rust#153401 (Migrationg of `LintDiagnostic` - part 7)
 - rust-lang/rust#153406 (Remove a ping for myself)
 - rust-lang/rust#153414 (Rename translation -> formatting)
github-actions bot pushed a commit to rust-lang/miri that referenced this pull request Mar 5, 2026
…uwer

Rollup of 12 pull requests



Successful merges:

 - rust-lang/rust#153402 (miri subtree update)
 - rust-lang/rust#152164 (Lint unused features)
 - rust-lang/rust#152801 (Refactor WriteBackendMethods a bit)
 - rust-lang/rust#153196 (Update path separators to be available in const context)
 - rust-lang/rust#153204 (Add `#[must_use]` attribute to `HashMap` and `HashSet` constructors)
 - rust-lang/rust#153317 (Abort after `representability` errors)
 - rust-lang/rust#153276 (Remove `cycle_fatal` query modifier)
 - rust-lang/rust#153300 (Tweak some of our internal `#[rustc_*]` TEST attributes)
 - rust-lang/rust#153396 (use `minicore` in some `run-make` tests)
 - rust-lang/rust#153401 (Migrationg of `LintDiagnostic` - part 7)
 - rust-lang/rust#153406 (Remove a ping for myself)
 - rust-lang/rust#153414 (Rename translation -> formatting)
@fmease fmease deleted the test-attrs-tweaks branch March 5, 2026 07:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-attributes Area: Attributes (`#[…]`, `#![…]`) A-rustc-dev-guide Area: rustc-dev-guide 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.

4 participants