about summary refs log tree commit diff
path: root/library/std/src
diff options
context:
space:
mode:
authorJubilee <46493976+workingjubilee@users.noreply.github.com>2024-05-08 00:37:10 -0700
committerGitHub <noreply@github.com>2024-05-08 00:37:10 -0700
commit40926fdc1955da1b00f80cc9706c4dd130f8b24d (patch)
treeeb156a053cf1bb6ec30d1850082de21626fff0cc /library/std/src
parentbc42f25b046e14a1c316a16fe752576cc10c1571 (diff)
parent81f5175868eefa9a12b27377c9fc474d7033cee6 (diff)
downloadrust-40926fdc1955da1b00f80cc9706c4dd130f8b24d.tar.gz
rust-40926fdc1955da1b00f80cc9706c4dd130f8b24d.zip
Rollup merge of #124782 - anatawa12:docs-create-new-already-exists, r=workingjubilee
add note about `AlreadyExists` to `create_new`

Fixes #119244
Diffstat (limited to 'library/std/src')
-rw-r--r--library/std/src/fs.rs9
1 files changed, 9 insertions, 0 deletions
diff --git a/library/std/src/fs.rs b/library/std/src/fs.rs
index a59faf551e8..77e94365b08 100644
--- a/library/std/src/fs.rs
+++ b/library/std/src/fs.rs
@@ -408,6 +408,9 @@ impl File {
     ///
     /// This function will create a file if it does not exist, or return an error if it does. This
     /// way, if the call succeeds, the file returned is guaranteed to be new.
+    /// If a file exists at the target location, creating a new file will fail with [`AlreadyExists`]
+    /// or another error based on the situation. See [`OpenOptions::open`] for a
+    /// non-exhaustive list of likely errors.
     ///
     /// This option is useful because it is atomic. Otherwise between checking whether a file
     /// exists and creating a new one, the file may have been created by another process (a TOCTOU
@@ -416,6 +419,8 @@ impl File {
     /// This can also be written using
     /// `File::options().read(true).write(true).create_new(true).open(...)`.
     ///
+    /// [`AlreadyExists`]: crate::io::ErrorKind::AlreadyExists
+    ///
     /// # Examples
     ///
     /// ```no_run
@@ -1071,6 +1076,9 @@ impl OpenOptions {
     ///
     /// No file is allowed to exist at the target location, also no (dangling) symlink. In this
     /// way, if the call succeeds, the file returned is guaranteed to be new.
+    /// If a file exists at the target location, creating a new file will fail with [`AlreadyExists`]
+    /// or another error based on the situation. See [`OpenOptions::open`] for a
+    /// non-exhaustive list of likely errors.
     ///
     /// This option is useful because it is atomic. Otherwise between checking
     /// whether a file exists and creating a new one, the file may have been
@@ -1084,6 +1092,7 @@ impl OpenOptions {
     ///
     /// [`.create()`]: OpenOptions::create
     /// [`.truncate()`]: OpenOptions::truncate
+    /// [`AlreadyExists`]: io::ErrorKind::AlreadyExists
     ///
     /// # Examples
     ///