Skip to content

Add #[rustc_dump_generics] attribute#157384

Open
addiesh wants to merge 1 commit into
rust-lang:mainfrom
addiesh:turbofisherwoman
Open

Add #[rustc_dump_generics] attribute#157384
addiesh wants to merge 1 commit into
rust-lang:mainfrom
addiesh:turbofisherwoman

Conversation

@addiesh

@addiesh addiesh commented Jun 3, 2026

Copy link
Copy Markdown

View all comments

Added a rustc attribute to dump the generic parameters of a given item to the compiler output.

@rustbot

rustbot commented Jun 3, 2026

Copy link
Copy Markdown
Collaborator

Some changes occurred in compiler/rustc_attr_parsing

cc @jdonszelmann, @JonathanBrouwer

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

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, @tshepang

@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 Jun 3, 2026
@rustbot

rustbot commented Jun 3, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @oli-obk (or someone else) some time within the next two weeks.

Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue

Comment thread compiler/rustc_attr_parsing/src/attributes/rustc_dump.rs
Comment thread compiler/rustc_hir_analysis/src/collect/dump.rs Outdated
@addiesh addiesh force-pushed the turbofisherwoman branch from c240b2b to 08cf89c Compare June 3, 2026 15:27
@rustbot

This comment has been minimized.

@rustbot

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@jdonszelmann jdonszelmann self-assigned this Jun 4, 2026
@jdonszelmann

Copy link
Copy Markdown
Contributor

I can review the attrs part!

Allow(Target::Struct),
Allow(Target::Enum),
Allow(Target::Union),
Allow(Target::Trait),

@jdonszelmann jdonszelmann Jun 4, 2026

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.

You'll probably want a test using it on a trait some day, because I imagine the interaction can be a bit more involved for that. Im not quite sure how far along this is from proof of concept to done. You might want to initially not support traits if that test gives you trouble?

View changes since the review

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Just added a test for a trait, but it's definitely not exhaustive. Let me know your thoughts.

Comment thread compiler/rustc_attr_parsing/src/attributes/rustc_dump.rs Outdated
Comment thread compiler/rustc_hir_analysis/src/collect/dump.rs Outdated
Comment thread compiler/rustc_attr_parsing/src/attributes/rustc_dump.rs
Comment thread compiler/rustc_hir_analysis/src/collect/dump.rs Outdated
Comment thread compiler/rustc_hir_analysis/src/collect/dump.rs Outdated
Comment thread compiler/rustc_hir_analysis/src/collect/dump.rs Outdated
Comment thread compiler/rustc_hir_analysis/src/collect/dump.rs Outdated
Comment thread library/backtrace
@addiesh addiesh marked this pull request as draft June 8, 2026 16:27
@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 Jun 8, 2026
@addiesh addiesh force-pushed the turbofisherwoman branch from 2bae2d2 to 7f0f6e0 Compare June 10, 2026 14:50
@addiesh addiesh marked this pull request as ready for review June 10, 2026 14:58
@rustbot rustbot 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 Jun 10, 2026
@oli-obk

oli-obk commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

@bors r+ rollup

@rust-bors

rust-bors Bot commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 7f0f6e0 has been approved by oli-obk

It is now in the queue for this repository.

@rust-bors rust-bors Bot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 10, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jun 10, 2026
Add `#[rustc_dump_generics]` attribute

Added a rustc attribute to dump the generic parameters of a given item to the compiler output.
jhpratt added a commit to jhpratt/rust that referenced this pull request Jun 10, 2026
Add `#[rustc_dump_generics]` attribute

Added a rustc attribute to dump the generic parameters of a given item to the compiler output.
rust-bors Bot pushed a commit that referenced this pull request Jun 10, 2026
Rollup of 23 pull requests

Successful merges:

 - #157280 (traits: Allow escaping self types in ExistentialTraitRef::with_self_ty)
 - #157282 (Fix post-monomorphization error note race in the parallel frontend)
 - #157352 (Make the retained dep graph deterministic under the parallel frontend)
 - #157601 (Emit error for unused target expression in glob and list delegations)
 - #157611 (Update `browser-ui-test` version to `0.24.0`)
 - #157620 (Add a strategy FnMut to inject behavior into the flush cycle)
 - #157645 (Windows TLS - Only register the `atexit` hook when `cleanup` can be unloaded)
 - #157647 (Start using comptime for reflection intrinsics and their wrapper functions)
 - #157719 (resolve: Partially revert "Remove a special case for dummy imports")
 - #156497 (fix-155516: Don't suggest wrong unwrap expect)
 - #156583 (Support defaults for static EIIs)
 - #157013 (Ensure inferred let pattern types are well-formed)
 - #157230 (borrowck: avoid ICE describing fields on generic params)
 - #157288 (platform support: add SNaN erratum to MIPS targets)
 - #157350 (compiletest: ignore SVG `y` offset in by-lines comparison)
 - #157355 (Add `or_try_*` variants for `HashMap` and `BTreeMap` Entry APIs)
 - #157384 (Add `#[rustc_dump_generics]` attribute)
 - #157577 (Fix parser error recovery treating 'dyn' as a strict keyword in Rust 2015 when used in `dyn + dyn`)
 - #157670 (Rename `errors.rs` file to `diagnostics.rs` (4/N))
 - #157691 (Move symbol hiding code to a new file)
 - #157697 (Add more tests that exercise the well-formedness checking of lazy type aliases)
 - #157700 (Rename `errors.rs` file to `diagnostics.rs` (5/N))
 - #157703 (Fix doc link to Instant sub in saturating caveat)

Failed merges:

 - #157699 (Arg splat experiment - hir FnDecl impl)
rust-bors Bot pushed a commit that referenced this pull request Jun 11, 2026
Rollup of 23 pull requests

Successful merges:

 - #157280 (traits: Allow escaping self types in ExistentialTraitRef::with_self_ty)
 - #157282 (Fix post-monomorphization error note race in the parallel frontend)
 - #157352 (Make the retained dep graph deterministic under the parallel frontend)
 - #157601 (Emit error for unused target expression in glob and list delegations)
 - #157611 (Update `browser-ui-test` version to `0.24.0`)
 - #157620 (Add a strategy FnMut to inject behavior into the flush cycle)
 - #157645 (Windows TLS - Only register the `atexit` hook when `cleanup` can be unloaded)
 - #157647 (Start using comptime for reflection intrinsics and their wrapper functions)
 - #157719 (resolve: Partially revert "Remove a special case for dummy imports")
 - #156497 (fix-155516: Don't suggest wrong unwrap expect)
 - #156583 (Support defaults for static EIIs)
 - #157013 (Ensure inferred let pattern types are well-formed)
 - #157230 (borrowck: avoid ICE describing fields on generic params)
 - #157288 (platform support: add SNaN erratum to MIPS targets)
 - #157350 (compiletest: ignore SVG `y` offset in by-lines comparison)
 - #157355 (Add `or_try_*` variants for `HashMap` and `BTreeMap` Entry APIs)
 - #157384 (Add `#[rustc_dump_generics]` attribute)
 - #157577 (Fix parser error recovery treating 'dyn' as a strict keyword in Rust 2015 when used in `dyn + dyn`)
 - #157670 (Rename `errors.rs` file to `diagnostics.rs` (4/N))
 - #157691 (Move symbol hiding code to a new file)
 - #157697 (Add more tests that exercise the well-formedness checking of lazy type aliases)
 - #157700 (Rename `errors.rs` file to `diagnostics.rs` (5/N))
 - #157703 (Fix doc link to Instant sub in saturating caveat)

Failed merges:

 - #157699 (Arg splat experiment - hir FnDecl impl)
@jhpratt

jhpratt commented Jun 11, 2026

Copy link
Copy Markdown
Member

@bors r-

#157726 (comment)

@rust-bors rust-bors Bot 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-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Jun 11, 2026
@rust-bors

rust-bors Bot commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

This pull request was unapproved.

This PR was contained in a rollup (#157726), which was unapproved.

View changes since this unapproval

@rustbot

This comment has been minimized.

@rustbot

This comment has been minimized.

@rustbot rustbot added the has-merge-commits PR has merge commits, merge with caution. label Jun 11, 2026
@addiesh addiesh force-pushed the turbofisherwoman branch from ccd13cf to 7f0f6e0 Compare June 11, 2026 03:07
@rustbot

This comment has been minimized.

@rustbot rustbot removed has-merge-commits PR has merge commits, merge with caution. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jun 11, 2026
@addiesh addiesh force-pushed the turbofisherwoman branch from 7f0f6e0 to 6f6f157 Compare June 11, 2026 03:28
@rustbot

rustbot commented Jun 11, 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.

@mejrs

mejrs commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

@bors try jobs=i686-gnu-nopt-1

@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Jun 11, 2026
Add `#[rustc_dump_generics]` attribute


try-job: i686-gnu-nopt-1
@rust-bors rust-bors Bot added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Jun 11, 2026
@rust-bors

rust-bors Bot commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

💔 Test for 87945f8 failed: CI. Failed job:

@rust-log-analyzer

Copy link
Copy Markdown
Collaborator

The job i686-gnu-nopt-1 failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
572           has_self: false,
573           has_late_bound_regions: None,

Note: some mismatched output was normalized before being compared
-               DefId(0:8 ~ dump_generics[c1f6]::NiceOfTheFoundation::U): 5,
-               DefId(0:7 ~ dump_generics[c1f6]::NiceOfTheFoundation::T): 4,
-               DefId(0:6 ~ dump_generics[c1f6]::NiceOfTheFoundation::N): 3,
-               DefId(0:5 ~ dump_generics[c1f6]::NiceOfTheFoundation::'_b): 2,
-               DefId(0:4 ~ dump_generics[c1f6]::NiceOfTheFoundation::'_a): 1,
-               DefId(0:3 ~ dump_generics[c1f6]::NiceOfTheFoundation): 0,
-               DefId(0:17 ~ dump_generics[c1f6]::IHopeItMadeLotsOfCode::'a): 1,
-               DefId(0:16 ~ dump_generics[c1f6]::IHopeItMadeLotsOfCode): 0,
-               DefId(0:21 ~ dump_generics[c1f6]::IHopeItMadeLotsOfCode::U): 5,
-               DefId(0:20 ~ dump_generics[c1f6]::IHopeItMadeLotsOfCode::T): 4,
-               DefId(0:19 ~ dump_generics[c1f6]::IHopeItMadeLotsOfCode::N): 3,
-               DefId(0:18 ~ dump_generics[c1f6]::IHopeItMadeLotsOfCode::'b): 2,
-               DefId(0:34 ~ dump_generics[c1f6]::HaveTakenOver::N): 2,
-               DefId(0:33 ~ dump_generics[c1f6]::HaveTakenOver::'b): 1,
-               DefId(0:32 ~ dump_generics[c1f6]::HaveTakenOver::'a): 0,
-               DefId(0:36 ~ dump_generics[c1f6]::HaveTakenOver::U): 4,
-               DefId(0:35 ~ dump_generics[c1f6]::HaveTakenOver::T): 3,
-               DefId(0:59 ~ dump_generics[c1f6]::i_dare_you::N): 1,
-               DefId(0:57 ~ dump_generics[c1f6]::i_dare_you::'a): 0,
-               DefId(0:61 ~ dump_generics[c1f6]::i_dare_you::U): 3,
-               DefId(0:60 ~ dump_generics[c1f6]::i_dare_you::T): 2,
+               DefId(..): 5,
+               DefId(..): 3,
+               DefId(..): 0,
+               DefId(..): 1,
+               DefId(..): 5,
+               DefId(..): 2,
+               DefId(..): 1,
+               DefId(..): 4,
+               DefId(..): 3,
+               DefId(..): 2,
+               DefId(..): 0,
+               DefId(..): 4,
+               DefId(..): 2,
+               DefId(..): 4,
+               DefId(..): 1,
+               DefId(..): 3,
+               DefId(..): 1,
+               DefId(..): 3,
+               DefId(..): 0,


The actual stderr differed from the expected stderr
To update references, rerun the tests and pass the `--bless` flag
To only update this specific test, also pass `--test-args attributes/dump_generics.rs`

error: 1 errors occurred comparing output.
status: exit status: 1
command: env -u RUSTC_LOG_COLOR RUSTC_ICE="0" RUST_BACKTRACE="short" "/checkout/obj/build/i686-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/attributes/dump_generics.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/cargo" "-Z" "ignore-directory-in-diagnostics-source-blocks=/checkout/vendor" "--sysroot" "/checkout/obj/build/i686-unknown-linux-gnu/stage2" "--target=i686-unknown-linux-gnu" "--check-cfg" "cfg(test,FALSE)" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/i686-unknown-linux-gnu/test/ui/attributes/dump_generics" "-A" "unused" "-W" "unused_attributes" "-A" "internal_features" "-A" "incomplete_features" "-A" "unused_parens" "-A" "unused_braces" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/i686-unknown-linux-gnu/native/rust-test-helpers"
stdout: none
--- stderr -------------------------------
error: rustc_dump_generics: DefId(0:3 ~ dump_generics[c1f6]::NiceOfTheFoundation)
##[error]  --> /checkout/tests/ui/attributes/dump_generics.rs:8:1
   |
LL | trait NiceOfTheFoundation<'_a: '_a, '_b, const N: usize, T, U: Clone> {
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
note: Generics {
          parent: None,
          parent_count: 0,
          own_params: [
              GenericParamDef {
                  name: "Self",
                  def_id: DefId(0:3 ~ dump_generics[c1f6]::NiceOfTheFoundation),
                  index: 0,
                  pure_wrt_drop: false,
                  kind: Type {
                      has_default: false,
                      synthetic: false,
                  },
              },
              GenericParamDef {
                  name: "'_a",
                  def_id: DefId(0:4 ~ dump_generics[c1f6]::NiceOfTheFoundation::'_a),
                  index: 1,
                  pure_wrt_drop: false,
                  kind: Lifetime,
              },
              GenericParamDef {
                  name: "'_b",
                  def_id: DefId(0:5 ~ dump_generics[c1f6]::NiceOfTheFoundation::'_b),
                  index: 2,
                  pure_wrt_drop: false,
                  kind: Lifetime,
              },
              GenericParamDef {
                  name: "N",
                  def_id: DefId(0:6 ~ dump_generics[c1f6]::NiceOfTheFoundation::N),
                  index: 3,
                  pure_wrt_drop: false,
                  kind: Const {
                      has_default: false,
                  },
              },
              GenericParamDef {
                  name: "T",
                  def_id: DefId(0:7 ~ dump_generics[c1f6]::NiceOfTheFoundation::T),
                  index: 4,
                  pure_wrt_drop: false,
                  kind: Type {
                      has_default: false,
                      synthetic: false,
                  },
              },
              GenericParamDef {
                  name: "U",
                  def_id: DefId(0:8 ~ dump_generics[c1f6]::NiceOfTheFoundation::U),
                  index: 5,
                  pure_wrt_drop: false,
                  kind: Type {
                      has_default: false,
                      synthetic: false,
                  },
              },
          ],
          param_def_id_to_index: {
              DefId(0:8 ~ dump_generics[c1f6]::NiceOfTheFoundation::U): 5,
              DefId(0:7 ~ dump_generics[c1f6]::NiceOfTheFoundation::T): 4,
              DefId(0:6 ~ dump_generics[c1f6]::NiceOfTheFoundation::N): 3,
              DefId(0:5 ~ dump_generics[c1f6]::NiceOfTheFoundation::'_b): 2,
              DefId(0:4 ~ dump_generics[c1f6]::NiceOfTheFoundation::'_a): 1,
              DefId(0:3 ~ dump_generics[c1f6]::NiceOfTheFoundation): 0,
          },
          has_self: true,
          has_late_bound_regions: None,
      }
  --> /checkout/tests/ui/attributes/dump_generics.rs:8:1
   |
LL | trait NiceOfTheFoundation<'_a: '_a, '_b, const N: usize, T, U: Clone> {
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: rustc_dump_generics: DefId(0:16 ~ dump_generics[c1f6]::IHopeItMadeLotsOfCode)
##[error]  --> /checkout/tests/ui/attributes/dump_generics.rs:28:1
   |
LL | pub trait IHopeItMadeLotsOfCode<'a, 'b, const N: usize, T, U: Clone>
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
note: Generics {
          parent: None,
          parent_count: 0,
          own_params: [
              GenericParamDef {
                  name: "Self",
                  def_id: DefId(0:16 ~ dump_generics[c1f6]::IHopeItMadeLotsOfCode),
                  index: 0,
                  pure_wrt_drop: false,
                  kind: Type {
                      has_default: false,
                      synthetic: false,
                  },
              },
              GenericParamDef {
                  name: "'a",
                  def_id: DefId(0:17 ~ dump_generics[c1f6]::IHopeItMadeLotsOfCode::'a),
                  index: 1,
                  pure_wrt_drop: false,
                  kind: Lifetime,
              },
              GenericParamDef {
                  name: "'b",
                  def_id: DefId(0:18 ~ dump_generics[c1f6]::IHopeItMadeLotsOfCode::'b),
                  index: 2,
                  pure_wrt_drop: false,
                  kind: Lifetime,
              },
              GenericParamDef {
                  name: "N",
                  def_id: DefId(0:19 ~ dump_generics[c1f6]::IHopeItMadeLotsOfCode::N),
                  index: 3,
                  pure_wrt_drop: false,
                  kind: Const {
                      has_default: false,
                  },
              },
              GenericParamDef {
                  name: "T",
                  def_id: DefId(0:20 ~ dump_generics[c1f6]::IHopeItMadeLotsOfCode::T),
                  index: 4,
                  pure_wrt_drop: false,
                  kind: Type {
                      has_default: false,
                      synthetic: false,
                  },
              },
              GenericParamDef {
                  name: "U",
                  def_id: DefId(0:21 ~ dump_generics[c1f6]::IHopeItMadeLotsOfCode::U),
                  index: 5,
                  pure_wrt_drop: false,
                  kind: Type {
                      has_default: false,
                      synthetic: false,
                  },
              },
          ],
          param_def_id_to_index: {
              DefId(0:17 ~ dump_generics[c1f6]::IHopeItMadeLotsOfCode::'a): 1,
              DefId(0:16 ~ dump_generics[c1f6]::IHopeItMadeLotsOfCode): 0,
              DefId(0:21 ~ dump_generics[c1f6]::IHopeItMadeLotsOfCode::U): 5,
              DefId(0:20 ~ dump_generics[c1f6]::IHopeItMadeLotsOfCode::T): 4,
              DefId(0:19 ~ dump_generics[c1f6]::IHopeItMadeLotsOfCode::N): 3,
              DefId(0:18 ~ dump_generics[c1f6]::IHopeItMadeLotsOfCode::'b): 2,
          },
          has_self: true,
          has_late_bound_regions: None,
      }
  --> /checkout/tests/ui/attributes/dump_generics.rs:28:1
   |
LL | pub trait IHopeItMadeLotsOfCode<'a, 'b, const N: usize, T, U: Clone>
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: rustc_dump_generics: DefId(0:22 ~ dump_generics[c1f6]::LookItsFromCorro)
##[error]  --> /checkout/tests/ui/attributes/dump_generics.rs:33:1
   |
LL | struct LookItsFromCorro<'a, 'b, const N: usize, T, U: Clone> {
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
note: Generics {
          parent: None,
          parent_count: 0,
          own_params: [
              GenericParamDef {
                  name: "'a",
                  def_id: DefId(0:23 ~ dump_generics[c1f6]::LookItsFromCorro::'a),
                  index: 0,
                  pure_wrt_drop: false,
                  kind: Lifetime,
              },
              GenericParamDef {
                  name: "'b",
                  def_id: DefId(0:24 ~ dump_generics[c1f6]::LookItsFromCorro::'b),
                  index: 1,
                  pure_wrt_drop: false,
                  kind: Lifetime,
              },
              GenericParamDef {
                  name: "N",
                  def_id: DefId(0:25 ~ dump_generics[c1f6]::LookItsFromCorro::N),
                  index: 2,
                  pure_wrt_drop: false,
                  kind: Const {
                      has_default: false,
                  },
              },
              GenericParamDef {
                  name: "T",
                  def_id: DefId(0:26 ~ dump_generics[c1f6]::LookItsFromCorro::T),
                  index: 3,
                  pure_wrt_drop: false,
                  kind: Type {
                      has_default: false,
                      synthetic: false,
                  },
              },
              GenericParamDef {
                  name: "U",
                  def_id: DefId(0:27 ~ dump_generics[c1f6]::LookItsFromCorro::U),
                  index: 4,
                  pure_wrt_drop: false,
                  kind: Type {
                      has_default: false,
                      synthetic: false,
                  },
              },
          ],
          param_def_id_to_index: {
              DefId(0:25 ~ dump_generics[c1f6]::LookItsFromCorro::N): 2,
              DefId(0:24 ~ dump_generics[c1f6]::LookItsFromCorro::'b): 1,
              DefId(0:23 ~ dump_generics[c1f6]::LookItsFromCorro::'a): 0,
              DefId(0:27 ~ dump_generics[c1f6]::LookItsFromCorro::U): 4,
              DefId(0:26 ~ dump_generics[c1f6]::LookItsFromCorro::T): 3,
          },
          has_self: false,
          has_late_bound_regions: None,
      }
  --> /checkout/tests/ui/attributes/dump_generics.rs:33:1
   |
LL | struct LookItsFromCorro<'a, 'b, const N: usize, T, U: Clone> {
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: rustc_dump_generics: DefId(0:31 ~ dump_generics[c1f6]::HaveTakenOver)
##[error]  --> /checkout/tests/ui/attributes/dump_generics.rs:40:1
   |
LL | enum HaveTakenOver<'a: 'a, 'b, const N: usize, T, U: Clone> {
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
note: Generics {
          parent: None,
          parent_count: 0,
          own_params: [
              GenericParamDef {
                  name: "'a",
                  def_id: DefId(0:32 ~ dump_generics[c1f6]::HaveTakenOver::'a),
                  index: 0,
                  pure_wrt_drop: false,
                  kind: Lifetime,
              },
              GenericParamDef {
                  name: "'b",
                  def_id: DefId(0:33 ~ dump_generics[c1f6]::HaveTakenOver::'b),
                  index: 1,
                  pure_wrt_drop: false,
                  kind: Lifetime,
              },
              GenericParamDef {
                  name: "N",
                  def_id: DefId(0:34 ~ dump_generics[c1f6]::HaveTakenOver::N),
                  index: 2,
                  pure_wrt_drop: false,
                  kind: Const {
                      has_default: false,
                  },
              },
              GenericParamDef {
                  name: "T",
                  def_id: DefId(0:35 ~ dump_generics[c1f6]::HaveTakenOver::T),
                  index: 3,
                  pure_wrt_drop: false,
                  kind: Type {
                      has_default: false,
                      synthetic: false,
                  },
              },
              GenericParamDef {
                  name: "U",
                  def_id: DefId(0:36 ~ dump_generics[c1f6]::HaveTakenOver::U),
                  index: 4,
                  pure_wrt_drop: false,
                  kind: Type {
                      has_default: false,
                      synthetic: false,
                  },
              },
          ],
          param_def_id_to_index: {
              DefId(0:34 ~ dump_generics[c1f6]::HaveTakenOver::N): 2,
              DefId(0:33 ~ dump_generics[c1f6]::HaveTakenOver::'b): 1,
              DefId(0:32 ~ dump_generics[c1f6]::HaveTakenOver::'a): 0,
              DefId(0:36 ~ dump_generics[c1f6]::HaveTakenOver::U): 4,
              DefId(0:35 ~ dump_generics[c1f6]::HaveTakenOver::T): 3,
          },
          has_self: false,
          has_late_bound_regions: None,
      }
  --> /checkout/tests/ui/attributes/dump_generics.rs:40:1
   |
LL | enum HaveTakenOver<'a: 'a, 'b, const N: usize, T, U: Clone> {
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: rustc_dump_generics: DefId(0:47 ~ dump_generics[c1f6]::TheFoundation)
##[error]  --> /checkout/tests/ui/attributes/dump_generics.rs:48:1
   |
LL | union TheFoundation<'a: 'a, 'b, const N: usize, T, U: Clone> {
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
note: Generics {
          parent: None,
          parent_count: 0,
          own_params: [
              GenericParamDef {
                  name: "'a",
                  def_id: DefId(0:48 ~ dump_generics[c1f6]::TheFoundation::'a),
                  index: 0,
                  pure_wrt_drop: false,
                  kind: Lifetime,
              },
              GenericParamDef {
                  name: "'b",
                  def_id: DefId(0:49 ~ dump_generics[c1f6]::TheFoundation::'b),
                  index: 1,
                  pure_wrt_drop: false,
                  kind: Lifetime,
              },
              GenericParamDef {
                  name: "N",
                  def_id: DefId(0:50 ~ dump_generics[c1f6]::TheFoundation::N),
                  index: 2,
                  pure_wrt_drop: false,
                  kind: Const {
                      has_default: false,
                  },
              },
              GenericParamDef {
                  name: "T",
                  def_id: DefId(0:51 ~ dump_generics[c1f6]::TheFoundation::T),
                  index: 3,
                  pure_wrt_drop: false,
                  kind: Type {
                      has_default: false,
                      synthetic: false,
                  },
              },
              GenericParamDef {
                  name: "U",
                  def_id: DefId(0:52 ~ dump_generics[c1f6]::TheFoundation::U),
                  index: 4,
                  pure_wrt_drop: false,
                  kind: Type {
                      has_default: false,
                      synthetic: false,
                  },
              },
          ],
          param_def_id_to_index: {
              DefId(0:51 ~ dump_generics[c1f6]::TheFoundation::T): 3,
              DefId(0:50 ~ dump_generics[c1f6]::TheFoundation::N): 2,
              DefId(0:49 ~ dump_generics[c1f6]::TheFoundation::'b): 1,
              DefId(0:48 ~ dump_generics[c1f6]::TheFoundation::'a): 0,
              DefId(0:52 ~ dump_generics[c1f6]::TheFoundation::U): 4,
          },
          has_self: false,
          has_late_bound_regions: None,
      }
  --> /checkout/tests/ui/attributes/dump_generics.rs:48:1
   |
LL | union TheFoundation<'a: 'a, 'b, const N: usize, T, U: Clone> {
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: rustc_dump_generics: DefId(0:56 ~ dump_generics[c1f6]::i_dare_you)
##[error]  --> /checkout/tests/ui/attributes/dump_generics.rs:55:1
   |
LL | const fn i_dare_you<'a: 'a, 'b, const N: usize, T, U>(you_can: &'a bool, _: &'b [(T, U); N]) {
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
note: Generics {
          parent: None,
          parent_count: 0,
          own_params: [
              GenericParamDef {
                  name: "'a",
                  def_id: DefId(0:57 ~ dump_generics[c1f6]::i_dare_you::'a),
                  index: 0,
                  pure_wrt_drop: false,
                  kind: Lifetime,
              },
              GenericParamDef {
                  name: "N",
                  def_id: DefId(0:59 ~ dump_generics[c1f6]::i_dare_you::N),
                  index: 1,
                  pure_wrt_drop: false,
                  kind: Const {
                      has_default: false,
                  },
              },
              GenericParamDef {
                  name: "T",
                  def_id: DefId(0:60 ~ dump_generics[c1f6]::i_dare_you::T),
                  index: 2,
                  pure_wrt_drop: false,
                  kind: Type {
                      has_default: false,
                      synthetic: false,
                  },
              },
              GenericParamDef {
                  name: "U",
                  def_id: DefId(0:61 ~ dump_generics[c1f6]::i_dare_you::U),
                  index: 3,
                  pure_wrt_drop: false,
                  kind: Type {
                      has_default: false,
                      synthetic: false,
                  },
              },
          ],
          param_def_id_to_index: {
              DefId(0:59 ~ dump_generics[c1f6]::i_dare_you::N): 1,
              DefId(0:57 ~ dump_generics[c1f6]::i_dare_you::'a): 0,
              DefId(0:61 ~ dump_generics[c1f6]::i_dare_you::U): 3,
              DefId(0:60 ~ dump_generics[c1f6]::i_dare_you::T): 2,
          },
          has_self: false,
          has_late_bound_regions: Some(
              /checkout/tests/ui/attributes/dump_generics.rs:55:29: 55:31 (#0),
          ),
      }
  --> /checkout/tests/ui/attributes/dump_generics.rs:55:1
   |
LL | const fn i_dare_you<'a: 'a, 'b, const N: usize, T, U>(you_can: &'a bool, _: &'b [(T, U); N]) {
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: rustc_dump_generics: DefId(0:64 ~ dump_generics[c1f6]::IfYouNeed)
##[error]  --> /checkout/tests/ui/attributes/dump_generics.rs:66:1
   |
LL | trait IfYouNeed<'_a: '_a, '_b, const N: usize, T, U: Clone> {}
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
note: Generics {
          parent: None,
          parent_count: 0,
          own_params: [
              GenericParamDef {
                  name: "Self",
                  def_id: DefId(0:64 ~ dump_generics[c1f6]::IfYouNeed),
                  index: 0,
                  pure_wrt_drop: false,

@addiesh

addiesh commented Jun 11, 2026

Copy link
Copy Markdown
Author

That's frustrating. Why does it fail specifically on that target triple?

@fmease

fmease commented Jun 11, 2026

Copy link
Copy Markdown
Member

The specific target doesn't matter. You're printing a FxHashMap (param_def_id_to_index) whose entries don't have a "stable ordering" due to the hashing (it happens to be stable across compilations & re-runs but the behavior may differ by target; i686-gnu-nopt-1 differs most likely because it's a 32-bit arch).

You need to add another compiletest normalization rule to make the mapping stable by "normalizing away" the concrete indices.

@addiesh

addiesh commented Jun 11, 2026

Copy link
Copy Markdown
Author

The specific target doesn't matter. You're printing a FxHashMap (param_def_id_to_index) whose entries don't have a "stable ordering" due to the hashing (it happens to be stable across compilations & re-runs but the behavior may differ by target; i686-gnu-nopt-1 differs most likely because it's a 32-bit arch).

You somehow need to compiletest-normalize away this mapping in the output.

Ah, I see. That makes sense. I'll try my best to do that.

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-author Status: This is awaiting some action (such as code changes or more information) from the author. 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.

9 participants