about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorBarosl Lee <vcs@barosl.com>2016-02-29 15:04:22 +0900
committerBarosl Lee <vcs@barosl.com>2016-04-12 15:12:39 +0900
commitbcbc9e5346941011f36f71f66c808675b263a589 (patch)
tree860c9e61d90daf6880942d9b40d66e7ae843cdf4 /src/libstd
parentc0221c8897db309a79990367476177b1230bb264 (diff)
downloadrust-bcbc9e5346941011f36f71f66c808675b263a589.tar.gz
rust-bcbc9e5346941011f36f71f66c808675b263a589.zip
Describe more platform-specific behaviors of `std::fs::rename`
Fixes #31301.
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/fs.rs9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/libstd/fs.rs b/src/libstd/fs.rs
index c4d6cb33365..6777dfdabb7 100644
--- a/src/libstd/fs.rs
+++ b/src/libstd/fs.rs
@@ -968,7 +968,8 @@ pub fn symlink_metadata<P: AsRef<Path>>(path: P) -> io::Result<Metadata> {
     fs_imp::lstat(path.as_ref()).map(Metadata)
 }
 
-/// Rename a file or directory to a new name.
+/// Rename a file or directory to a new name, replacing the original file if
+/// `to` already exists.
 ///
 /// This will not work if the new name is on a different mount point.
 ///
@@ -976,6 +977,12 @@ pub fn symlink_metadata<P: AsRef<Path>>(path: P) -> io::Result<Metadata> {
 ///
 /// This function currently corresponds to the `rename` function on Unix
 /// and the `MoveFileEx` function with the `MOVEFILE_REPLACE_EXISTING` flag on Windows.
+///
+/// Because of this, the behavior when both `from` and `to` exist differs. On
+/// Unix, if `from` is a directory, `to` must also be an (empty) directory. If
+/// `from` is not a directory, `to` must also be not a directory. In contrast,
+/// on Windows, `from` can be anything, but `to` must *not* be a directory.
+///
 /// Note that, this [may change in the future][changes].
 /// [changes]: ../io/index.html#platform-specific-behavior
 ///