about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPanagiotis "Ivory" Vasilopoulos <git@n0toose.net>2024-11-21 15:58:06 +0100
committerPanagiotis Vasilopoulos <git@n0toose.net>2024-11-21 17:18:39 +0100
commit197bba5a2e834ab62aadff6932fe9059fa41f950 (patch)
tree27b91f8b9105bc7b972bfafba9b912e93dda04cb
parent717f5df2c308dfb4b7b8e6c002c11fe8269c4011 (diff)
downloadrust-197bba5a2e834ab62aadff6932fe9059fa41f950.tar.gz
rust-197bba5a2e834ab62aadff6932fe9059fa41f950.zip
Mention that std::fs::remove_dir_all fails on files
This is explicitly mentioned for std::fs::remove_file's documentation,
but not in the aforementioned function.

It is more likely for a slightly lazy programmer to believe that
removing a file would work and that they do not have to distinguish
between directories (with contents) and files themself, because of the
function's recursive nature and how it distinguishes between files and
directories when removing them.
-rw-r--r--library/std/src/fs.rs3
1 files changed, 2 insertions, 1 deletions
diff --git a/library/std/src/fs.rs b/library/std/src/fs.rs
index 555e8804eab..d846a4e5f09 100644
--- a/library/std/src/fs.rs
+++ b/library/std/src/fs.rs
@@ -2804,8 +2804,9 @@ pub fn remove_dir<P: AsRef<Path>>(path: P) -> io::Result<()> {
 ///
 /// See [`fs::remove_file`] and [`fs::remove_dir`].
 ///
-/// `remove_dir_all` will fail if `remove_dir` or `remove_file` fail on any constituent paths, including the root path.
+/// `remove_dir_all` will fail if `remove_dir` or `remove_file` fail on any constituent paths, including the root `path`.
 /// As a result, the directory you are deleting must exist, meaning that this function is not idempotent.
+/// Additionally, `remove_dir_all` will also fail if the `path` is not a directory.
 ///
 /// Consider ignoring the error if validating the removal is not required for your use case.
 ///