Skip to content

Commit ab1ccf8

Browse files
committed
fix: clarify that fs::rename on unix accepts targets that don't exist
1 parent 8e15021 commit ab1ccf8

1 file changed

Lines changed: 10 additions & 9 deletions

File tree

library/std/src/fs.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2751,19 +2751,20 @@ pub fn symlink_metadata<P: AsRef<Path>>(path: P) -> io::Result<Metadata> {
27512751
///
27522752
/// # Platform-specific behavior
27532753
///
2754-
/// This function currently corresponds to the `rename` function on Unix
2755-
/// and the `MoveFileExW` or `SetFileInformationByHandle` function on Windows.
2756-
///
2757-
/// Because of this, the behavior when both `from` and `to` exist differs. On
2758-
/// Unix, if `from` is a directory, `to` must also be an (empty) directory. If
2759-
/// `from` is not a directory, `to` must also be not a directory. The behavior
2760-
/// on Windows is the same on Windows 10 1607 and higher if `FileRenameInfoEx`
2761-
/// is supported by the filesystem; otherwise, `from` can be anything, but
2762-
/// `to` must *not* be a directory.
2754+
/// This function currently corresponds to the [rename] function on Unix, and
2755+
/// `MoveFileExW` with a fallback to `SetFileInformationByHandle` on Windows.
2756+
/// The exact behavior differs:
2757+
/// - If `to` does not exist, `from` can be anything.
2758+
/// - On Unix, when `from` is a directory and `to` exists, `to` must be an empty directory.
2759+
/// - On Unix, when `from` is not a directory and `to` exists, `to` may not be a directory.
2760+
/// - On Windows 10 version 1607 and above, the behavior is the same as Unix if the
2761+
/// filesystem supports `FileRenameInfoEx`.
2762+
/// - Otherwise on Windows, `from` can be anything but `to` must not be a directory.
27632763
///
27642764
/// Note that, this [may change in the future][changes].
27652765
///
27662766
/// [changes]: io#platform-specific-behavior
2767+
/// [rename]: https://pubs.opengroup.org/onlinepubs/9799919799/functions/rename.html
27672768
///
27682769
/// # Errors
27692770
///

0 commit comments

Comments
 (0)