rust/library
bors 95815c9b2b Auto merge of #76241 - RalfJung:flt2dec, r=Mark-Simulacrum
flt2dec: properly handle uninitialized memory

The float-to-str code currently uses uninitialized memory incorrectly (see https://github.com/rust-lang/rust/issues/76092). This PR fixes that.

Specifically, that code used `&mut [T]` as "out references", but it would be incorrect for the caller to actually pass uninitialized memory. So the PR changes this to `&mut [MaybeUninit<T>]`, and then functions return a `&[T]` to the part of the buffer that they initialized (some functions already did that, indirectly via `&Formatted`, others were adjusted to return that buffer instead of just the initialized length).

What I particularly like about this is that it moves `unsafe` to the right place: previously, the outermost caller had to use `unsafe` to assert that things are initialized; now it is the functions that do the actual initializing which have the corresponding `unsafe` block when they call `MaybeUninit::slice_get_ref` (renamed in https://github.com/rust-lang/rust/pull/76217 to `slice_assume_init_ref`).

Reviewers please be aware that I have no idea how any of this code actually works. My changes were purely mechanical and type-driven. The test suite passes so I guess I didn't screw up badly...

Cc @sfackler this is somewhat related to your RFC, and possibly some of this code could benefit from (a generalized version of) the API you describe there. But for now I think what I did is "good enough".

Fixes https://github.com/rust-lang/rust/issues/76092.
2020-09-02 15:23:08 +00:00
..
alloc Will land in 1.48, not 1.47 2020-09-01 09:50:32 -04:00
backtrace@4083a90168 std: Switch from libbacktrace to gimli 2020-07-28 16:34:01 -07:00
core Auto merge of #76241 - RalfJung:flt2dec, r=Mark-Simulacrum 2020-09-02 15:23:08 +00:00
panic_abort Rollup merge of #75990 - rylev:arm-fastfail, r=alexcrichton 2020-08-30 01:43:54 +02:00
panic_unwind Auto merge of #70212 - Amanieu:catch_foreign, r=Mark-Simulacrum 2020-08-28 01:20:17 +00:00
proc_macro Add -Z proc-macro-backtrace to allow showing proc-macro panics 2020-08-30 22:17:24 -04:00
profiler_builtins Add InstrProfilingPlatformFuchsia.c to profiler_builtins 2020-08-27 11:52:36 -07:00
rtstartup
rustc-std-workspace-alloc
rustc-std-workspace-core
rustc-std-workspace-std
std Rollup merge of #76206 - CDirkx:const-ipv6, r=ecstatic-morse 2020-09-01 18:24:41 -07:00
stdarch@78891cdf29 fix broken git commit in stdarch 2020-08-03 15:52:30 +08:00
term
test Prefer https link for wikipedia URLs 2020-08-23 10:02:42 +00:00
unwind Add back unwinding support for Sony PSP 2020-08-08 02:14:40 -04:00