Skip to content

Commit a4f1234

Browse files
committed
add comments explaining our uses of get_ref/get_mut for MaybeUninit
1 parent 2f2f379 commit a4f1234

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

src/libcore/fmt/float.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ fn float_to_decimal_common_exact<T>(fmt: &mut Formatter, num: &T,
2222
unsafe {
2323
let mut buf = MaybeUninit::<[u8; 1024]>::uninitialized(); // enough for f32 and f64
2424
let mut parts = MaybeUninit::<[flt2dec::Part; 4]>::uninitialized();
25+
// FIXME: Technically, this is calling `get_mut` on an uninitialized
26+
// `MaybeUninit` (here and elsewhere in this file). Revisit this once
27+
// we decided whether that is valid or not.
2528
let formatted = flt2dec::to_exact_fixed_str(flt2dec::strategy::grisu::format_exact,
2629
*num, sign, precision,
2730
false, buf.get_mut(), parts.get_mut());

src/libcore/mem.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,6 +1106,9 @@ impl<T> MaybeUninit<T> {
11061106
///
11071107
/// It is up to the caller to guarantee that the `MaybeUninit` really is in an initialized
11081108
/// state, otherwise this will immediately cause undefined behavior.
1109+
// FIXME: We currently rely on the above being incorrect, i.e., we have references
1110+
// to uninitialized data (e.g. in `libstd/sys/windows/mutex.rs`). We should make
1111+
// a final decision about the rules before stabilization.
11091112
#[unstable(feature = "maybe_uninit", issue = "53491")]
11101113
#[inline(always)]
11111114
pub unsafe fn get_ref(&self) -> &T {
@@ -1118,6 +1121,9 @@ impl<T> MaybeUninit<T> {
11181121
///
11191122
/// It is up to the caller to guarantee that the `MaybeUninit` really is in an initialized
11201123
/// state, otherwise this will immediately cause undefined behavior.
1124+
// FIXME: We currently rely on the above being incorrect, i.e., we have references
1125+
// to uninitialized data (e.g. in `libcore/fmt/float.rs`). We should make
1126+
// a final decision about the rules before stabilization.
11211127
#[unstable(feature = "maybe_uninit", issue = "53491")]
11221128
#[inline(always)]
11231129
pub unsafe fn get_mut(&mut self) -> &mut T {

src/libstd/sys/windows/mutex.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,9 @@ impl ReentrantMutex {
168168
}
169169

170170
pub unsafe fn init(&mut self) {
171+
// FIXME: Technically, this is calling `get_ref` on an uninitialized
172+
// `MaybeUninit`. Revisit this once we decided whether that is valid
173+
// or not.
171174
c::InitializeCriticalSection(self.inner.get_ref().get());
172175
}
173176

0 commit comments

Comments
 (0)