-
-
Notifications
You must be signed in to change notification settings - Fork 14.3k
Support pointers in type reflection #151119
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?
Conversation
|
rustbot has assigned @JonathanBrouwer. Use |
| /// The type of the value being pointed to. | ||
| pub ty: TypeId, | ||
| /// Whether this pointer is mutable or not. | ||
| pub mutable: bool, |
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.
An alternative design to this is to create a Mutability enum:
enum Mutability {
Mutable,
Immutable,
}I chose to go with a boolean instead because I thought it was more concise and easier to work with.
|
r? @oli-obk |
|
|
| sym::mutable => self.write_scalar( | ||
| match mutability { | ||
| Mutability::Not => ScalarInt::FALSE, | ||
| Mutability::Mut => ScalarInt::TRUE, | ||
| }, | ||
| &field_place, | ||
| )?, |
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.
| sym::mutable => self.write_scalar( | |
| match mutability { | |
| Mutability::Not => ScalarInt::FALSE, | |
| Mutability::Mut => ScalarInt::TRUE, | |
| }, | |
| &field_place, | |
| )?, | |
| sym::mutable => self.write_scalar( | |
| Scalar::from_bool(mutability.is_mut()), | |
| &field_place, | |
| )?, |
This could be written more concisely.
Tracking issue: #146922
This PR adds support for inspecting pointers
*const Tand*mut Tthrough type reflection. It does so by adding the newPointerstruct + variant:This can be gathered using
Type::of, for example: