mirror of
https://github.com/rust-lang/rust.git
synced 2026-06-02 15:56:09 +03:00
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.
This commit is contained in:
@@ -371,6 +371,14 @@ fn read_to_end_with_reservation<R, F>(
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user