This updates the mutable static item example to fix some issues with how it works and how it is presented.
First, the unsafe operations are wrapped in an unsafe block so that it doesn't trigger unsafe_op_in_unsafe_fn.
Second, it switches the mutation example to use addr_of_mut to avoid the undefined behavior, and to compile correctly in 2024 edition.
Third, it rewrites the second example to be safe with a different description. My understanding is that the original example was written at a time when it was considered that any potential race condition was considered unsafe. However, that is no longer a widely held view. The example has been rewritten to illustrate the two different ways you can wrap mutable static access.
This updates the mutable static item example to fix some issues with how it works and how it is presented.
First, the unsafe operations are wrapped in an
unsafe
block so that it doesn't triggerunsafe_op_in_unsafe_fn
.Second, it switches the mutation example to use addr_of_mut to avoid the undefined behavior, and to compile correctly in 2024 edition.
Third, it rewrites the second example to be safe with a different description. My understanding is that the original example was written at a time when it was considered that any potential race condition was considered unsafe. However, that is no longer a widely held view. The example has been rewritten to illustrate the two different ways you can wrap mutable static access.
This is an alternative to https://github.com/rust-lang/reference/pull/1349.