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

@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
@rust-log-analyzer

This comment has been minimized.

@rust-bors

This comment has been minimized.

Zalathar added a commit to Zalathar/rust that referenced this pull request Jan 17, 2026
feat: Support references in reflection type info

Tracking issue: rust-lang#146922 `#![feature(type_info)]`

Based on rust-lang#151119 implementation for pointers for consistency

r? oli-obk
rust-timer added a commit that referenced this pull request Jan 17, 2026
Rollup merge of #151222 - reflect-references, r=oli-obk

feat: Support references in reflection type info

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

Based on #151119 implementation for pointers for consistency

r? oli-obk
@oli-obk
Copy link
Contributor

oli-obk commented Jan 18, 2026

Needs a rebase

@SpriteOvO SpriteOvO 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 18, 2026
@rustbot
Copy link
Collaborator

rustbot commented Jan 19, 2026

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.

@SpriteOvO SpriteOvO added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jan 19, 2026
&Unsized, &str, &[u8],
str, [u8],
&u8, &mut u8,
*const u8, *mut u8,
Copy link
Contributor

Choose a reason for hiding this comment

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

Since we encountered problems with dumps in other PRs with these dumps let's not add more here. You already added assert tests, those are sufficient

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, good call. Is there still a benefit in dump.rs, or can it be deleted? (In a follow-up PR.)

Copy link
Contributor

Choose a reason for hiding this comment

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

Should make sure there is sufficient other testing for the existing cases, but yea, that seems like the best

@oli-obk
Copy link
Contributor

oli-obk commented Jan 19, 2026

@bors r+ rollup

@rust-bors
Copy link
Contributor

rust-bors bot commented Jan 19, 2026

📌 Commit 976cea3 has been approved by oli-obk

It is now in the queue for this repository.

@rust-bors rust-bors bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 19, 2026
rust-bors bot pushed a commit that referenced this pull request Jan 19, 2026
…uwer

Rollup of 15 pull requests

Successful merges:

 - #148623 (Ignore `#[doc(hidden)]` items when computing trimmed paths for printing)
 - #150550 (Miscellaneous cleanups to borrowck related code)
 - #150879 (Remove the diagnostic lints)
 - #150895 (rustc_errors: Add (heuristic) Syntax Highlighting for `rustc --explain`)
 - #150987 (remote-test-server: Fix header in batch mode)
 - #151004 (std: implement `sleep_until` on Apple platforms)
 - #151045 (Simplify some literal-value negations with `u128::wrapping_neg`)
 - #151119 (Support pointers in type reflection)
 - #151171 (Do not recover from `Trait()` if generic list is unterminated)
 - #151231 (HIR typeck cleanup: clarify and re-style `check_expr_unop`)
 - #151249 (Parse ident with allowing recovery when trying to diagnose)
 - #151295 (THIR patterns: Use `ty::Value` in more places throughout `const_to_pat`)
 - #151326 (Remove `DiagMessage::Translated` in favour of `DiagMessage::Str`)
 - #151361 (add test for issue 61463)
 - #151371 (Add `S-blocked` to `labels_blocking_approval`)

r? @ghost
@rust-bors rust-bors bot merged commit 25e6f5c into rust-lang:main Jan 20, 2026
11 checks passed
@rustbot rustbot added this to the 1.95.0 milestone Jan 20, 2026
rust-timer added a commit that referenced this pull request Jan 20, 2026
Rollup merge of #151119 - reflect-pointers, r=oli-obk

Support pointers in type reflection

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:

```rust
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:

```rust
match const { Type::of::<*const u8>() }.kind {
    TypeKind::Pointer(pointer) => {
        assert_eq!(pointer.ty, TypeId::of::<u8>());
        assert!(!pointer.mutable);
    }
    _ => unreachable!(),
}
```
github-actions bot pushed a commit to rust-lang/miri that referenced this pull request Jan 20, 2026
…uwer

Rollup of 15 pull requests

Successful merges:

 - rust-lang/rust#148623 (Ignore `#[doc(hidden)]` items when computing trimmed paths for printing)
 - rust-lang/rust#150550 (Miscellaneous cleanups to borrowck related code)
 - rust-lang/rust#150879 (Remove the diagnostic lints)
 - rust-lang/rust#150895 (rustc_errors: Add (heuristic) Syntax Highlighting for `rustc --explain`)
 - rust-lang/rust#150987 (remote-test-server: Fix header in batch mode)
 - rust-lang/rust#151004 (std: implement `sleep_until` on Apple platforms)
 - rust-lang/rust#151045 (Simplify some literal-value negations with `u128::wrapping_neg`)
 - rust-lang/rust#151119 (Support pointers in type reflection)
 - rust-lang/rust#151171 (Do not recover from `Trait()` if generic list is unterminated)
 - rust-lang/rust#151231 (HIR typeck cleanup: clarify and re-style `check_expr_unop`)
 - rust-lang/rust#151249 (Parse ident with allowing recovery when trying to diagnose)
 - rust-lang/rust#151295 (THIR patterns: Use `ty::Value` in more places throughout `const_to_pat`)
 - rust-lang/rust#151326 (Remove `DiagMessage::Translated` in favour of `DiagMessage::Str`)
 - rust-lang/rust#151361 (add test for issue 61463)
 - rust-lang/rust#151371 (Add `S-blocked` to `labels_blocking_approval`)

r? @ghost
@BD103 BD103 deleted the reflect-pointers branch January 20, 2026 20:15
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-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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.

6 participants