-
-
Notifications
You must be signed in to change notification settings - Fork 14.4k
Support trait objects in type info reflection #151239
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
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 |
|---|---|---|
|
|
@@ -47,6 +47,8 @@ pub enum TypeKind { | |
| Array(Array), | ||
| /// Slices. | ||
| Slice(Slice), | ||
| /// Dynamic Traits. | ||
| DynTrait(DynTrait), | ||
| /// Primitive boolean type. | ||
| Bool(Bool), | ||
| /// Primitive character type. | ||
|
|
@@ -105,6 +107,36 @@ pub struct Slice { | |
| pub element_ty: TypeId, | ||
| } | ||
|
|
||
| /// Compile-time type information about dynamic traits. | ||
| /// FIXME(#146922): Add super traits and generics | ||
| #[derive(Debug)] | ||
| #[non_exhaustive] | ||
| #[unstable(feature = "type_info", issue = "146922")] | ||
| pub struct DynTrait { | ||
| /// The predicates of a dynamic trait. | ||
| pub predicates: &'static [DynTraitPredicate], | ||
|
Comment on lines
+116
to
+117
Member
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. Additionally, predicates perhaps should be unordered? (e.g. But I'm not sure if const_eval can express an unordered set. Anyway, I just wanted to bring this up, not sure if there's a solution at the moment.
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. What if we keep the const-eval representation as a slice, but wrap it in a newtype (e.g. Unordered(&'static [T])) whose PartialEq, and other similar traits treats it as order-insensitive? That way we don’t need a real “set” in const_eval
Member
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. Let's leave it as is for now. It can be discussed later. |
||
| } | ||
|
|
||
| /// Compile-time type information about a dynamic trait predicate. | ||
| #[derive(Debug)] | ||
| #[non_exhaustive] | ||
| #[unstable(feature = "type_info", issue = "146922")] | ||
| pub struct DynTraitPredicate { | ||
| /// The type of the trait as a dynamic trait type. | ||
| pub trait_ty: Trait, | ||
| } | ||
|
|
||
| /// Compile-time type information about a trait. | ||
| #[derive(Debug)] | ||
| #[non_exhaustive] | ||
| #[unstable(feature = "type_info", issue = "146922")] | ||
| pub struct Trait { | ||
| /// The TypeId of the trait as a dynamic type | ||
| pub ty: TypeId, | ||
| /// Whether the trait is an auto trait | ||
| pub is_auto: bool, | ||
| } | ||
|
|
||
| /// Compile-time type information about `bool`. | ||
| #[derive(Debug)] | ||
| #[non_exhaustive] | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is very much non-blocking, but I would prefer this be named
TraitObject, as that is how they are presented in the book and the reference. Definitely something that should be done in a follow-up PR, as I don't want to hold up merging this due to bikeshedding :)