Skip to content

Commit bcbc9e5

Browse files
committed
Describe more platform-specific behaviors of std::fs::rename
Fixes #31301.
1 parent c0221c8 commit bcbc9e5

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/libstd/fs.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -968,14 +968,21 @@ pub fn symlink_metadata<P: AsRef<Path>>(path: P) -> io::Result<Metadata> {
968968
fs_imp::lstat(path.as_ref()).map(Metadata)
969969
}
970970

971-
/// Rename a file or directory to a new name.
971+
/// Rename a file or directory to a new name, replacing the original file if
972+
/// `to` already exists.
972973
///
973974
/// This will not work if the new name is on a different mount point.
974975
///
975976
/// # Platform-specific behavior
976977
///
977978
/// This function currently corresponds to the `rename` function on Unix
978979
/// and the `MoveFileEx` function with the `MOVEFILE_REPLACE_EXISTING` flag on Windows.
980+
///
981+
/// Because of this, the behavior when both `from` and `to` exist differs. On
982+
/// Unix, if `from` is a directory, `to` must also be an (empty) directory. If
983+
/// `from` is not a directory, `to` must also be not a directory. In contrast,
984+
/// on Windows, `from` can be anything, but `to` must *not* be a directory.
985+
///
979986
/// Note that, this [may change in the future][changes].
980987
/// [changes]: ../io/index.html#platform-specific-behavior
981988
///

0 commit comments

Comments
 (0)