@@ -14,25 +14,17 @@ fn float_to_decimal_common_exact<T>(
1414where
1515 T : flt2dec:: DecodableFloat ,
1616{
17- // SAFETY: Possible undefined behavior, see FIXME(#76092)
18- unsafe {
19- let mut buf = MaybeUninit :: < [ u8 ; 1024 ] > :: uninit ( ) ; // enough for f32 and f64
20- let mut parts = MaybeUninit :: < [ flt2dec:: Part < ' _ > ; 4 ] > :: uninit ( ) ;
21- // FIXME(#76092): This is calling `assume_init_mut` on an uninitialized
22- // `MaybeUninit` (here and elsewhere in this file). Revisit this once
23- // we decided whether that is valid or not.
24- // We can do this only because we are libstd and coupled to the compiler.
25- // (FWIW, using `freeze` would not be enough; `flt2dec::Part` is an enum!)
26- let formatted = flt2dec:: to_exact_fixed_str (
27- flt2dec:: strategy:: grisu:: format_exact,
28- * num,
29- sign,
30- precision,
31- buf. assume_init_mut ( ) ,
32- parts. assume_init_mut ( ) ,
33- ) ;
34- fmt. pad_formatted_parts ( & formatted)
35- }
17+ let mut buf: [ MaybeUninit < u8 > ; 1024 ] = MaybeUninit :: uninit_array ( ) ; // enough for f32 and f64
18+ let mut parts: [ MaybeUninit < flt2dec:: Part < ' _ > > ; 4 ] = MaybeUninit :: uninit_array ( ) ;
19+ let formatted = flt2dec:: to_exact_fixed_str (
20+ flt2dec:: strategy:: grisu:: format_exact,
21+ * num,
22+ sign,
23+ precision,
24+ & mut buf,
25+ & mut parts,
26+ ) ;
27+ fmt. pad_formatted_parts ( & formatted)
3628}
3729
3830// Don't inline this so callers that call both this and the above won't wind
@@ -47,22 +39,18 @@ fn float_to_decimal_common_shortest<T>(
4739where
4840 T : flt2dec:: DecodableFloat ,
4941{
50- // SAFETY: Possible undefined behavior, see FIXME(#76092)
51- unsafe {
52- // enough for f32 and f64
53- let mut buf = MaybeUninit :: < [ u8 ; flt2dec:: MAX_SIG_DIGITS ] > :: uninit ( ) ;
54- let mut parts = MaybeUninit :: < [ flt2dec:: Part < ' _ > ; 4 ] > :: uninit ( ) ;
55- // FIXME(#76092)
56- let formatted = flt2dec:: to_shortest_str (
57- flt2dec:: strategy:: grisu:: format_shortest,
58- * num,
59- sign,
60- precision,
61- buf. assume_init_mut ( ) ,
62- parts. assume_init_mut ( ) ,
63- ) ;
64- fmt. pad_formatted_parts ( & formatted)
65- }
42+ // enough for f32 and f64
43+ let mut buf: [ MaybeUninit < u8 > ; flt2dec:: MAX_SIG_DIGITS ] = MaybeUninit :: uninit_array ( ) ;
44+ let mut parts: [ MaybeUninit < flt2dec:: Part < ' _ > > ; 4 ] = MaybeUninit :: uninit_array ( ) ;
45+ let formatted = flt2dec:: to_shortest_str (
46+ flt2dec:: strategy:: grisu:: format_shortest,
47+ * num,
48+ sign,
49+ precision,
50+ & mut buf,
51+ & mut parts,
52+ ) ;
53+ fmt. pad_formatted_parts ( & formatted)
6654}
6755
6856// Common code of floating point Debug and Display.
@@ -103,22 +91,18 @@ fn float_to_exponential_common_exact<T>(
10391where
10492 T : flt2dec:: DecodableFloat ,
10593{
106- // SAFETY: Possible undefined behavior, see FIXME(#76092)
107- unsafe {
108- let mut buf = MaybeUninit :: < [ u8 ; 1024 ] > :: uninit ( ) ; // enough for f32 and f64
109- let mut parts = MaybeUninit :: < [ flt2dec:: Part < ' _ > ; 6 ] > :: uninit ( ) ;
110- // FIXME(#76092)
111- let formatted = flt2dec:: to_exact_exp_str (
112- flt2dec:: strategy:: grisu:: format_exact,
113- * num,
114- sign,
115- precision,
116- upper,
117- buf. assume_init_mut ( ) ,
118- parts. assume_init_mut ( ) ,
119- ) ;
120- fmt. pad_formatted_parts ( & formatted)
121- }
94+ let mut buf: [ MaybeUninit < u8 > ; 1024 ] = MaybeUninit :: uninit_array ( ) ; // enough for f32 and f64
95+ let mut parts: [ MaybeUninit < flt2dec:: Part < ' _ > > ; 6 ] = MaybeUninit :: uninit_array ( ) ;
96+ let formatted = flt2dec:: to_exact_exp_str (
97+ flt2dec:: strategy:: grisu:: format_exact,
98+ * num,
99+ sign,
100+ precision,
101+ upper,
102+ & mut buf,
103+ & mut parts,
104+ ) ;
105+ fmt. pad_formatted_parts ( & formatted)
122106}
123107
124108// Don't inline this so callers that call both this and the above won't wind
@@ -133,23 +117,19 @@ fn float_to_exponential_common_shortest<T>(
133117where
134118 T : flt2dec:: DecodableFloat ,
135119{
136- // SAFETY: Possible undefined behavior, see FIXME(#76092)
137- unsafe {
138- // enough for f32 and f64
139- let mut buf = MaybeUninit :: < [ u8 ; flt2dec:: MAX_SIG_DIGITS ] > :: uninit ( ) ;
140- let mut parts = MaybeUninit :: < [ flt2dec:: Part < ' _ > ; 6 ] > :: uninit ( ) ;
141- // FIXME(#76092)
142- let formatted = flt2dec:: to_shortest_exp_str (
143- flt2dec:: strategy:: grisu:: format_shortest,
144- * num,
145- sign,
146- ( 0 , 0 ) ,
147- upper,
148- buf. assume_init_mut ( ) ,
149- parts. assume_init_mut ( ) ,
150- ) ;
151- fmt. pad_formatted_parts ( & formatted)
152- }
120+ // enough for f32 and f64
121+ let mut buf: [ MaybeUninit < u8 > ; flt2dec:: MAX_SIG_DIGITS ] = MaybeUninit :: uninit_array ( ) ;
122+ let mut parts: [ MaybeUninit < flt2dec:: Part < ' _ > > ; 6 ] = MaybeUninit :: uninit_array ( ) ;
123+ let formatted = flt2dec:: to_shortest_exp_str (
124+ flt2dec:: strategy:: grisu:: format_shortest,
125+ * num,
126+ sign,
127+ ( 0 , 0 ) ,
128+ upper,
129+ & mut buf,
130+ & mut parts,
131+ ) ;
132+ fmt. pad_formatted_parts ( & formatted)
153133}
154134
155135// Common code of floating point LowerExp and UpperExp.
0 commit comments