From 23c76ff7b912f16f6fdbde167306b08e59353427 Mon Sep 17 00:00:00 2001 From: Daniel Henry-Mantilla Date: Tue, 3 Sep 2019 12:17:03 +0200 Subject: [PATCH 1/2] Added warning around code with reference to uninit bytes --- src/libstd/io/mod.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs index 5060f368229bb..495c0c8d17256 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_. + // + // - This having defined behavior is **unstable**: + // it could become UB in the future, + // at which point it would have be changed. g.buf.reserve(reservation_size(r)); let capacity = g.buf.capacity(); g.buf.set_len(capacity); From b03d3dc478ba13f405cf9a877a4894de096a1cc1 Mon Sep 17 00:00:00 2001 From: Daniel Henry-Mantilla Date: Tue, 3 Sep 2019 15:36:21 +0200 Subject: [PATCH 2/2] Changed comment to better reflect std's exceptional situation --- src/libstd/io/mod.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs index 495c0c8d17256..0386dbd490d03 100644 --- a/src/libstd/io/mod.rs +++ b/src/libstd/io/mod.rs @@ -374,11 +374,11 @@ where // FIXME(danielhenrymantilla): #42788 // // - This creates a (mut) reference to a slice of - // _uninitialized integers_. + // _uninitialized_ integers, which is **undefined behavior** // - // - This having defined behavior is **unstable**: - // it could become UB in the future, - // at which point it would have be changed. + // - 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);