-
-
Notifications
You must be signed in to change notification settings - Fork 15.1k
Add #[rustc_dump_generics] attribute
#157384
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
1c2f6ad
08cf89c
bce83d7
2b51d96
595a593
25d3576
5c948a2
9849625
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -45,6 +45,35 @@ 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(&[ | ||
|
addiesh marked this conversation as resolved.
|
||
| Allow(Target::Struct), | ||
| Allow(Target::Enum), | ||
| Allow(Target::Union), | ||
| Allow(Target::Trait), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| Allow(Target::TraitAlias), | ||
| Allow(Target::Fn), | ||
| Allow(Target::Closure), | ||
| Allow(Target::TyAlias), | ||
| Allow(Target::Const), | ||
| Allow(Target::AssocConst), | ||
| Allow(Target::AssocTy), | ||
| Allow(Target::Impl { of_trait: false }), | ||
| Allow(Target::Impl { of_trait: true }), | ||
| Allow(Target::Method(MethodKind::Inherent)), | ||
| Allow(Target::Method(MethodKind::Trait { body: false })), | ||
| Allow(Target::Method(MethodKind::Trait { body: true })), | ||
| Allow(Target::Method(MethodKind::TraitImpl)), | ||
| Allow(Target::Delegation { mac: false }), | ||
| Allow(Target::Delegation { mac: true }), | ||
| ]); | ||
| const STABILITY: AttributeStability = unstable!(rustc_attrs); | ||
| const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcDumpGenerics; | ||
| } | ||
|
|
||
| pub(crate) struct RustcDumpHiddenTypeOfOpaquesParser; | ||
|
|
||
| impl NoArgsAttributeParser for RustcDumpHiddenTypeOfOpaquesParser { | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this intentional?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nope 😅. I just couldn't figure out how to undo the change in git. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| //@ normalize-stderr: "DefId\(.+?\)" -> "DefId(..)" | ||
|
|
||
| #![feature(rustc_attrs)] | ||
|
|
||
| fn foo() { | ||
| || { | ||
| 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:6 ~ dump_generics[c1f6]::qux) | ||
|
|
||
| fn main() {} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| error: rustc_dump_generics: DefId(..) | ||
| --> $DIR/dump_generics.rs:12: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(..): 2, | ||
| DefId(..): 0, | ||
| DefId(..): 4, | ||
| DefId(..): 3, | ||
| DefId(..): 1, | ||
| }, | ||
| has_self: false, | ||
| has_late_bound_regions: None, | ||
| } | ||
| --> $DIR/dump_generics.rs:12:1 | ||
| | | ||
| LL | const fn qux<'a: 'a, 'b: 'b, const N: usize, T, U>() {} | ||
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
|
||
| error: aborting due to 1 previous error | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| //@ normalize-stderr: "DefId\(.+?\)" -> "DefId(..)" | ||
|
|
||
| #![feature(rustc_attrs)] | ||
|
|
||
| #[rustc_dump_generics] | ||
| trait NiceOfThePrincess<'a, 'b, const N: usize, T, U: Clone> { | ||
| //~^ ERROR: rustc_dump_generics: DefId(0:3 ~ dump_generics_trait[89b1]::NiceOfThePrincess) | ||
|
|
||
| type ToInviteUs<V: PartialEq>; | ||
|
|
||
| fn over_for_a_picnic<const NN: usize>( | ||
| eh: [u8; N], | ||
| luigi: [u32; NN] | ||
| ); | ||
| } | ||
|
|
||
| fn main() {} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| error: rustc_dump_generics: DefId(..) | ||
| --> $DIR/dump_generics_trait.rs:6:1 | ||
| | | ||
| LL | trait NiceOfThePrincess<'a, 'b, const N: usize, T, U: Clone> { | ||
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | | ||
| note: Generics { | ||
| parent: None, | ||
| parent_count: 0, | ||
| own_params: [ | ||
| GenericParamDef { | ||
| name: "Self", | ||
| def_id: DefId(..), | ||
| index: 0, | ||
| pure_wrt_drop: false, | ||
| kind: Type { | ||
| has_default: false, | ||
| synthetic: false, | ||
| }, | ||
| }, | ||
| GenericParamDef { | ||
| name: "'a", | ||
| def_id: DefId(..), | ||
| index: 1, | ||
| pure_wrt_drop: false, | ||
| kind: Lifetime, | ||
| }, | ||
| GenericParamDef { | ||
| name: "'b", | ||
| def_id: DefId(..), | ||
| index: 2, | ||
| pure_wrt_drop: false, | ||
| kind: Lifetime, | ||
| }, | ||
| GenericParamDef { | ||
| name: "N", | ||
| def_id: DefId(..), | ||
| index: 3, | ||
| pure_wrt_drop: false, | ||
| kind: Const { | ||
| has_default: false, | ||
| }, | ||
| }, | ||
| GenericParamDef { | ||
| name: "T", | ||
| def_id: DefId(..), | ||
| index: 4, | ||
| pure_wrt_drop: false, | ||
| kind: Type { | ||
| has_default: false, | ||
| synthetic: false, | ||
| }, | ||
| }, | ||
| GenericParamDef { | ||
| name: "U", | ||
| def_id: DefId(..), | ||
| index: 5, | ||
| pure_wrt_drop: false, | ||
| kind: Type { | ||
| has_default: false, | ||
| synthetic: false, | ||
| }, | ||
| }, | ||
| ], | ||
| param_def_id_to_index: { | ||
| DefId(..): 4, | ||
| DefId(..): 0, | ||
| DefId(..): 2, | ||
| DefId(..): 3, | ||
| DefId(..): 1, | ||
| DefId(..): 5, | ||
| }, | ||
| has_self: true, | ||
| has_late_bound_regions: None, | ||
| } | ||
| --> $DIR/dump_generics_trait.rs:6:1 | ||
| | | ||
| LL | trait NiceOfThePrincess<'a, 'b, const N: usize, T, U: Clone> { | ||
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
|
||
| error: aborting due to 1 previous error | ||
|
|
Uh oh!
There was an error while loading. Please reload this page.