Skip to content

Commit 6df44a3

Browse files
committed
Document how last_os_error should be used
1 parent 18bb8c6 commit 6df44a3

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)