Skip to content

Commit d95e074

Browse files
authored
Rollup merge of rust-lang#62102 - RalfJung:read, r=Centril
call out explicitly that general read needs to be called with an initialized buffer
2 parents 5343acd + 390f717 commit d95e074

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/libstd/io/mod.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -506,9 +506,18 @@ pub trait Read {
506506
///
507507
/// No guarantees are provided about the contents of `buf` when this
508508
/// function is called, implementations cannot rely on any property of the
509-
/// contents of `buf` being true. It is recommended that implementations
509+
/// contents of `buf` being true. It is recommended that *implementations*
510510
/// only write data to `buf` instead of reading its contents.
511511
///
512+
/// Correspondingly, however, *callers* of this method may not assume any guarantees
513+
/// about how the implementation uses `buf`. The trait is safe to implement,
514+
// so it is possible that the code that's supposed to write to the buffer might also read
515+
// from it. It is your responsibility to make sure that `buf` is initialized
516+
/// before calling `read`. Calling `read` with an uninitialized `buf` (of the kind one
517+
/// obtains via [`MaybeUninit<T>`]) is not safe, and can lead to undefined behavior.
518+
///
519+
/// [`MaybeUninit<T>`]: ../mem/union.MaybeUninit.html
520+
///
512521
/// # Errors
513522
///
514523
/// If this function encounters any form of I/O or other error, an error

0 commit comments

Comments
 (0)