-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Closed
Labels
T-langRelevant to the language team, which will review and decide on the RFC.Relevant to the language team, which will review and decide on the RFC.
Description
https://play.rust-lang.org/?gist=beaba7cc10b93f3e6ac1d97717099f26&version=undefined
The code produces a warning:
Compiling playground v0.0.1 (file:///playground)
warning: unnecessary `unsafe` block
--> src/main.rs:9:5
|
9 | unsafe { u.f1 = 5 };
| ^^^^^^^^^^^^^^^^^^^ unnecessary `unsafe` block
|
= note: #[warn(unused_unsafe)] on by default
Finished dev [unoptimized + debuginfo] target(s) in 0.55 secs
Running `target/debug/playground`
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?
Metadata
Metadata
Assignees
Labels
T-langRelevant to the language team, which will review and decide on the RFC.Relevant to the language team, which will review and decide on the RFC.