Skip to content

Conversation

@BD103
Copy link
Contributor

@BD103 BD103 commented Jan 14, 2026

Tracking issue: #146922

This PR adds support for inspecting pointers *const T and *mut T through type reflection. It does so by adding the new Pointer struct + variant:

pub struct Pointer {
    /// The type of the value being pointed to.
    pub ty: TypeId,
    /// Whether this pointer is mutable or not.
    pub mutable: bool,
}

This can be gathered using Type::of, for example:

match const { Type::of::<*const u8>() }.kind {
    TypeKind::Pointer(pointer) => {
        assert_eq!(pointer.ty, TypeId::of::<u8>());
        assert!(!pointer.mutable);
    }
    _ => unreachable!(),
}

@rustbot
Copy link
Collaborator

rustbot commented Jan 14, 2026

Some changes occurred to the CTFE machinery

cc @RalfJung, @oli-obk, @lcnr

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

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jan 14, 2026
@rustbot rustbot added 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

r? @JonathanBrouwer

rustbot has assigned @JonathanBrouwer.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

/// The type of the value being pointed to.
pub ty: TypeId,
/// Whether this pointer is mutable or not.
pub mutable: bool,
Copy link
Contributor Author

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.

@BD103
Copy link
Contributor Author

BD103 commented Jan 14, 2026

r? @oli-obk

@rustbot rustbot assigned oli-obk and unassigned JonathanBrouwer 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 added F-type_info #![feature(type_info)] A-type-system Area: Type system labels Jan 14, 2026
Comment on lines +232 to +238
sym::mutable => self.write_scalar(
match mutability {
Mutability::Not => ScalarInt::FALSE,
Mutability::Mut => ScalarInt::TRUE,
},
&field_place,
)?,
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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.

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-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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants