Skip to content

Commit e13b7f7

Browse files
authored
Rollup merge of #105745 - philpax:patch-1, r=jyn514
docs(std): clarify remove_dir_all errors When using `remove_dir_all`, I assumed that the function was idempotent and that I could always call it to remove a directory if it existed. That's not the case and it bit me in production, so I figured I'd submit this to clarify the docs.
2 parents 901fdb3 + d5d2785 commit e13b7f7

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

library/std/src/fs.rs

+5
Original file line numberDiff line numberDiff line change
@@ -2284,6 +2284,11 @@ pub fn remove_dir<P: AsRef<Path>>(path: P) -> io::Result<()> {
22842284
///
22852285
/// See [`fs::remove_file`] and [`fs::remove_dir`].
22862286
///
2287+
/// `remove_dir_all` will fail if `remove_dir` or `remove_file` fail on any constituent paths, including the root path.
2288+
/// As a result, the directory you are deleting must exist, meaning that this function is not idempotent.
2289+
///
2290+
/// Consider ignoring the error if validating the removal is not required for your use case.
2291+
///
22872292
/// [`fs::remove_file`]: remove_file
22882293
/// [`fs::remove_dir`]: remove_dir
22892294
///

0 commit comments

Comments
 (0)