diff options
| author | 许杰友 Jieyou Xu (Joe) <39484203+jieyouxu@users.noreply.github.com> | 2024-11-25 00:39:05 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-11-25 00:39:05 +0800 |
| commit | 1741b394da9818aea67deb66a2b5cf4ddc2a1440 (patch) | |
| tree | e1a54f6fa62c268c51a8eda3fb3094dfa339b99f | |
| parent | 8d20d71256af83d1e26a1f8c402c9938d3d1de86 (diff) | |
| parent | 197bba5a2e834ab62aadff6932fe9059fa41f950 (diff) | |
| download | rust-1741b394da9818aea67deb66a2b5cf4ddc2a1440.tar.gz rust-1741b394da9818aea67deb66a2b5cf4ddc2a1440.zip | |
Rollup merge of #133298 - n0toose:remove-dir-all-but-not-paths, r=Noratrieb
Mention that std::fs::remove_dir_all fails on files This is explicitly mentioned for std::fs::remove_file. 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. Follow-up for #133183.
| -rw-r--r-- | library/std/src/fs.rs | 3 |
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. /// |
