diff options
| author | bors <bors@rust-lang.org> | 2020-06-28 08:26:22 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2020-06-28 08:26:22 +0000 |
| commit | 25687caa2e4e35b31c29e28998710670e9d54ee9 (patch) | |
| tree | 65b2f12402411f111f87e2fd39ec73aae44d6325 /src/libstd | |
| parent | 3b4a3d68b5d3026bab9d41fcc004439207ecff90 (diff) | |
| parent | cdb59d90417b60bc373ab4ea44c768447a7c7994 (diff) | |
| download | rust-25687caa2e4e35b31c29e28998710670e9d54ee9.tar.gz rust-25687caa2e4e35b31c29e28998710670e9d54ee9.zip | |
Auto merge of #73830 - Manishearth:rollup-8k68ysm, r=Manishearth
Rollup of 10 pull requests Successful merges: - #72796 (MIR sanity check: validate types on assignment) - #73243 (Add documentation to point to `File::open` or `OpenOptions::open` instead of `is_file` to check read/write possibility) - #73525 (Prepare for LLVM 11) - #73672 (Adds a clearer message for when the async keyword is missing from a f…) - #73708 (Explain move errors that occur due to method calls involving `self` (take two)) - #73758 (improper_ctypes: fix remaining `Reveal:All`) - #73763 (errors: use `-Z terminal-width` in JSON emitter) - #73796 (replace more `DefId`s with `LocalDefId`) - #73797 (fix typo in self-profile.md) - #73809 (Add links to fs::DirEntry::metadata) Failed merges: r? @ghost
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/fs.rs | 21 | ||||
| -rw-r--r-- | src/libstd/path.rs | 19 |
2 files changed, 34 insertions, 6 deletions
diff --git a/src/libstd/fs.rs b/src/libstd/fs.rs index f4c164a324e..17f890375f8 100644 --- a/src/libstd/fs.rs +++ b/src/libstd/fs.rs @@ -1033,8 +1033,16 @@ impl Metadata { /// [`is_dir`], and will be false for symlink metadata /// obtained from [`symlink_metadata`]. /// + /// When the goal is simply to read from (or write to) the source, the most + /// reliable way to test the source can be read (or written to) is to open + /// it. Only using `is_file` can break workflows like `diff <( prog_a )` on + /// a Unix-like system for example. See [`File::open`] or + /// [`OpenOptions::open`] for more information. + /// /// [`is_dir`]: struct.Metadata.html#method.is_dir /// [`symlink_metadata`]: fn.symlink_metadata.html + /// [`File::open`]: struct.File.html#method.open + /// [`OpenOptions::open`]: struct.OpenOptions.html#method.open /// /// # Examples /// @@ -1307,8 +1315,16 @@ impl FileType { /// [`is_dir`] and [`is_symlink`]; only zero or one of these /// tests may pass. /// + /// When the goal is simply to read from (or write to) the source, the most + /// reliable way to test the source can be read (or written to) is to open + /// it. Only using `is_file` can break workflows like `diff <( prog_a )` on + /// a Unix-like system for example. See [`File::open`] or + /// [`OpenOptions::open`] for more information. + /// /// [`is_dir`]: struct.FileType.html#method.is_dir /// [`is_symlink`]: struct.FileType.html#method.is_symlink + /// [`File::open`]: struct.File.html#method.open + /// [`OpenOptions::open`]: struct.OpenOptions.html#method.open /// /// # Examples /// @@ -1429,7 +1445,10 @@ impl DirEntry { /// Returns the metadata for the file that this entry points at. /// /// This function will not traverse symlinks if this entry points at a - /// symlink. + /// symlink. To traverse symlinks use [`fs::metadata`] or [`fs::File::metadata`]. + /// + /// [`fs::metadata`]: fn.metadata.html + /// [`fs::File::metadata`]: struct.File.html#method.metadata /// /// # Platform-specific behavior /// diff --git a/src/libstd/path.rs b/src/libstd/path.rs index 8ff7508ba64..f14a9ff72f6 100644 --- a/src/libstd/path.rs +++ b/src/libstd/path.rs @@ -2503,11 +2503,20 @@ impl Path { /// # See Also /// /// This is a convenience function that coerces errors to false. If you want to - /// check errors, call [fs::metadata] and handle its Result. Then call - /// [fs::Metadata::is_file] if it was Ok. - /// - /// [fs::metadata]: ../../std/fs/fn.metadata.html - /// [fs::Metadata::is_file]: ../../std/fs/struct.Metadata.html#method.is_file + /// check errors, call [`fs::metadata`] and handle its Result. Then call + /// [`fs::Metadata::is_file`] if it was Ok. + /// + /// When the goal is simply to read from (or write to) the source, the most + /// reliable way to test the source can be read (or written to) is to open + /// it. Only using `is_file` can break workflows like `diff <( prog_a )` on + /// a Unix-like system for example. See [`File::open`] or + /// [`OpenOptions::open`] for more information. + /// + /// [`fs::metadata`]: ../../std/fs/fn.metadata.html + /// [`fs::Metadata`]: ../../std/fs/struct.Metadata.html + /// [`fs::Metadata::is_file`]: ../../std/fs/struct.Metadata.html#method.is_file + /// [`File::open`]: ../../std/fs/struct.File.html#method.open + /// [`OpenOptions::open`]: ../../std/fs/struct.OpenOptions.html#method.open #[stable(feature = "path_ext", since = "1.5.0")] pub fn is_file(&self) -> bool { fs::metadata(self).map(|m| m.is_file()).unwrap_or(false) |
