-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
RFC: Aligned
trait
#3319
base: master
Are you sure you want to change the base?
RFC: Aligned
trait
#3319
Conversation
3a78602
to
7320191
Compare
3daaa26
to
7f4fd2b
Compare
I also suggested having |
Yeah, this would be nice for |
So, one slight callout that I think might be worth considering for a future edition. I think that I also think that However, this is just my opinion on the matter, and changing everyone's muscle-memory for There may have also been discussion on this already that I didn't see in the RFC, in which case that's fine and we should include it. But I think we should at least have some stance on this. |
Discussion of |
I think having the "only aligned" version be |
Yeah, it's entirely reasonable to just say it's not worth the effort, although I think it might be worth considering for completeness. I personally think it would be a positive change as a way of pushing people to think more about what kinds of types they want to allow in their APIs, but it could also be another barrier to learning the language for others. I just want to make sure that it was mentioned in the discussion so people can think about whether they prefer |
Another factor in this discussion is that new opt-out traits might be added in the future (like |
Added note about |
I'd like to see some consideration on how this interacts with the pointer metadata APIs? In particular, it is being considered in rust-lang/rust#81513 to add |
I would expect #[repr(C)]
struct PascalString {
len: u8,
#[thin]
data: [u8],
} There are also fat |
Currently, this RFC leaves adding |
Prior art for this: |
Also expand on back-compat issues in Future Possibilities
I've proposed that |
@Jules-Bertholet can you elaborate on what is enabled by this trait? The RFC says
but I was hoping for a more detailed example, or a link. |
@nikomatsakis I've added a link to unsized-vec, which is the crate that originally motivated me to write this RFC. The specific "dangling pointer" use-case that the RFC originally cited turns out to have a much simpler solution that doesn't require |
unsized-vec has been entirely rewritten since this RFC was first posted. Compare |
This may be off-topic but I would still want point out a possible extension for the alignment of the unsized types. Currently custom DST has this problem of having to dynamically calculate the offset for its unsized field due to its unknown alignment. (rust-lang/rust#106683 (comment)). However, from a zero-cost abstraction point of view, if we can somehow guarantee the alignment of the unsized type to be the same value or to be a large enough value (which is quite common), this offset calculation should not be necessary. This would involve complex interactions with the type representations and I don't expect it to come with this RFC. But still worth to explore for custom DST. |
See also the lang-team notes around
I have a few suggestions for things I think the RFC should note:
It's not necessary to add these, but I think it's an improvement to mention these explicitly. off-topic
This can't be done in general, because we allow increasing alignment arbitrarily high. However, it could be allowed to say It's not possible to increase alignment for the trait object but not for the concrete type, though, or at least not without breaking the ability to actually create that trait object via unsizing, because it's necessary to be able to go from Footnotes
|
355163d
to
85a4e7d
Compare
@CAD97 I've adressed your comments. |
85a4e7d
to
3cba8ae
Compare
With the |
As a datapoint: we actually have an |
@Jules-Bertholet we discussed this in the @rust-lang/lang planning meeting and we were concerned that the RFC didn't really have much for motivation. @workingjubilee mentioned that there was strong motivation, but it wasn't really present in the RFC. Do you think you could update it? |
I've added an explanation of how |
Rendered
Add an
Aligned
trait tocore::marker
, as a supertrait ofSized
.Implementation