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.
This commit is contained in:
许杰友 Jieyou Xu (Joe) 2024-11-25 00:39:05 +08:00 committed by GitHub
commit 1741b394da
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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.
///