Skip to content
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

Can DynMetadata be made constructable? #126828

Open
Rua opened this issue Jun 22, 2024 · 2 comments
Open

Can DynMetadata be made constructable? #126828

Rua opened this issue Jun 22, 2024 · 2 comments
Labels
C-feature-request Category: A feature request, i.e: not implemented / a PR. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@Rua
Copy link
Contributor

Rua commented Jun 22, 2024

Related tracking issue: #81513

As of right now, the only way to get a DynMetadata is to call ptr::metadata on an existing pointer, which can create a chicken-and-egg problem. It could be useful to be able to get the metadata for a hypothetical trait object Foo as Trait as well, without first having to construct such a trait object. However, I don't know if this would be possible, and whether it would lead to soundness issues or have other undesired consequences.

@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jun 22, 2024
@fmease fmease added T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. C-feature-request Category: A feature request, i.e: not implemented / a PR. labels Jun 23, 2024
@bjorn3
Copy link
Member

bjorn3 commented Jun 24, 2024

I think std::ptr::metadata(std::ptr::null::<Foo>() as *const dyn Trait) would work.

@jieyouxu jieyouxu removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Aug 5, 2024
@spunit262
Copy link
Contributor

Yes metadata(null()) does work.

feature(unsize) is only need if you want to be generic over the trait, otherwise T: Trait is enough.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-feature-request Category: A feature request, i.e: not implemented / a PR. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

6 participants