Uh oh!
There was an error while loading. Please reload this page.
Add a DynSized trait - #44469
Conversation
rust-highfive
commented
Sep 9, 2017
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @pnkfelix (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
There was a problem hiding this comment.
The error message is now thrown twice, once when checking if the field type is WF, and once when checking that it is DynSized.
I'm not sure how to prevent this, or whether it even matters.
e5c3032 to
4bf8bbbCompareplietar
commented
Sep 9, 2017
Rustdoc output is not great with this (it displays the implicit I'm working on a fix for it, should I add it to this PR, or as a follow up one ? |
retep998
commented
Sep 10, 2017
Personally I'd prefer if the last field of a struct could be a |
That would be a problem because of alignment concerns - you can't do the "DST align" thing without knowing the alignment. However, we could allow it for I don't want to add a new |
@arielb1 Why should it need to know the alignment if I have a pointer? The alignment of the EDIT: Hmmmmm, the alignment of the |
bors
commented
Sep 11, 2017
☔ The latest upstream changes (presumably #44316) made this pull request unmergeable. Please resolve the merge conflicts. |
@retep998 Yes, that's definitely a use case I'd like to support eventually. My goal was to keep the feature conservative for now, and expand with an RFC. OTOH, there was already an RFC for extern types, so maybe opaque tails falls under that RFC. I'm happy to include it if there's consensus about it. @arielb1 Something like #[repr(C)]structFoo{x:u8,tail:Opaque,// OK}fnuse_foo(foo:&Foo) -> &Opaque{&foo.tail// ERROR: Cannot access field `foo`, type `Opaque` doesn't implement `DynSized`}There are cases where it could be allowed, such as single field structs, |
pnkfelix
commented
Sep 13, 2017
I'll try to look at this somewhat soon, but I assume the review should not be considered pressing until #44295 successfully lands, right? |
eddyb
commented
Sep 13, 2017
r? @arielb1 cc @rust-lang/compiler Does this need FCP? |
arielb1
commented
Sep 13, 2017
I think this does |
carols10cents
commented
Sep 18, 2017
@arielb1 is this ready to be proposed to be fcped? if so, could you do that please? if not, what needs to be done first? |
arielb1
commented
Sep 19, 2017
@rfcbot fcp merge |
arielb1
commented
Sep 19, 2017
I don't think I can invoke rfcbot. I'll need to ask @nikomatsakis for help. |
Team member @arielb1 has proposed to merge this. The next step is review by the rest of the tagged teams: No concerns currently listed. Once these reviewers reach consensus, this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
Zoxc
commented
Sep 26, 2017
Note that this will likely break the use std::fmt::Debug;traitDescriptiveSpec<'r>{}impl<'r,T>DescriptiveSpec<'r>for&'rT{}fnfrom_spec<'r,T:DescriptiveSpec<'r>>(spec:&'rT){}fnmatching_contains<'s,T:'s,I>(a:&mut&'sI)where&'sI:Debug{from_spec(a);}fnmain(){}See #21974 (comment) It would also be a good idea to use crater on this. |
Did you check that spectral isn't fixed by the sized-constraint "hack"? This should still break your example, but I'm not sure how bad that is (that's why we want a crater run) - it "only" makes an existing bug worse (e.g. the |
Zoxc
commented
Sep 27, 2017
Also I suggest you remove the documentation on |
@plietar Hi, could you resolve the merge conflict and fix the CI failure? Thanks. |
Rustfmt needs support for extern types, and rls depends on rustfmt.
The DynSized trait is implemented by all types which have a size and alignment known at runtime. This includes every type other than extern types, introduced in RFC 1861 and implemented in rust-lang#44295, which are completely opaque. The main motivation for this trait is to prevent the use of !DynSized types as struct tails. Consider for example the following types : ```rust extern { type foo; } struct A<T: ?Sized> { a_x: u8 a_y: T } struct B<T: ?Sized> { b_x: u8 b_y: T } ``` Before this change, the type `A<B<foo>>` is considered well-formed. However, the alignment of `B<foo>` and thus the offset of the `a_y` field depends on the alignment of `foo`, which is unknown. By introducing this new trait, struct tails are now required to implement `DynSized`, such that their alignment is known. The trait is an implicit bound, making `A<B<foo>>` ill-formed. Just like the `Sized` trait, the default bound can be opted-out by using `?DynSized`.
aturon
commented
Sep 29, 2017
Checking off for @nrc, who is away for some time. @petrochenkov, are you OK with this landing? |
petrochenkov
commented
Sep 30, 2017
Oh, I didn't even notice it was pending on me. |
rfcbot
commented
Sep 30, 2017
🔔 This is now entering its final comment period, as per the review above. 🔔 |
bors
commented
Oct 4, 2017
☔ The latest upstream changes (presumably #44901) made this pull request unmergeable. Please resolve the merge conflicts. |
rfcbot
commented
Oct 10, 2017
The final comment period is now complete. |
shepmaster
commented
Oct 15, 2017
Heads-up @plietar — you have merge conflicts that need to be addressed before this can progress. |
alexcrichton
commented
Oct 19, 2017
triage ping for @plietar! out of curiosity, any update on this? |
carols10cents
commented
Oct 30, 2017
I'm going to close this PR due to inactivity; looks like even though this has made it through FCP the merge conflicts need to be resolved and then a crater run needs to happen. @plietar thank you for your contribution, please feel free to reopen this when you have a chance to resolve the merge conflicts! Let us know if you need any help!! |
mikeyhew
commented
Nov 4, 2017
Is there a discussion taking place somewhere on the bullet points @plietar outlined in the first comment on this PR? |
(This depends on #44295)
The DynSized trait is implemented by all types which have a size and alignment
known at runtime. This includes every type other than extern types, introduced
in RFC 1861 and implemented in #44295, which are completely opaque.
The main motivation for this trait is to prevent the use of
!DynSizedtypes asstruct tails. Consider for example the following types :
Before this change, the type
A<B<foo>>is considered well-formed. However,the alignment of
B<foo>and thus the offset of thea_yfield depends on thealignment of
foo, which is unknown.By introducing this new trait, struct tails are now required to implement
DynSized, such that their alignment is known. The trait is an implicit bound,making
A<B<foo>>ill-formed.Just like the
Sizedtrait, the default bound can be opted-out by using?DynSized.The trait also prevents the use of the
size_of_valandalign_of_valfunctions with extern types.After discussion on IRC, the intention here is to include
DynSizedas an "implementation detail" for now just to fix extern types, and propose an RFC later to extend it / stabilize it. Until this is the case, generic functions/types can't be defined for extern types.The implementation here is deliberately conservative. There's a number of open questions to be resolved by the future RFC. All the answers are no in the current implementation.
DynSizedbe in the prelude ??Sizedto?DynSized(where applicable) ? For now I have only change theis_nullandas_reffunctions on raw pointers, since they should frequently be used with extern types.!DynSizedtails be allowed in structs, as long as they are never accessed ?struct A { x: u8, y: foo }could be accepted buta.yrejected, since getting the offset ofyis the part that can't be done.DynSized? This would allow things like C strings (null terminated) and Pascal strings (length prefixed). This has some overlap with the "custom DST" proposal.