Skip to content

Conversation

@SpriteOvO
Copy link
Member

@SpriteOvO SpriteOvO commented Jan 14, 2026

Tracking issue: #146922 #![feature(type_info)]

This PR supports {bool,char,int,uint,float,str} primitive types for feature type_info reflection.

r? @oli-obk

@SpriteOvO SpriteOvO added the F-type_info #![feature(type_info)] label Jan 14, 2026
@rustbot
Copy link
Collaborator

rustbot commented Jan 14, 2026

The reflection data structures are tied exactly to the implementation
in the compiler. Make sure to also adjust rustc_const_eval/src/const_eval/type_info.rs

cc @oli-obk

Some changes occurred to the CTFE machinery

cc @RalfJung, @oli-obk, @lcnr

@rustbot rustbot added 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. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Jan 14, 2026
@rustbot
Copy link
Collaborator

rustbot commented Jan 14, 2026

oli-obk is not on the review rotation at the moment.
They may take a while to respond.

@SpriteOvO SpriteOvO force-pushed the type-info-primitives branch 3 times, most recently from 7fccb29 to 1066081 Compare January 14, 2026 16:13
@SpriteOvO SpriteOvO added the A-type-system Area: Type system label Jan 14, 2026
@SpriteOvO SpriteOvO force-pushed the type-info-primitives branch from 1066081 to 8281828 Compare January 14, 2026 16:15
@rust-log-analyzer

This comment has been minimized.

@SpriteOvO SpriteOvO force-pushed the type-info-primitives branch from 8281828 to 8d00b3b Compare January 14, 2026 16:32
Copy link
Member Author

@SpriteOvO SpriteOvO left a comment

Choose a reason for hiding this comment

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

I also added a ty: TypeId to all primitive variants to represent their own type. The rationale is that users won't need to manually retrieve the TypeId when accessing type info (especially through Type::of::<T>() usage). I'm not sure if this approach is advisable, and whether it's necessary to also provide a ty: TypeId for other variants like Tuple and Array.

View changes since this review

/// The type id of signed integer type.
pub ty: TypeId,
/// The bit width of the signed integer type.
pub bit_width: usize,
Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not sure whether we should use usize or u64 here to represent the bit width.

Besides, as Option is not used here, reflection on isize and usize will fall into the Int and Uint variants, and users cannot distinguish between them, which may be an issue.

Is it necessary for end users to distinguish between {u,i}size and {u,i}int? If yes, should we add a separate field or add distinct variants to indicate it?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think having a single Int variant that has a signed: bool field is nicer. It avoids some recurring matches that do Int(_) | Uint(_)

@rust-log-analyzer

This comment has been minimized.

@SpriteOvO SpriteOvO force-pushed the type-info-primitives branch from 8d00b3b to 80ae7d8 Compare January 14, 2026 18:14
Support {bool,char,int,uint,float,str} primitive types for feature
`type_info` reflection.
@SpriteOvO
Copy link
Member Author

I also added a ty: TypeId to all primitive variants to represent their own type. The rationale is that users won't need to manually retrieve the TypeId when accessing type info (especially through Type::of::<T>() usage). I'm not sure if this approach is advisable, and whether it's necessary to also provide a ty: TypeId for other variants like Tuple and Array.

In that case, it might be better to place ty: TypeId under struct Type rather than under enum TypeKind's variants I think.

Copy link
Contributor

@oli-obk oli-obk left a comment

Choose a reason for hiding this comment

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

Yea I think we can leave off the extra TypeId field. I understand that reflection libraries have that on their Opaque variant, but they can still do that when processing the rustc reflection info. I'd rather users invoke TypeId::of manually when they also need the type id

View changes since this review

/// The type id of signed integer type.
pub ty: TypeId,
/// The bit width of the signed integer type.
pub bit_width: usize,
Copy link
Contributor

Choose a reason for hiding this comment

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

I think having a single Int variant that has a signed: bool field is nicer. It avoids some recurring matches that do Int(_) | Uint(_)

@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 Jan 15, 2026
Comment on lines +28 to +32
macro_rules! dump_types {
($($ty:ty),+ $(,)?) => {
$(println!("{:#?}", const { Type::of::<$ty>() });)+
};
}
Copy link
Contributor

Choose a reason for hiding this comment

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

ohh great idea, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-type-system Area: Type system F-type_info #![feature(type_info)] 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. T-libs Relevant to the library 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