diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2021-12-02 22:16:16 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-12-02 22:16:16 +0100 |
| commit | 2ec0f841b44015888b69154955bd5aa7bcd9c9be (patch) | |
| tree | 1d105779b57b3ea2932328305fb97e985987decb | |
| parent | d5fc7cf2c499771520cbd81d000f920a0627a8c2 (diff) | |
| parent | 6df44a389cfab95807027a420903ee0b8cc08f0e (diff) | |
| download | rust-2ec0f841b44015888b69154955bd5aa7bcd9c9be.tar.gz rust-2ec0f841b44015888b69154955bd5aa7bcd9c9be.zip | |
Rollup merge of #91460 - ChrisDenton:doc-last-os-error, r=joshtriplett
Document how `last_os_error` should be used It should be made clear that the state of the last OS error could change if another function call is made before the call to `Error::last_os_error()`. Fixes: #53155
| -rw-r--r-- | library/std/src/io/error.rs | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/library/std/src/io/error.rs b/library/std/src/io/error.rs index d93c6172cfc..da88c8c9261 100644 --- a/library/std/src/io/error.rs +++ b/library/std/src/io/error.rs @@ -440,12 +440,18 @@ impl Error { /// `GetLastError` on Windows) and will return a corresponding instance of /// [`Error`] for the error code. /// + /// This should be called immediately after a call to a platform function, + /// otherwise the state of the error value is indeterminate. In particular, + /// other standard library functions may call platform functions that may + /// (or may not) reset the error value even if they succeed. + /// /// # Examples /// /// ``` /// use std::io::Error; /// - /// println!("last OS error: {:?}", Error::last_os_error()); + /// let os_error = Error::last_os_error(); + /// println!("last OS error: {:?}", os_error); /// ``` #[stable(feature = "rust1", since = "1.0.0")] #[must_use] |
