Skip to content

Commit 101f7c2

Browse files
committedMar 24, 2018
Rollup merge of #49076 - bobdavelisafrank:filetype-metadata-docfix, r=bluss
Fix Issue #48345, is_file, is_dir, and is_symlink note mutual exclusion The methods on the structures `fs::FileType` and `fs::Metadata` of (respectively) `is_file`, `is_dir`, and `is_symlink` had some ambiguity in documentation, where it was not noted whether files will pass those tests exclusively or not. It is now written that the tests are mutually exclusive. Fixes #48345.
2 parents a64cd26 + aaac69f commit 101f7c2

File tree

1 file changed

+32
-3
lines changed

1 file changed

+32
-3
lines changed
 

‎src/libstd/fs.rs

+32-3
Original file line numberDiff line numberDiff line change
@@ -906,7 +906,13 @@ impl Metadata {
906906
FileType(self.0.file_type())
907907
}
908908

909-
/// Returns whether this metadata is for a directory.
909+
/// Returns whether this metadata is for a directory. The
910+
/// result is mutually exclusive to the result of
911+
/// [`is_file`], and will be false for symlink metadata
912+
/// obtained from [`symlink_metadata`].
913+
///
914+
/// [`is_file`]: struct.Metadata.html#method.is_file
915+
/// [`symlink_metadata`]: fn.symlink_metadata.html
910916
///
911917
/// # Examples
912918
///
@@ -923,7 +929,13 @@ impl Metadata {
923929
#[stable(feature = "rust1", since = "1.0.0")]
924930
pub fn is_dir(&self) -> bool { self.file_type().is_dir() }
925931

926-
/// Returns whether this metadata is for a regular file.
932+
/// Returns whether this metadata is for a regular file. The
933+
/// result is mutually exclusive to the result of
934+
/// [`is_dir`], and will be false for symlink metadata
935+
/// obtained from [`symlink_metadata`].
936+
///
937+
/// [`is_dir`]: struct.Metadata.html#method.is_dir
938+
/// [`symlink_metadata`]: fn.symlink_metadata.html
927939
///
928940
/// # Examples
929941
///
@@ -1148,7 +1160,13 @@ impl Permissions {
11481160
}
11491161

11501162
impl FileType {
1151-
/// Test whether this file type represents a directory.
1163+
/// Test whether this file type represents a directory. The
1164+
/// result is mutually exclusive to the results of
1165+
/// [`is_file`] and [`is_symlink`]; only zero or one of these
1166+
/// tests may pass.
1167+
///
1168+
/// [`is_file`]: struct.FileType.html#method.is_file
1169+
/// [`is_symlink`]: struct.FileType.html#method.is_symlink
11521170
///
11531171
/// # Examples
11541172
///
@@ -1167,6 +1185,12 @@ impl FileType {
11671185
pub fn is_dir(&self) -> bool { self.0.is_dir() }
11681186

11691187
/// Test whether this file type represents a regular file.
1188+
/// The result is mutually exclusive to the results of
1189+
/// [`is_dir`] and [`is_symlink`]; only zero or one of these
1190+
/// tests may pass.
1191+
///
1192+
/// [`is_dir`]: struct.FileType.html#method.is_dir
1193+
/// [`is_symlink`]: struct.FileType.html#method.is_symlink
11701194
///
11711195
/// # Examples
11721196
///
@@ -1185,6 +1209,9 @@ impl FileType {
11851209
pub fn is_file(&self) -> bool { self.0.is_file() }
11861210

11871211
/// Test whether this file type represents a symbolic link.
1212+
/// The result is mutually exclusive to the results of
1213+
/// [`is_dir`] and [`is_file`]; only zero or one of these
1214+
/// tests may pass.
11881215
///
11891216
/// The underlying [`Metadata`] struct needs to be retrieved
11901217
/// with the [`fs::symlink_metadata`] function and not the
@@ -1195,6 +1222,8 @@ impl FileType {
11951222
/// [`Metadata`]: struct.Metadata.html
11961223
/// [`fs::metadata`]: fn.metadata.html
11971224
/// [`fs::symlink_metadata`]: fn.symlink_metadata.html
1225+
/// [`is_dir`]: struct.FileType.html#method.is_dir
1226+
/// [`is_file`]: struct.FileType.html#method.is_file
11981227
/// [`is_symlink`]: struct.FileType.html#method.is_symlink
11991228
///
12001229
/// # Examples

0 commit comments

Comments
 (0)
Please sign in to comment.