Skip to content

Commit a3a0b7f

Browse files
authored
Rollup merge of rust-lang#59470 - czipperz:document-fs-file-close, r=dtolnay
Document std::fs::File close behavior ignoring errors Resolves rust-lang#52685
2 parents a5dfdc5 + a969d40 commit a3a0b7f

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/libstd/fs.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ use crate::time::SystemTime;
2121
/// it was opened with. Files also implement [`Seek`] to alter the logical cursor
2222
/// that the file contains internally.
2323
///
24-
/// Files are automatically closed when they go out of scope.
24+
/// Files are automatically closed when they go out of scope. Errors detected
25+
/// on closing are ignored by the implementation of `Drop`. Use the method
26+
/// [`sync_all`] if these errors must be manually handled.
2527
///
2628
/// # Examples
2729
///
@@ -84,6 +86,7 @@ use crate::time::SystemTime;
8486
/// [`Read`]: ../io/trait.Read.html
8587
/// [`Write`]: ../io/trait.Write.html
8688
/// [`BufReader<R>`]: ../io/struct.BufReader.html
89+
/// [`sync_all`]: struct.File.html#method.sync_all
8790
#[stable(feature = "rust1", since = "1.0.0")]
8891
pub struct File {
8992
inner: fs_imp::File,
@@ -391,9 +394,13 @@ impl File {
391394

392395
/// Attempts to sync all OS-internal metadata to disk.
393396
///
394-
/// This function will attempt to ensure that all in-core data reaches the
397+
/// This function will attempt to ensure that all in-memory data reaches the
395398
/// filesystem before returning.
396399
///
400+
/// This can be used to handle errors that would otherwise only be caught
401+
/// when the `File` is closed. Dropping a file will ignore errors in
402+
/// synchronizing this in-memory data.
403+
///
397404
/// # Examples
398405
///
399406
/// ```no_run

0 commit comments

Comments
 (0)