Skip to content

Conversation

@dingxiangfei2009
Copy link
Contributor

@dingxiangfei2009 dingxiangfei2009 commented Dec 14, 2025

This does not fix #148727, rather probably a good addition to how Unsize behaves. I am looking into anti-fundamenetal trait as suggested to solve a different problem.

This patch proposes relaxation on the type unsizing condition.
PhantomData has been in the current type system exempted from being treated as carrying any data, including dropck, virtual call dispatch by DispatchFromDyn and unsizing container by CoerceUnsize. PhantomData is a special 1-ZST that really carries no "data" of the types it captures.

I propose that we should also extend this interpretation to Unsize.

This patch proposes relaxation on the type unsizing
condition.
`PhantomData` has been in the current type system
exempted from being treated as carrying any data,
including dropck, virtual call dispatch by
`DispatchFromDyn` and unsizing container by
`CoerceUnsize`.
`PhantomData` is a special 1-ZST that really
carries no "data" of the types it captures.

I propose that we should also extend this
interpretation to `Unsize`.

Signed-off-by: Xiangfei Ding <[email protected]>
@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. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Dec 14, 2025
@rustbot
Copy link
Collaborator

rustbot commented Dec 14, 2025

r? @lcnr

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

@theemathas theemathas added the T-types Relevant to the types team, which will review and decide on the PR/issue. label Dec 14, 2025
@theemathas
Copy link
Contributor

FYI, with the way you currently worded this PR, if it were to be merged, #148727 would be closed.

@theemathas
Copy link
Contributor

This change is visible on stable. The following code fails to compile on nightly, but compiles with this PR

use std::marker::PhantomData;

pub struct Thing<T: ?Sized>(PhantomData<T>, T);

pub fn foo(x: &Thing<i32>) -> &Thing<dyn Send> {
    x
}

I'm unsure whether this code starting to compiling might cause some library to become unsound.

@theemathas theemathas added the needs-fcp This change is insta-stable, or significant enough to need a team FCP to proceed. label Dec 14, 2025
@lcnr
Copy link
Contributor

lcnr commented Dec 15, 2025

seems fine from a @rust-lang/types perspective, would like to hand this over to lang.

Is there a specific use enabled by this/what's the reasoning behind this PR?

Right now my vibe here is "sure, would be fine, don't really see why this is relevant" which probably makes it harder for T-lang to make a decision here,

The start of the PR description is a bit confusing 😅

This does not fix #148727, rather probably a good addition to how Unsize behaves. I am looking into anti-fundamenetal trait as suggested to solve a different problem.

While you're explicitly stating that it does not fix #148727, this is the first thing you mention so I end up thinking "hmm, how does this relate to #148727, do I have to understand that issue to review this".

I think this PR literally doesn't interact with that unsoundness, so either don't mention it at all or as a quick note at the end stating that these this PR does not interact with it

@lcnr lcnr 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 Dec 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-fcp This change is insta-stable, or significant enough to need a team FCP to proceed. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. 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. T-types Relevant to the types team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unsoundness and ICE due to DispatchFromDyn allowing bogus impls on references.

4 participants