-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Open
Listed in
Labels
A-DSTsArea: Dynamically-sized types (DSTs)Area: Dynamically-sized types (DSTs)A-coercionsArea: implicit and explicit `expr as Type` coercionsArea: implicit and explicit `expr as Type` coercionsB-RFC-approvedBlocker: Approved by a merged RFC but not yet implemented.Blocker: Approved by a merged RFC but not yet implemented.C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCS-tracking-needs-summaryStatus: It's hard to tell what's been done and what hasn't! Someone should do some investigation.Status: It's hard to tell what's been done and what hasn't! Someone should do some investigation.T-langRelevant to the language teamRelevant to the language team
Description
Tracking issue for RFC rust-lang/rfcs#982.
Current state:
- Implementation work (largely done)Stabilization -- the
CoerceUnsized
trait is unstable and we wish to revisit its design before stabilizing, so for now only stdlib types can be "unsized"To pick up a draggable item, press the space bar. While dragging, use the arrow keys to move the item. Press space again to drop the item in its new position, or press escape to cancel.
Things to consider prior to stabilization
- Interaction with pin, see this internals thread and
Pin
is unsound due to transitive effects ofCoerceUnsized
#68015 for details.
Part of #18469
iago-lito, MatrixDev, demurgos, tim-harding, stepancheg and 3 moreJames-Oswald and orzogc
Metadata
Metadata
Assignees
Labels
A-DSTsArea: Dynamically-sized types (DSTs)Area: Dynamically-sized types (DSTs)A-coercionsArea: implicit and explicit `expr as Type` coercionsArea: implicit and explicit `expr as Type` coercionsB-RFC-approvedBlocker: Approved by a merged RFC but not yet implemented.Blocker: Approved by a merged RFC but not yet implemented.C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCS-tracking-needs-summaryStatus: It's hard to tell what's been done and what hasn't! Someone should do some investigation.Status: It's hard to tell what's been done and what hasn't! Someone should do some investigation.T-langRelevant to the language teamRelevant to the language team
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
steveklabnik commentedon Jan 27, 2015
I'm confused as to what this is about. isn't #18469 the tracking issue?
nrc commentedon Jan 27, 2015
Yes, this is a specific part of 18469. Seems useful to have it by itself since it stands alone (goes for the other issues too).
eternaleye commentedon Jan 14, 2017
Is there anything that could be done to push this towards stabilization? I have some APIs in mind that would benefit significantly from the ability to bound on the
Unsize
trait.alexcrichton commentedon Feb 6, 2017
I was idly wondering about this the other date with a type such as:
Today there's not a huge amount of support for that but I noticed one oddity. So in theory the only way to instantiate such a type is to start with a concrete type, right? Let's say:
I would personally expect, then that if we had a function like:
That function would simultaneously run the destructor for the underlying type and also free the memory. Currently, however, it only frees the memory and doesn't actually run any destructor. More interestingly this namely to me at least means that the
Box<Foo>
type needs two pieces of external data, both a vtable for the destructor but also ausize
for the length of the dynamically sized data.I'm not sure if this is just an unsupported use case perhaps? Or maybe support for this is planned elsewhere? Or maybe this isn't part of this issue at all?
In any case just wanted to bring it up!
arielb1 commentedon Feb 6, 2017
What do you mean by the destructor not being called? I am quite sure it is:
EDIT:
Code above is buggy, better version:
alexcrichton commentedon Feb 6, 2017
Oh I mean when you implement the destructor for
FooConcrete
instead ofFoo
, that one isn't run. (your example gives a segfault locally for me as well...)I'm specifically thinking of something like this:
where the IR is:
Notably there's some concrete type behind
Box<Foo>
, so presumably some dynamic call to a destructor needs to be made, but in this case it isn't :(Stebalien commentedon Feb 6, 2017
@alexcrichton transmuting
Box::new((..., 10usize))
instead ofBox::new((..., 10))
fixes the segfault (bug?).Back on topic,
Foo
isn't a trait so I don't see whyBox<Foo>
should have a vtable;Box<Foo>
is a concrete type (just an unsized one). After transmuting,Box<Foo>
should (and does) forget it ever was aBox<FooConcrete>
.alexcrichton commentedon Feb 6, 2017
@Stebalien ah yes that does indeed fix it!
For me at least I'd expect
Box<Foo>
here to still run the destructor of the underlying type. It's not a trait object, yeah, but it's still erasing the underlying type. Otherwise this'd end up leaking resources, and would practically not be too useful I'd imagine?(that being said I'm still not sure of the practicality of the
Foo
type anyway)51 remaining items