Skip to content

Conversation

@izagawd
Copy link
Contributor

@izagawd izagawd commented Jan 17, 2026

Tracking issue: #146922

Adds type_info support for trait object types by introducing a DynTrait variant

I can't seem to get it to work correctly with dyn for<'a> Foo<'a>, though it works fine for normal dyn Foo trait objects

r? @oli-obk

@rustbot
Copy link
Collaborator

rustbot commented Jan 17, 2026

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

Some changes occurred to the CTFE machinery

cc @RalfJung, @oli-obk, @lcnr

@rustbot rustbot added 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. labels Jan 17, 2026
@rustbot rustbot added the T-libs Relevant to the library team, which will review and decide on the PR/issue. label Jan 17, 2026
@rustbot
Copy link
Collaborator

rustbot commented Jan 17, 2026

oli-obk is not on the review rotation at the moment.
They may take a while to respond.

@izagawd izagawd marked this pull request as draft January 17, 2026 09:30
@rustbot rustbot 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 17, 2026
@SpriteOvO SpriteOvO added the F-type_info #![feature(type_info)] label Jan 17, 2026
@izagawd

This comment was marked as resolved.

Comment on lines 219 to 307
Type {
kind: DynTrait(
DynTrait {
super_traits: [
TypeId(0xf726af39bcd0090512f636802780d009),
TypeId(0xd3eba1307d3a0b58acd77b80e4532fbf),
],
is_auto: false,
auto_traits: [
TypeId(0x0d5e48167084e668b711d10061f0446a),
],
},
),
size: None,
}
Copy link
Member

@SpriteOvO SpriteOvO Jan 17, 2026

Choose a reason for hiding this comment

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

trait A {}
trait B: A {}
trait C: B {}

The quoted dump is the type info for dyn C + Send. How do we determine whether it has trait C?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, I don't think I fully understand the question. Could you elaborate?

Copy link
Member

@SpriteOvO SpriteOvO Jan 18, 2026

Choose a reason for hiding this comment

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

For clear, I replaced the type ID number with type name in the following examples.

First, TypeId(dyn C) != TypeId(dyn C + Send), then the type info of dyn C + Send is

Type {
    kind: DynTrait(
        DynTrait {
            super_traits: [
                TypeId(B),
                TypeId(A),
            ],
            is_auto: false,
            auto_traits: [
                TypeId(Send),
            ],
        },
    ),
    size: None,
}

For the current PR implementation, if given a dyn C + Send (or type ID of it), we can know there are A, B and Send but no way of knowing C.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did not include C in it since C is not a super trait of itself. I am assuming you want a field that represents the TypeId of the trait object itself?

Copy link
Member

@SpriteOvO SpriteOvO Jan 18, 2026

Choose a reason for hiding this comment

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

Not exactly, dyn C and dyn C + Send are two different things, so it's not "the trait object itself".

Intuitively, I think DynTrait's layout should probably look something like this. Take dyn C + Send as an example again.

Type {
    kind: DynTrait(
        DynTrait {
            predicates: [ Predicate(Trait(C)), Predicate(Trait(Send)) ]
        },
    ),
    size: None,
}

Predicate {
    trait,
    negative: bool, // Not sure if possible, #144241
}

Trait(C) = Trait {
    supers: [ Trait(B), Trait(A) ],
    is_auto: false,
}

Trait(Send) = Trait {
    supers: [],
    is_auto: true,
}

Trait(B) = ...
Trait(A) = ...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This makes a lot of sense! I will go with this

@izagawd

This comment was marked as resolved.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@izagawd izagawd marked this pull request as ready for review January 18, 2026 12:42
@rustbot rustbot 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 18, 2026
@rustbot

This comment has been minimized.

@rustbot rustbot added the has-merge-commits PR has merge commits, merge with caution. label Jan 18, 2026
@izagawd izagawd force-pushed the comptime-reflection-dyn-trait-variant branch from eb13b48 to f782c2f Compare January 18, 2026 12:53
@rustbot

This comment has been minimized.

@rustbot rustbot removed the has-merge-commits PR has merge commits, merge with caution. label Jan 18, 2026
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@izagawd izagawd force-pushed the comptime-reflection-dyn-trait-variant branch from a7df6d9 to b5eecb0 Compare January 18, 2026 20:24
@rustbot

This comment has been minimized.

@SpriteOvO
Copy link
Member

like this?

#[derive(Debug)]
// FIXME(type_info): Add supertraits
pub struct DynTraitPredicate {
    ...
}

Also, we might need to do that for generics as well no?

Yea. BTW, I'm adding generics info for ADT types in PR #151142. Once your PR is merged, I can also add generics info to traits later.

@rust-log-analyzer

This comment has been minimized.

@rustbot rustbot added the A-run-make Area: port run-make Makefiles to rmake.rs label Jan 21, 2026
@izagawd izagawd force-pushed the comptime-reflection-dyn-trait-variant branch from be15746 to e8b0f6c Compare January 21, 2026 02:18
Copy link
Member

@SpriteOvO SpriteOvO left a comment

Choose a reason for hiding this comment

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

LGTM, waiting for further review by @oli-obk. (I don't have r+ permission)

View changes since this review

#[derive(Debug)]
#[non_exhaustive]
#[unstable(feature = "type_info", issue = "146922")]
pub struct DynTrait {
Copy link
Contributor

@BD103 BD103 Jan 21, 2026

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 :)

Copy link
Contributor

Choose a reason for hiding this comment

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

The nomenclature has moved away from trait object, looks like we have more places to update

@izagawd izagawd force-pushed the comptime-reflection-dyn-trait-variant branch from e8b0f6c to 714dc35 Compare January 22, 2026 10:55
@rustbot

This comment has been minimized.

@izagawd
Copy link
Contributor Author

izagawd commented Jan 26, 2026

What else do I have to do to get this PR merged @oli-obk ?

Copy link
Contributor

@oli-obk oli-obk left a comment

Choose a reason for hiding this comment

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

🤦 forgot to submit the review

@bors delegate+

r=me after moving the code to a new module

View changes since this review

@rust-bors
Copy link
Contributor

rust-bors bot commented Jan 27, 2026

✌️ @izagawd, you can now approve this pull request!

If @oli-obk told you to "r=me" after making some further change, then please make that change and post @bors r=oli-obk.

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

rustbot commented Jan 27, 2026

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@izagawd izagawd force-pushed the comptime-reflection-dyn-trait-variant branch from 714dc35 to afe3fc1 Compare January 27, 2026 22:56
@rustbot
Copy link
Collaborator

rustbot commented Jan 27, 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.

@izagawd izagawd force-pushed the comptime-reflection-dyn-trait-variant branch from e7e72a1 to f4125af Compare January 27, 2026 23:23
@izagawd izagawd force-pushed the comptime-reflection-dyn-trait-variant branch from d3842ef to a1893d3 Compare January 27, 2026 23:49
@rust-log-analyzer
Copy link
Collaborator

The job x86_64-gnu-tools failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
##[group]Runner Image Provisioner
Hosted Compute Agent
Version: 20260115.477
Commit: 4b342d620503cbe250a3154040964899ea7c9b00
Build Date: 2026-01-15T22:32:41Z
Worker ID: {863c4987-3665-466c-a4b0-7fc0be49ac59}
Azure Region: westcentralus
##[endgroup]
##[group]Operating System
Ubuntu
24.04.3
LTS
---
REPOSITORY                                   TAG       IMAGE ID       CREATED      SIZE
ghcr.io/dependabot/dependabot-updater-core   latest    354d02aa29ac   8 days ago   783MB
=> Removing docker images...
Deleted Images:
untagged: ghcr.io/dependabot/dependabot-updater-core:latest
untagged: ghcr.io/dependabot/dependabot-updater-core@sha256:596da3f22bcbdff2c96fd7126001278022c834c1621c5efa2ad1a7794590636c
deleted: sha256:354d02aa29acf525570c732b6e006ecf138de6d63ca525d552eb4b24880ddc6c
deleted: sha256:8b7af0e426bc2cbeeacfd96b8354d3b80016991520977197e62090e47abaede8
deleted: sha256:cadf11ef1de7fdd5eab563757942353684047f09b212dc99d6ed48e8acf34d62
deleted: sha256:569b0caf9d5285db44ccd2629a3470139eea755be423a33a54d8a24cb3926bfa
deleted: sha256:f9dc5feb048d8f9fd43137e3998f59e9acfbd76c47a4e14984d109654119e282
---
tests/ui/drain_collect.fixed ... ok
tests/ui/drop_non_drop.rs ... ok
tests/ui/duplicate_underscore_argument.rs ... ok
tests/ui/duplicated_attributes.rs ... ok
tests/ui/duration_suboptimal_units.rs ... ok
tests/ui/duration_suboptimal_units_days_weeks.rs ... ok
tests/ui/double_parens.fixed ... ok
tests/ui/duration_subsec.rs ... ok
tests/ui/duration_suboptimal_units_days_weeks.fixed ... ok
tests/ui/duration_suboptimal_units.fixed ... ok
tests/ui/duration_subsec.fixed ... ok
tests/ui/else_if_without_else.rs ... ok
tests/ui/eager_transmute.rs ... ok
tests/ui/elidable_lifetime_names.rs ... ok
tests/ui/empty_docs.rs ... ok
---
...............................................    (147/147)

======== tests/rustdoc-gui/globals.goml ========

[ERROR] line 14: The following errors happened: [Property named `"searchIndex"` doesn't exist]: for command `assert-window-property-false: {"searchIndex": null}`
    at <file:///checkout/obj/build/x86_64-unknown-linux-gnu/test/rustdoc-gui/doc/test_docs/index.html?search=Foo>

======== tests/rustdoc-gui/search-result-display.goml ========

[WARNING] line 39: Delta is 0 for "x", maybe try to use `compare-elements-position` instead?

@izagawd
Copy link
Contributor Author

izagawd commented Jan 28, 2026

@bors r=oli-obk

@rust-bors
Copy link
Contributor

rust-bors bot commented Jan 28, 2026

📌 Commit a1893d3 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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jan 28, 2026
rust-bors bot pushed a commit that referenced this pull request Jan 28, 2026
Rollup of 9 pull requests

Successful merges:

 - #151239 (Support trait objects in type info reflection)
 - #150893 (offload: move (un)register lib into global_ctors)
 - #151013 (Add some clarifications and fixes for fmt syntax)
 - #151666 (compiler: Rename several types/traits for per-query vtables)
 - #151738 (Add `extern crate core` to diagnostic tests)
 - #151747 (Update `askama` version to `0.15.2`)
 - #151759 (Update `browser-ui-test` version to `0.23.3`)
 - #151763 (Add FileCheck annotations to simplify_match.rs)
 - #151766 (Fix `x fix`, again)
@rust-bors rust-bors bot merged commit f488671 into rust-lang:main Jan 28, 2026
18 of 22 checks passed
@rustbot rustbot added this to the 1.95.0 milestone Jan 28, 2026
rust-timer added a commit that referenced this pull request Jan 28, 2026
Rollup merge of #151239 - izagawd:comptime-reflection-dyn-trait-variant, r=oli-obk

Support trait objects in type info reflection

Tracking issue: #146922

Adds type_info support for trait object types by introducing a DynTrait variant

~~I can't seem to get it to work correctly with `dyn for<'a> Foo<'a>`, though it works fine for normal `dyn Foo` trait objects~~

r? @oli-obk
@izagawd izagawd deleted the comptime-reflection-dyn-trait-variant branch January 28, 2026 17:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-run-make Area: port run-make Makefiles to rmake.rs 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.

7 participants