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

Add trait_upcasting related languages changes #1259

Closed
wants to merge 2 commits into from

Conversation

crlf0710
Copy link
Member

@crlf0710 crlf0710 commented Sep 2, 2022

@ehuss ehuss added the S-waiting-on-stabilization Waiting for a stabilization PR to be merged in the main Rust repository label Sep 2, 2022
Co-authored-by: Michael Goulet <michael@errs.io>
@WaffleLapkin
Copy link
Member

What is the status here? The feature is being stabilized so maybe we should merge the reference changes :)

@@ -34,6 +34,7 @@ code.
* Invoking undefined behavior via compiler intrinsics.
* Executing code compiled with platform features that the current platform
does not support (see [`target_feature`]), *except* if the platform explicitly documents this to be safe.
* Performing non-nop coercion on a dangling or unaligned raw pointer.
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not exactly clear why this is being added in this PR, since I can't find any reference to it related to RFC 3324. Can you say more about why this is being added? Is there some context here?

cc @RalfJung since you often know about UB stuff.

Copy link
Member

Choose a reason for hiding this comment

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

I believe it was decided in a T-lang FCP in rust-lang/rust#101336, the stabilization of trait_upcasting just becomes the first time that this behavior can be exercised, as far as I recall.

Copy link
Member

Choose a reason for hiding this comment

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

My expectation was that it is completely okay for the pointer itself to be dangling or unaligned; only the vtable must be valid. And we already require the vtable to be valid; we say it is UB when one creates the following:

Invalid metadata in a wide reference, `Box<T>`, or raw pointer

So I don't think any change is needed to the UB list. At least I highly doubt we want to require the data part of the wide raw pointer to be valid in any way for such a coercion.

Cc @rust-lang/opsem

@ehuss
Copy link
Contributor

ehuss commented Nov 24, 2023

What is the status here? The feature is being stabilized so maybe we should merge the reference changes :)

The reference changes have to wait for the stabilization PR to merge.

Sorry I didn't get to reviewing this earlier, I did not know it was being stabilized, and I tend to not prioritize pre-stabilization PRs when it seems like they are a long way off from being stabilized.

@@ -34,6 +34,7 @@ code.
* Invoking undefined behavior via compiler intrinsics.
* Executing code compiled with platform features that the current platform
does not support (see [`target_feature`]), *except* if the platform explicitly documents this to be safe.
* Performing non-nop coercion on a dangling or unaligned raw pointer.
Copy link
Member

Choose a reason for hiding this comment

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

Though now that I read this, I think this should be clarified though to integrate language which more precisely reflects the decision in rust-lang/rust#101336.

Specifically, should we mention that the vtable pointer needs to point to a valid vtable?

@@ -172,6 +172,8 @@ an implementation of `Unsize<U>` for `T` will be provided:

* `T` to `dyn U`, when `T` implements `U + Sized`, and `U` is [object safe].

* `dyn T` to `dyn U`, when `U` is one of `T`'s supertraits.
Copy link
Member

Choose a reason for hiding this comment

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

This should also mention that upcasting coercions allow dropping auto traits. i.e. dyn Trait + Send -> dyn Trait.

@@ -159,7 +159,7 @@ Coercion is allowed between the following types:
### Unsized Coercions

The following coercions are called `unsized coercions`, since they
relate to converting sized types to unsized types, and are permitted in a few
relate to converting types to unsized types, and are permitted in a few
cases where other coercions are not, as described above. They can still happen
anywhere else a coercion can occur.
Copy link
Member

Choose a reason for hiding this comment

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

IMO it is worth stating explicitly that "unsizing" is a misnomer now and this also covers coercions from unsized types to unsized types.

@ehuss
Copy link
Contributor

ehuss commented Jan 22, 2024

Ping @crlf0710 Do you think you'd be able to address the comments here?

@RalfJung
Copy link
Member

RalfJung commented Jan 22, 2024

This feature is being reverted so we should not land this PR.

That said, it'd still be good to have the PR ready for when this gets stabilized for real. :)

@ehuss
Copy link
Contributor

ehuss commented Jan 22, 2024

Yea, I wanted to get this ready for when it lands again. The stabilization should not have been done without this being ready, but I let it fall through the cracks.

@crlf0710
Copy link
Member Author

Do you think you'd be able to address the comments here?

Frankly, i don't feel i have enough skill of writing to address the comments here(especially as i'm not a English-speaker). I can deal with "add XXX after YYY"-style of comments well, but i can't deal with the "This should mention" and "worth stating explicitly" style of comments.

@crlf0710
Copy link
Member Author

Help wanted: It would be nice if someone could post a new PR addressing comments above and superseding this PR.

@traviscross
Copy link
Contributor

We discussed this in the lang-docs call today. It seems this stabilization still needs to happen, though the way for it has been mostly cleared with this PR being merged:

..and the documentation here likely needs to be updated accordingly.

cc @WaffleLapkin

@crlf0710
Copy link
Member Author

Superseded by #1622 :)

@crlf0710 crlf0710 closed this Sep 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-stabilization Waiting for a stabilization PR to be merged in the main Rust repository
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants