diff options
| author | Ziru Niu <zirconium.n@gmail.com> | 2023-05-25 18:37:58 +0800 |
|---|---|---|
| committer | Ziru Niu <zirconium.n@gmail.com> | 2023-05-25 18:38:38 +0800 |
| commit | dd56f930cc6e174a24ddd1ea5f1bbf9af978abf9 (patch) | |
| tree | c3df00e5076ecdea408d425676eb369381df5796 | |
| parent | 9a767b6b9e1e53c3cfc25103ed7c88d77ee65d5d (diff) | |
| download | rust-dd56f930cc6e174a24ddd1ea5f1bbf9af978abf9.tar.gz rust-dd56f930cc6e174a24ddd1ea5f1bbf9af978abf9.zip | |
Clarify safety concern of `io::Read::read` is only relevant in unsafe code
| -rw-r--r-- | library/std/src/io/mod.rs | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/library/std/src/io/mod.rs b/library/std/src/io/mod.rs index 9e09ce337bc..8a007d095d5 100644 --- a/library/std/src/io/mod.rs +++ b/library/std/src/io/mod.rs @@ -593,7 +593,8 @@ pub trait Read { /// This may happen for example because fewer bytes are actually available right now /// (e. g. being close to end-of-file) or because read() was interrupted by a signal. /// - /// As this trait is safe to implement, callers cannot rely on `n <= buf.len()` for safety. + /// As this trait is safe to implement, callers in unsafe code cannot rely on + /// `n <= buf.len()` for safety. /// Extra care needs to be taken when `unsafe` functions are used to access the read bytes. /// Callers have to ensure that no unchecked out-of-bounds accesses are possible even if /// `n > buf.len()`. @@ -603,8 +604,8 @@ pub trait Read { /// contents of `buf` being true. It is recommended that *implementations* /// only write data to `buf` instead of reading its contents. /// - /// Correspondingly, however, *callers* of this method must not assume any guarantees - /// about how the implementation uses `buf`. The trait is safe to implement, + /// Correspondingly, however, *callers* of this method in unsafe code must not assume + /// any guarantees about how the implementation uses `buf`. The trait is safe to implement, /// so it is possible that the code that's supposed to write to the buffer might also read /// from it. It is your responsibility to make sure that `buf` is initialized /// before calling `read`. Calling `read` with an uninitialized `buf` (of the kind one |
