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

Allow the last field of a struct to be a DST #13121

Closed
nrc opened this issue Mar 24, 2014 · 5 comments
Closed

Allow the last field of a struct to be a DST #13121

nrc opened this issue Mar 24, 2014 · 5 comments

Comments

@nrc
Copy link
Member

nrc commented Mar 24, 2014

blocks #12938
assigned to me

@nrc nrc mentioned this issue Mar 24, 2014
23 tasks
@nrc
Copy link
Member Author

nrc commented Mar 24, 2014

This will interact with inherited fields for virtual structs. I propose we order the fields in structs with the base struct first and the concrete struct last. Then we only allow a DST field in non-virtual structs, which means they would actually be the last field.

@nrc nrc mentioned this issue Apr 8, 2014
bors added a commit that referenced this issue Apr 23, 2014
Now with proper checking of enums and allows unsized fields as the last field in a struct or variant. This PR only checks passing of unsized types and distinguishing them from sized ones. To be safe we also need to control storage.

Closes issues #12969 and #13121, supersedes #13375 (all the discussion there is valid here too).
@brson
Copy link
Contributor

brson commented May 31, 2014

@nick29581 Is this done with 696f16e merged?

@pnkfelix
Copy link
Member

Something that came up in an IRC discussion (which botbot.me unfortunately failed to capture completely): when the last field of a struct is unsized, is it always supposed to be one of the type parameters to the struct, as is shown in the examples on niko's blog? Or is one allowed to have an unsized field where the struct could never be instantiated to a sized version of itself?

I.e. compare these two variants:

struct Foo<Sized? T> { x: int, d: T }
struct Bar{ x: int, d: [int] }

I assume the way one would create an instance of the latter, if it is allowed at all, would be via transmute, as some level, even if only e.g. within the Allocator.

(update: deleted bogus example that tried to have unsized local variables. And it also tried to transmute a Foo to a Bar, which seemed sane (though incorrect in the end) when they were unsized locals, but became insane when I turned them into &Foo and &Bar.)


Or perhaps it would be legal to do let b : &Bar = &Bar { x: 0, d: [1,2,3] as [int] }; ?

@nikomatsakis
Copy link
Contributor

@pnkfelix I believe both are allowed but the only way to create the Bar example is via unsafe code

@nrc
Copy link
Member Author

nrc commented Sep 23, 2014

Fixed

@nrc nrc closed this as completed Sep 23, 2014
compiler-errors pushed a commit to compiler-errors/rust that referenced this issue Oct 26, 2022
…nerics, r=Veykril

Support const generics for builtin derive macro

Fixes rust-lang#13121

We have been treating every generic parameter as type parameter during builtin derive macro expansion. This patch adds support for const generics in such expansions.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants