Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions compiler/rustc_attr_parsing/src/attributes/rustc_dump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,25 @@ impl SingleAttributeParser for RustcDumpDefPathParser {
}
}

pub(crate) struct RustcDumpGenericsParser;

impl NoArgsAttributeParser for RustcDumpGenericsParser {
const PATH: &[Symbol] = &[sym::rustc_dump_generics];
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[
Copy link
Copy Markdown
Author

@addiesh addiesh Jun 3, 2026

Choose a reason for hiding this comment

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

this might be overzealous, might need to add/remove some

View changes since the review

Allow(Target::Struct),
Allow(Target::Enum),
Allow(Target::Union),
Allow(Target::Trait),
Allow(Target::Fn),
Allow(Target::Closure),
Allow(Target::Union),
Allow(Target::TyAlias),
Allow(Target::TraitAlias),
]);
const STABILITY: AttributeStability = unstable!(rustc_attrs);
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcDumpGenerics;
}

pub(crate) struct RustcDumpHiddenTypeOfOpaquesParser;

impl NoArgsAttributeParser for RustcDumpHiddenTypeOfOpaquesParser {
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_attr_parsing/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ attribute_parsers!(
Single<WithoutArgs<RustcDenyExplicitImplParser>>,
Single<WithoutArgs<RustcDoNotConstCheckParser>>,
Single<WithoutArgs<RustcDumpDefParentsParser>>,
Single<WithoutArgs<RustcDumpGenericsParser>>,
Single<WithoutArgs<RustcDumpHiddenTypeOfOpaquesParser>>,
Single<WithoutArgs<RustcDumpInferredOutlivesParser>>,
Single<WithoutArgs<RustcDumpItemBoundsParser>>,
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_feature/src/builtin_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,7 @@ pub static BUILTIN_ATTRIBUTES: &[Symbol] = &[
sym::rustc_strict_coherence,
sym::rustc_dump_variances,
sym::rustc_dump_variances_of_opaques,
sym::rustc_dump_generics,
sym::rustc_dump_hidden_type_of_opaques,
sym::rustc_dump_layout,
sym::rustc_abi,
Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_hir/src/attrs/data_structures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1359,6 +1359,9 @@ pub enum AttributeKind {
/// Represents `#[rustc_dump_def_path]`
RustcDumpDefPath(Span),

/// Represents `#[rustc_dump_generics]`
RustcDumpGenerics,

/// Represents `#[rustc_dump_hidden_type_of_opaques]`
RustcDumpHiddenTypeOfOpaques,

Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_hir/src/attrs/encode_cross_crate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ impl AttributeKind {
RustcDummy => No,
RustcDumpDefParents => No,
RustcDumpDefPath(..) => No,
RustcDumpGenerics => No,
RustcDumpHiddenTypeOfOpaques => No,
RustcDumpInferredOutlives => No,
RustcDumpItemBounds => No,
Expand Down
18 changes: 18 additions & 0 deletions compiler/rustc_hir_analysis/src/collect/dump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,24 @@ use rustc_middle::hir::nested_filter;
use rustc_middle::ty::{self, TyCtxt, TypeVisitableExt, Unnormalized};
use rustc_span::sym;

pub(crate) fn generics(tcx: TyCtxt<'_>) {
for iid in tcx.hir_free_items() {
let did = iid.owner_id.def_id;
if find_attr!(tcx, did, RustcDumpGenerics) {
let span = tcx.def_span(did);

let mut diag = tcx
.dcx()
.struct_span_err(span, format!("{}: {did:?}", sym::rustc_dump_generics.as_str()));
Comment thread
addiesh marked this conversation as resolved.

let current_did = did.to_def_id();
let generics = tcx.generics_of(current_did);
diag.span_note(tcx.def_span(did), format!("{generics:#?}"));
diag.emit();
}
}
}

pub(crate) fn opaque_hidden_types(tcx: TyCtxt<'_>) {
if !find_attr!(tcx, crate, RustcDumpHiddenTypeOfOpaques) {
return;
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_hir_analysis/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ pub fn check_crate(tcx: TyCtxt<'_>) {
tcx.sess.time("dumping_rustc_attr_data", || {
outlives::dump::inferred_outlives(tcx);
variance::dump::variances(tcx);
collect::dump::generics(tcx);
collect::dump::opaque_hidden_types(tcx);
collect::dump::predicates_and_item_bounds(tcx);
collect::dump::def_parents(tcx);
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_passes/src/check_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
AttributeKind::RustcDummy => (),
AttributeKind::RustcDumpDefParents => (),
AttributeKind::RustcDumpDefPath(..) => (),
AttributeKind::RustcDumpGenerics => (),
AttributeKind::RustcDumpHiddenTypeOfOpaques => (),
AttributeKind::RustcDumpInferredOutlives => (),
AttributeKind::RustcDumpItemBounds => (),
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1744,6 +1744,7 @@ symbols! {
rustc_dummy,
rustc_dump_def_parents,
rustc_dump_def_path,
rustc_dump_generics,
rustc_dump_hidden_type_of_opaques,
rustc_dump_inferred_outlives,
rustc_dump_item_bounds,
Expand Down
2 changes: 1 addition & 1 deletion library/backtrace
1 change: 1 addition & 0 deletions src/doc/rustc-dev-guide/src/compiler-debugging.md
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ Here are some notable ones:
|----------------|-------------|
| `rustc_dump_def_parents` | Dumps the chain of `DefId` parents of certain definitions. |
| `rustc_dump_def_path` | Dumps the [`def_path_str`] of an item. |
| `rustc_dump_generics` | Dumps the generics of an item. |
| `rustc_dump_hidden_type_of_opaques` | Dumps the [hidden type of each opaque types][opaq] in the crate. |
| `rustc_dump_inferred_outlives` | Dumps implied bounds of an item. More precisely, the [`inferred_outlives_of`] an item. |
| `rustc_dump_item_bounds` | Dumps the [`item_bounds`] of an item. |
Expand Down
19 changes: 19 additions & 0 deletions tests/ui/attributes/dump_generics.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//@ normalize-stderr: "DefId\(.+?\)" -> "DefId(..)"

#![feature(rustc_attrs)]

fn bar() {
fn foo() {
fn baz() {
|| {
qux::<'_, '_, 400, u32, u64>();
};
}
}
}

#[rustc_dump_generics]
const fn qux<'a: 'a, 'b: 'b, const N: usize, T, U>() {}
//~^ ERROR: rustc_dump_generics: DefId(0:8 ~ dump_generics[c1f6]::qux)

fn main() {}
71 changes: 71 additions & 0 deletions tests/ui/attributes/dump_generics.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
error: rustc_dump_generics: DefId(..)
--> $DIR/dump_generics.rs:16:1
|
LL | const fn qux<'a: 'a, 'b: 'b, const N: usize, T, U>() {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: Generics {
parent: None,
parent_count: 0,
own_params: [
GenericParamDef {
name: "'a",
def_id: DefId(..),
index: 0,
pure_wrt_drop: false,
kind: Lifetime,
},
GenericParamDef {
name: "'b",
def_id: DefId(..),
index: 1,
pure_wrt_drop: false,
kind: Lifetime,
},
GenericParamDef {
name: "N",
def_id: DefId(..),
index: 2,
pure_wrt_drop: false,
kind: Const {
has_default: false,
},
},
GenericParamDef {
name: "T",
def_id: DefId(..),
index: 3,
pure_wrt_drop: false,
kind: Type {
has_default: false,
synthetic: false,
},
},
GenericParamDef {
name: "U",
def_id: DefId(..),
index: 4,
pure_wrt_drop: false,
kind: Type {
has_default: false,
synthetic: false,
},
},
],
param_def_id_to_index: {
DefId(..): 0,
DefId(..): 2,
DefId(..): 3,
DefId(..): 1,
DefId(..): 4,
},
has_self: false,
has_late_bound_regions: None,
}
--> $DIR/dump_generics.rs:16:1
|
LL | const fn qux<'a: 'a, 'b: 'b, const N: usize, T, U>() {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 1 previous error

Loading