From 6add5c99cd1aed9b4c816613770da89470918d7b Mon Sep 17 00:00:00 2001 From: Tobias Bucher Date: Tue, 14 May 2024 11:40:19 +0200 Subject: [PATCH] Document behavior of `create_dir_all` wrt. empty path The behavior makes sense because `Path::new("one_component").parent() == Some(Path::new(""))`, so if one naively wants to create the parent directory for a file to be written, it simply works. Closes #105108 by documenting the current behavior. --- library/std/src/fs.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/library/std/src/fs.rs b/library/std/src/fs.rs index 77e94365b08ec..5d78b9611a02c 100644 --- a/library/std/src/fs.rs +++ b/library/std/src/fs.rs @@ -2310,6 +2310,9 @@ pub fn create_dir>(path: P) -> io::Result<()> { /// If this function returns an error, some of the parent components might have /// been created already. /// +/// If the empty path is passed to this function, it always succeeds without +/// creating any directories. +/// /// # Platform-specific behavior /// /// This function currently corresponds to multiple calls to the `mkdir`