Stream: t-lang/wg-unsafe-code-guidelines

Topic: Cast-to-raw without reborrow


RalfJ (Apr 17 2019 at 06:26, on Zulip):

@Matthew Jasper Is there any way to turn a &mut into a *mut without incurring a reborrow or an intermediate assignment? I am rewriting parts of Stacked Borrows, also to hopefully fix the problems you ran into when implementing the "take a raw ref" operator, but sometimes it is just impossible to even generate the MIR that I'd like to test.

Matthew Jasper (Apr 17 2019 at 06:29, on Zulip):

I don't think so, the way that we generate the cast means that there has to be a reborrow.

RalfJ (Apr 17 2019 at 06:34, on Zulip):

Dang. Well I guess that means we'll have to be creative when that is finally possible, and write the necessary tests then. Would be much easier now when everything is still fresh^^

Charles Lew (Apr 17 2019 at 06:44, on Zulip):

I don't know exactly the details, but i heard that it is defined behavior to first wrap the &mut with Some then transmute it to a *mut. Does that involve a reborrow or an intermediate assignment?

RalfJ (Apr 17 2019 at 06:46, on Zulip):

the transmute unfortunately does not have all the effects of a cast

RalfJ (Apr 17 2019 at 06:47, on Zulip):

and it is the cast that I wanted to study here

RalfJ (Apr 17 2019 at 06:47, on Zulip):

(also, no need to wrap it in Some, you can just transmute &mut to *mut -- but a cast is pretty much always preferred)

Charles Lew (Apr 17 2019 at 06:49, on Zulip):

thanks

Last update: Nov 20 2019 at 13:05UTC