You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
On second reading, the RFC says "May" which is not the same as "Shall". Which seems weird. Do you HAVE to use unsafe code to write mutable union fields? Is it optional? When is it needed/not needed?
The text was updated successfully, but these errors were encountered:
The change was done as a part of stabilization of Copy unions (rust-lang/rust#42083).
It was previously discussed in the tracking issue for unions (rust-lang/rust#32836 (comment) and below).
The motivation is that for Copy fields unsafe on writes is a false positive, field assignments u1.a = a are equivalent to whole union assignments u1 = u2 which are safe.
This was done before stabilization rather than later to avoid every write of a union field becoming a warning in stable code (possibly an error with deny(warnings)).
https://play.rust-lang.org/?gist=beaba7cc10b93f3e6ac1d97717099f26&version=undefined
The code produces a warning:
Saying the unsafe block is not needed for a write.
But the rfc says writes to union mutable fields require a unsafe block
https://github.com/rust-lang/rfcs/blob/master/text/1444-union.md#writing-fields
Found here:
https://www.reddit.com/r/rust/comments/6rcegm/unsafe_field_accesses_for_unions/
On second reading, the RFC says "May" which is not the same as "Shall". Which seems weird. Do you HAVE to use unsafe code to write mutable union fields? Is it optional? When is it needed/not needed?
The text was updated successfully, but these errors were encountered: