Skip to content

Commit a97f354

Browse files
authored
Rollup merge of #69284 - jumbatm:openoptions-create-doc, r=Dylan-DPC
Reword OpenOptions::{create, create_new} doc. Closes #69254. Currently, the doc comment for `fs::OpenOptions::create` doesn't mention its behaviour when opening an existing file, and `fs::OpenOptions::create_new`'s doc comment is worded in a way that doesn't make it clear that it actually _fails_ if the file already exists, not overwrite the existing file with a new one. This PR addresses addresses this by rewording the doc comments to be more explicit. r? @GuillaumeGomez
2 parents 61d3b6d + c899dc1 commit a97f354

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

src/libstd/fs.rs

+4-8
Original file line numberDiff line numberDiff line change
@@ -844,10 +844,7 @@ impl OpenOptions {
844844
self
845845
}
846846

847-
/// Sets the option for creating a new file.
848-
///
849-
/// This option indicates whether a new file will be created if the file
850-
/// does not yet already exist.
847+
/// Sets the option to create a new file, or open it if it already exists.
851848
///
852849
/// In order for the file to be created, [`write`] or [`append`] access must
853850
/// be used.
@@ -868,11 +865,10 @@ impl OpenOptions {
868865
self
869866
}
870867

871-
/// Sets the option to always create a new file.
868+
/// Sets the option to create a new file, failing if it already exists.
872869
///
873-
/// This option indicates whether a new file will be created.
874-
/// No file is allowed to exist at the target location, also no (dangling)
875-
/// symlink.
870+
/// No file is allowed to exist at the target location, also no (dangling) symlink. In this
871+
/// way, if the call succeeds, the file returned is guaranteed to be new.
876872
///
877873
/// This option is useful because it is atomic. Otherwise between checking
878874
/// whether a file exists and creating a new one, the file may have been

0 commit comments

Comments
 (0)