Add TypeId methods variants fields field for type_info#156403
Add TypeId methods variants fields field for type_info#156403SpriteOvO wants to merge 4 commits into
TypeId methods variants fields field for type_info#156403Conversation
|
Some changes occurred to the intrinsics. Make sure the CTFE / Miri interpreter cc @rust-lang/miri, @RalfJung, @oli-obk, @lcnr Some changes occurred to the CTFE machinery The reflection data structures are tied exactly to the implementation cc @oli-obk |
This comment has been minimized.
This comment has been minimized.
c503c83 to
827c2f9
Compare
This comment has been minimized.
This comment has been minimized.
| /// ``` | ||
| #[unstable(feature = "type_info", issue = "146922")] | ||
| #[rustc_const_unstable(feature = "type_info", issue = "146922")] | ||
| pub const fn fields(self, variant_index: usize) -> usize { |
There was a problem hiding this comment.
are these indexes affected by specified descriminants? ie does enum Descr { Five = 5 } have a variant_index = 5 ?
There was a problem hiding this comment.
Inside the compiler variant index refers to the lexical order of variants. So Descr::Five would have variant index 0. Should probably be documented here though.
There was a problem hiding this comment.
I'll update the doc later. But this is indeed worth mentioning for SemVer and privacy. If we use the current "index" term, then reordering enum variants or struct fields will result in different reflection results.
There was a problem hiding this comment.
Which may be entirely intentional. Proc macros also use source order. If you want sth else you need to sort by another key.
An alternative would be to provide fields and variants by a sorted list of names and require getting their info by names. Idk if that gets us into trouble with macros defining equal field names with different hygiene, but I hope we just error on that
827c2f9 to
8313075
Compare
This comment has been minimized.
This comment has been minimized.
8313075 to
12dee7d
Compare
|
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. |
This comment has been minimized.
This comment has been minimized.
12dee7d to
28733aa
Compare
Tracking issue #146922
fn TypeId::variantsreturns the number of variants, for struct and union and primitive types, it's always 1.fn TypeId::fieldsreturns the number of fields.fn TypeId::fieldreturns a field representing typeFieldId.FieldId, which is a wrapper ofTypeIdfor fields.For methods
{fields,field}, if indexing out of bounds, a compile-time error will be raised.Regarding the removal of
Typeitems, this will be done in a later PR in one go.r? @oli-obk