Skip to content

Commit 2ec0f84

Browse files
authored
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
2 parents d5fc7cf + 6df44a3 commit 2ec0f84

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

library/std/src/io/error.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -440,12 +440,18 @@ impl Error {
440440
/// `GetLastError` on Windows) and will return a corresponding instance of
441441
/// [`Error`] for the error code.
442442
///
443+
/// This should be called immediately after a call to a platform function,
444+
/// otherwise the state of the error value is indeterminate. In particular,
445+
/// other standard library functions may call platform functions that may
446+
/// (or may not) reset the error value even if they succeed.
447+
///
443448
/// # Examples
444449
///
445450
/// ```
446451
/// use std::io::Error;
447452
///
448-
/// println!("last OS error: {:?}", Error::last_os_error());
453+
/// let os_error = Error::last_os_error();
454+
/// println!("last OS error: {:?}", os_error);
449455
/// ```
450456
#[stable(feature = "rust1", since = "1.0.0")]
451457
#[must_use]

0 commit comments

Comments
 (0)