about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorMazdak Farrokhzad <twingoow@gmail.com>2019-09-05 03:59:47 +0200
committerGitHub <noreply@github.com>2019-09-05 03:59:47 +0200
commitc195145f565159c84e61b2f2c6f4ef2bebd5b66f (patch)
treeda1869c326cb19d956e93b0121beab5674a338bb /src/libstd
parent24f0778341691661121d093d4767a937fdb8ebed (diff)
parentb03d3dc478ba13f405cf9a877a4894de096a1cc1 (diff)
downloadrust-c195145f565159c84e61b2f2c6f4ef2bebd5b66f.tar.gz
rust-c195145f565159c84e61b2f2c6f4ef2bebd5b66f.zip
Rollup merge of #64123 - danielhenrymantilla:add_comment_about_uninit_integers, r=Centril
Added warning around code with reference to uninit bytes

Officially, uninitialized integers, and therefore, Rust references to them are _invalid_ (note that this may evolve into official defined behavior (_c.f._, https://github.com/rust-lang/unsafe-code-guidelines/issues/71)).

However, `::std` uses references to uninitialized integers when working with the `Read::initializer` feature (#42788), since it relies on this unstably having defined behavior with the current implementation of the compiler (IIUC).

Hence the comment to disincentivize people from using this pattern outside the standard library.
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/io/mod.rs8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs
index 5060f368229..0386dbd490d 100644
--- a/src/libstd/io/mod.rs
+++ b/src/libstd/io/mod.rs
@@ -371,6 +371,14 @@ where
     loop {
         if g.len == g.buf.len() {
             unsafe {
+                // FIXME(danielhenrymantilla): #42788
+                //
+                //   - This creates a (mut) reference to a slice of
+                //     _uninitialized_ integers, which is **undefined behavior**
+                //
+                //   - Only the standard library gets to soundly "ignore" this,
+                //     based on its privileged knowledge of unstable rustc
+                //     internals;
                 g.buf.reserve(reservation_size(r));
                 let capacity = g.buf.capacity();
                 g.buf.set_len(capacity);