Skip to content

Commit c195145

Browse files
authored
Rollup merge of rust-lang#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._, rust-lang/unsafe-code-guidelines#71)). However, `::std` uses references to uninitialized integers when working with the `Read::initializer` feature (rust-lang#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.
2 parents 24f0778 + b03d3dc commit c195145

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/libstd/io/mod.rs

+8
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,14 @@ where
371371
loop {
372372
if g.len == g.buf.len() {
373373
unsafe {
374+
// FIXME(danielhenrymantilla): #42788
375+
//
376+
// - This creates a (mut) reference to a slice of
377+
// _uninitialized_ integers, which is **undefined behavior**
378+
//
379+
// - Only the standard library gets to soundly "ignore" this,
380+
// based on its privileged knowledge of unstable rustc
381+
// internals;
374382
g.buf.reserve(reservation_size(r));
375383
let capacity = g.buf.capacity();
376384
g.buf.set_len(capacity);

0 commit comments

Comments
 (0)