Skip to content

Commit 60a24db

Browse files
authored
Rollup merge of rust-lang#58660 - RalfJung:maybe-uninit, r=Centril
MaybeUninit: add read_initialized, add examples This adds a new `read_initialized` method, similar to suggestions by @Amanieu and @shepmaster. I also added examples to this and other methods.
2 parents 63cca75 + cefe9b0 commit 60a24db

File tree

3 files changed

+229
-30
lines changed

3 files changed

+229
-30
lines changed

src/libcore/fmt/float.rs

+4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ fn float_to_decimal_common_exact<T>(fmt: &mut Formatter, num: &T,
1515
// FIXME(#53491): Technically, this is calling `get_mut` on an uninitialized
1616
// `MaybeUninit` (here and elsewhere in this file). Revisit this once
1717
// we decided whether that is valid or not.
18+
// Using `freeze` is *not enough*; `flt2dec::Part` is an enum!
1819
let formatted = flt2dec::to_exact_fixed_str(flt2dec::strategy::grisu::format_exact,
1920
*num, sign, precision,
2021
false, buf.get_mut(), parts.get_mut());
@@ -33,6 +34,7 @@ fn float_to_decimal_common_shortest<T>(fmt: &mut Formatter, num: &T,
3334
// enough for f32 and f64
3435
let mut buf = MaybeUninit::<[u8; flt2dec::MAX_SIG_DIGITS]>::uninitialized();
3536
let mut parts = MaybeUninit::<[flt2dec::Part; 4]>::uninitialized();
37+
// FIXME(#53491)
3638
let formatted = flt2dec::to_shortest_str(flt2dec::strategy::grisu::format_shortest, *num,
3739
sign, precision, false, buf.get_mut(),
3840
parts.get_mut());
@@ -71,6 +73,7 @@ fn float_to_exponential_common_exact<T>(fmt: &mut Formatter, num: &T,
7173
unsafe {
7274
let mut buf = MaybeUninit::<[u8; 1024]>::uninitialized(); // enough for f32 and f64
7375
let mut parts = MaybeUninit::<[flt2dec::Part; 6]>::uninitialized();
76+
// FIXME(#53491)
7477
let formatted = flt2dec::to_exact_exp_str(flt2dec::strategy::grisu::format_exact,
7578
*num, sign, precision,
7679
upper, buf.get_mut(), parts.get_mut());
@@ -90,6 +93,7 @@ fn float_to_exponential_common_shortest<T>(fmt: &mut Formatter,
9093
// enough for f32 and f64
9194
let mut buf = MaybeUninit::<[u8; flt2dec::MAX_SIG_DIGITS]>::uninitialized();
9295
let mut parts = MaybeUninit::<[flt2dec::Part; 6]>::uninitialized();
96+
// FIXME(#53491)
9397
let formatted = flt2dec::to_shortest_exp_str(flt2dec::strategy::grisu::format_shortest,
9498
*num, sign, (0, 0), upper,
9599
buf.get_mut(), parts.get_mut());

0 commit comments

Comments
 (0)