Skip to content

Do not require 'static for obtaining reflection information.#152381

Merged
rust-bors[bot] merged 1 commit intorust-lang:mainfrom
oli-obk:non_static_reflection
Feb 15, 2026
Merged

Do not require 'static for obtaining reflection information.#152381
rust-bors[bot] merged 1 commit intorust-lang:mainfrom
oli-obk:non_static_reflection

Conversation

@oli-obk
Copy link
Contributor

@oli-obk oli-obk commented Feb 9, 2026

tracking issue #142577

This does not affect the stable TypeId::of, as that has its own 'static bound.

But it will allow obtaining TypeIds for non-static types via the reflection API. To obtain such a TypeId for any type, just use Type::of::<(T,)>().kind to extract the first field of a tuple.

This effectively reintroduces #41875, which @rust-lang/lang decided against allowing back in 2018 due to lack of sound use cases. We will thus need to have a T-lang meeting specifically about TypeId for non-static types before stabilizing any part of reflection (in addition to T-lang meetings about reflection in general). I'm adding an explicit point about this to the tracking issue.

cc @scottmcm @joshtriplett @9SonSteroids @SpriteOvO @izagawd @BD103

@rustbot
Copy link
Collaborator

rustbot commented Feb 9, 2026

Some changes occurred to the intrinsics. Make sure the CTFE / Miri interpreter
gets adapted for the changes, if necessary.

cc @rust-lang/miri, @RalfJung, @lcnr

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Feb 9, 2026
@rustbot
Copy link
Collaborator

rustbot commented Feb 9, 2026

r? @Mark-Simulacrum

rustbot has assigned @Mark-Simulacrum.
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

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: @scottmcm, libs
  • @scottmcm, libs expanded to 8 candidates
  • Random selection from Mark-Simulacrum, scottmcm

@oli-obk oli-obk added the F-type_info #![feature(type_info)] label Feb 9, 2026
@oli-obk oli-obk mentioned this pull request Feb 9, 2026
15 tasks
@traviscross traviscross added the I-lang-radar Items that are on lang's radar and will need eventual work or consideration. label Feb 9, 2026
@lcnr
Copy link
Contributor

lcnr commented Feb 11, 2026

But it will allow obtaining TypeIds for non-static types via the reflection API. To obtain such a TypeId for any type, just use Type::of::<(T,)>().kind to extract the first field of a tuple.

This effectively reintroduces #41875, which @rust-lang/lang decided against allowing back in 2018 due to lack of sound use cases. We will thus need to have a T-lang meeting specifically about TypeId for non-static types before stabilizing any part of reflection (in addition to T-lang meetings about reflection in general). I'm adding an explicit point about this to the tracking issue.

Don't have much capacity and going to unsubscribe from this PR, but rly, we should readd non_static_type_id. It is incredibly useful 🤣 it allows soundly going from T without a static bound to types without free regions

@theemathas
Copy link
Contributor

Of note, the typeid crate already implements a hacky way to get a TypeId representing a non-'static type. The crate has a lot of downloads.

@Mark-Simulacrum
Copy link
Member

r=me unless we want T-lang/libs-api/xxx FCP or similar.

@oli-obk
Copy link
Contributor Author

oli-obk commented Feb 14, 2026

Nope. It's entirely unstable and the point of this experiment is to demonstrate use cases and problematic situations, so now we can explore the latter, too

@bors r=Mark-Simulacrum

@rust-bors
Copy link
Contributor

rust-bors bot commented Feb 14, 2026

📌 Commit 3339b06 has been approved by Mark-Simulacrum

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 Feb 14, 2026
rust-bors bot pushed a commit that referenced this pull request Feb 14, 2026
…uwer

Rollup of 7 pull requests

Successful merges:

 - #152622 (Update GCC subtree)
 - #145024 (Optimize indexing slices and strs with inclusive ranges)
 - #151365 (UnsafePinned: implement opsem effects of UnsafeUnpin)
 - #152381 (Do not require `'static` for obtaining reflection information.)
 - #143575 (Remove named lifetimes in some `PartialOrd` & `PartialEq` `impl`s)
 - #152404 (tests: adapt align-offset.rs for InstCombine improvements in LLVM 23)
 - #152582 (rustc_query_impl: Use `ControlFlow` in `visit_waiters` instead of nested options)
rust-bors bot pushed a commit that referenced this pull request Feb 14, 2026
…uwer

Rollup of 7 pull requests

Successful merges:

 - #152622 (Update GCC subtree)
 - #145024 (Optimize indexing slices and strs with inclusive ranges)
 - #151365 (UnsafePinned: implement opsem effects of UnsafeUnpin)
 - #152381 (Do not require `'static` for obtaining reflection information.)
 - #143575 (Remove named lifetimes in some `PartialOrd` & `PartialEq` `impl`s)
 - #152404 (tests: adapt align-offset.rs for InstCombine improvements in LLVM 23)
 - #152582 (rustc_query_impl: Use `ControlFlow` in `visit_waiters` instead of nested options)
@rust-bors rust-bors bot merged commit 16da3ab into rust-lang:main Feb 15, 2026
11 checks passed
@rustbot rustbot added this to the 1.95.0 milestone Feb 15, 2026
rust-timer added a commit that referenced this pull request Feb 15, 2026
Rollup merge of #152381 - oli-obk:non_static_reflection, r=Mark-Simulacrum

Do not require `'static` for obtaining reflection information.

tracking issue #142577

This does not affect the stable `TypeId::of`, as that has its own `'static` bound.

But it will allow obtaining `TypeId`s for non-static types via the reflection API. To obtain such a `TypeId` for any type, just use `Type::of::<(T,)>().kind` to extract the first field of a tuple.

This effectively reintroduces #41875, which @rust-lang/lang decided against allowing back in 2018 due to lack of sound use cases. We will thus need to have a T-lang meeting specifically about `TypeId` for non-static types before *stabilizing* any part of reflection (in addition to T-lang meetings about reflection in general). I'm adding an explicit point about this to the tracking issue.

cc @scottmcm @joshtriplett @9SonSteroids @SpriteOvO @izagawd @BD103
github-actions bot pushed a commit to rust-lang/miri that referenced this pull request Feb 15, 2026
…uwer

Rollup of 7 pull requests

Successful merges:

 - rust-lang/rust#152622 (Update GCC subtree)
 - rust-lang/rust#145024 (Optimize indexing slices and strs with inclusive ranges)
 - rust-lang/rust#151365 (UnsafePinned: implement opsem effects of UnsafeUnpin)
 - rust-lang/rust#152381 (Do not require `'static` for obtaining reflection information.)
 - rust-lang/rust#143575 (Remove named lifetimes in some `PartialOrd` & `PartialEq` `impl`s)
 - rust-lang/rust#152404 (tests: adapt align-offset.rs for InstCombine improvements in LLVM 23)
 - rust-lang/rust#152582 (rustc_query_impl: Use `ControlFlow` in `visit_waiters` instead of nested options)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

F-type_info #![feature(type_info)] I-lang-radar Items that are on lang's radar and will need eventual work or consideration. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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