From 229c00415fbaeb511208ed8f9e22516e6c084233 Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Wed, 20 Jan 2021 18:19:50 +0100 Subject: [PATCH] Seal all filesystem related extension traits. --- library/std/src/fs.rs | 28 +++++++++++++++++++++++++++ library/std/src/os/android/fs.rs | 3 ++- library/std/src/os/dragonfly/fs.rs | 3 ++- library/std/src/os/emscripten/fs.rs | 3 ++- library/std/src/os/freebsd/fs.rs | 3 ++- library/std/src/os/fuchsia/fs.rs | 3 ++- library/std/src/os/haiku/fs.rs | 3 ++- library/std/src/os/illumos/fs.rs | 3 ++- library/std/src/os/ios/fs.rs | 3 ++- library/std/src/os/linux/fs.rs | 3 ++- library/std/src/os/macos/fs.rs | 3 ++- library/std/src/os/netbsd/fs.rs | 3 ++- library/std/src/os/openbsd/fs.rs | 3 ++- library/std/src/os/redox/fs.rs | 3 ++- library/std/src/os/solaris/fs.rs | 3 ++- library/std/src/os/vxworks/fs.rs | 3 ++- library/std/src/sys/unix/ext/fs.rs | 15 +++++++------- library/std/src/sys/wasi/ext/fs.rs | 11 ++++++----- library/std/src/sys/windows/ext/fs.rs | 9 +++++---- 19 files changed, 77 insertions(+), 31 deletions(-) diff --git a/library/std/src/fs.rs b/library/std/src/fs.rs index e2d4f2e6a56af..6152f2d458115 100644 --- a/library/std/src/fs.rs +++ b/library/std/src/fs.rs @@ -92,6 +92,10 @@ pub struct File { inner: fs_imp::File, } +/// Allows extension traits within `std`. +#[unstable(feature = "sealed", issue = "none")] +impl crate::sealed::Sealed for File {} + /// Metadata information about a file. /// /// This structure is returned from the [`metadata`] or @@ -102,6 +106,10 @@ pub struct File { #[derive(Clone)] pub struct Metadata(fs_imp::FileAttr); +/// Allows extension traits within `std`. +#[unstable(feature = "sealed", issue = "none")] +impl crate::sealed::Sealed for Metadata {} + /// Iterator over the entries in a directory. /// /// This iterator is returned from the [`read_dir`] function of this module and @@ -128,6 +136,10 @@ pub struct ReadDir(fs_imp::ReadDir); #[stable(feature = "rust1", since = "1.0.0")] pub struct DirEntry(fs_imp::DirEntry); +/// Allows extension traits within `std`. +#[unstable(feature = "sealed", issue = "none")] +impl crate::sealed::Sealed for DirEntry {} + /// Options and flags which can be used to configure how a file is opened. /// /// This builder exposes the ability to configure how a [`File`] is opened and @@ -167,6 +179,10 @@ pub struct DirEntry(fs_imp::DirEntry); #[stable(feature = "rust1", since = "1.0.0")] pub struct OpenOptions(fs_imp::OpenOptions); +/// Allows extension traits within `std`. +#[unstable(feature = "sealed", issue = "none")] +impl crate::sealed::Sealed for OpenOptions {} + /// Representation of the various permissions on a file. /// /// This module only currently provides one bit of information, @@ -179,12 +195,20 @@ pub struct OpenOptions(fs_imp::OpenOptions); #[stable(feature = "rust1", since = "1.0.0")] pub struct Permissions(fs_imp::FilePermissions); +/// Allows extension traits within `std`. +#[unstable(feature = "sealed", issue = "none")] +impl crate::sealed::Sealed for Permissions {} + /// A structure representing a type of file with accessors for each file type. /// It is returned by [`Metadata::file_type`] method. #[stable(feature = "file_type", since = "1.1.0")] #[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)] pub struct FileType(fs_imp::FileType); +/// Allows extension traits within `std`. +#[unstable(feature = "sealed", issue = "none")] +impl crate::sealed::Sealed for FileType {} + /// A builder used to create directories in various manners. /// /// This builder also supports platform-specific options. @@ -195,6 +219,10 @@ pub struct DirBuilder { recursive: bool, } +/// Allows extension traits within `std`. +#[unstable(feature = "sealed", issue = "none")] +impl crate::sealed::Sealed for DirBuilder {} + /// Indicates how large a buffer to pre-allocate before reading the entire file. fn initial_buffer_size(file: &File) -> usize { // Allocate one extra byte so the buffer doesn't need to grow before the diff --git a/library/std/src/os/android/fs.rs b/library/std/src/os/android/fs.rs index 6aeef330dfa24..82fe0b90c31c8 100644 --- a/library/std/src/os/android/fs.rs +++ b/library/std/src/os/android/fs.rs @@ -1,6 +1,7 @@ #![stable(feature = "metadata_ext", since = "1.1.0")] use crate::fs::Metadata; +use crate::sealed::Sealed; use crate::sys_common::AsInner; #[allow(deprecated)] @@ -10,7 +11,7 @@ use crate::os::android::raw; /// /// [`fs::Metadata`]: crate::fs::Metadata #[stable(feature = "metadata_ext", since = "1.1.0")] -pub trait MetadataExt { +pub trait MetadataExt: Sealed { /// Gain a reference to the underlying `stat` structure which contains /// the raw information returned by the OS. /// diff --git a/library/std/src/os/dragonfly/fs.rs b/library/std/src/os/dragonfly/fs.rs index e4c4e04cd30aa..e885784739cac 100644 --- a/library/std/src/os/dragonfly/fs.rs +++ b/library/std/src/os/dragonfly/fs.rs @@ -1,6 +1,7 @@ #![stable(feature = "metadata_ext", since = "1.1.0")] use crate::fs::Metadata; +use crate::sealed::Sealed; use crate::sys_common::AsInner; #[allow(deprecated)] @@ -10,7 +11,7 @@ use crate::os::dragonfly::raw; /// /// [`fs::Metadata`]: crate::fs::Metadata #[stable(feature = "metadata_ext", since = "1.1.0")] -pub trait MetadataExt { +pub trait MetadataExt: Sealed { /// Gain a reference to the underlying `stat` structure which contains /// the raw information returned by the OS. /// diff --git a/library/std/src/os/emscripten/fs.rs b/library/std/src/os/emscripten/fs.rs index d4f758a3457fe..a9f46de4d2ec0 100644 --- a/library/std/src/os/emscripten/fs.rs +++ b/library/std/src/os/emscripten/fs.rs @@ -1,6 +1,7 @@ #![stable(feature = "metadata_ext", since = "1.1.0")] use crate::fs::Metadata; +use crate::sealed::Sealed; use crate::sys_common::AsInner; #[allow(deprecated)] @@ -10,7 +11,7 @@ use crate::os::emscripten::raw; /// /// [`fs::Metadata`]: crate::fs::Metadata #[stable(feature = "metadata_ext", since = "1.1.0")] -pub trait MetadataExt { +pub trait MetadataExt: Sealed { /// Gain a reference to the underlying `stat` structure which contains /// the raw information returned by the OS. /// diff --git a/library/std/src/os/freebsd/fs.rs b/library/std/src/os/freebsd/fs.rs index 1eda8690d5d1b..0db3970d18a6a 100644 --- a/library/std/src/os/freebsd/fs.rs +++ b/library/std/src/os/freebsd/fs.rs @@ -1,6 +1,7 @@ #![stable(feature = "metadata_ext", since = "1.1.0")] use crate::fs::Metadata; +use crate::sealed::Sealed; use crate::sys_common::AsInner; #[allow(deprecated)] @@ -10,7 +11,7 @@ use crate::os::freebsd::raw; /// /// [`fs::Metadata`]: crate::fs::Metadata #[stable(feature = "metadata_ext", since = "1.1.0")] -pub trait MetadataExt { +pub trait MetadataExt: Sealed { /// Gain a reference to the underlying `stat` structure which contains /// the raw information returned by the OS. /// diff --git a/library/std/src/os/fuchsia/fs.rs b/library/std/src/os/fuchsia/fs.rs index b48a46f9124a9..a2da22f6cec3f 100644 --- a/library/std/src/os/fuchsia/fs.rs +++ b/library/std/src/os/fuchsia/fs.rs @@ -1,13 +1,14 @@ #![stable(feature = "metadata_ext", since = "1.1.0")] use crate::fs::Metadata; +use crate::sealed::Sealed; use crate::sys_common::AsInner; /// OS-specific extensions to [`fs::Metadata`]. /// /// [`fs::Metadata`]: crate::fs::Metadata #[stable(feature = "metadata_ext", since = "1.1.0")] -pub trait MetadataExt { +pub trait MetadataExt: Sealed { #[stable(feature = "metadata_ext2", since = "1.8.0")] fn st_dev(&self) -> u64; #[stable(feature = "metadata_ext2", since = "1.8.0")] diff --git a/library/std/src/os/haiku/fs.rs b/library/std/src/os/haiku/fs.rs index 28015f6252633..9fb47d76da97a 100644 --- a/library/std/src/os/haiku/fs.rs +++ b/library/std/src/os/haiku/fs.rs @@ -1,6 +1,7 @@ #![stable(feature = "metadata_ext", since = "1.1.0")] use crate::fs::Metadata; +use crate::sealed::Sealed; use crate::sys_common::AsInner; #[allow(deprecated)] @@ -10,7 +11,7 @@ use crate::os::haiku::raw; /// /// [`fs::Metadata`]: crate::fs::Metadata #[stable(feature = "metadata_ext", since = "1.1.0")] -pub trait MetadataExt { +pub trait MetadataExt: Sealed { /// Gain a reference to the underlying `stat` structure which contains /// the raw information returned by the OS. /// diff --git a/library/std/src/os/illumos/fs.rs b/library/std/src/os/illumos/fs.rs index 021d154ff5a8a..d2c5cab5d3e01 100644 --- a/library/std/src/os/illumos/fs.rs +++ b/library/std/src/os/illumos/fs.rs @@ -1,6 +1,7 @@ #![stable(feature = "metadata_ext", since = "1.1.0")] use crate::fs::Metadata; +use crate::sealed::Sealed; use crate::sys_common::AsInner; #[allow(deprecated)] @@ -10,7 +11,7 @@ use crate::os::illumos::raw; /// /// [`fs::Metadata`]: crate::fs::Metadata #[stable(feature = "metadata_ext", since = "1.1.0")] -pub trait MetadataExt { +pub trait MetadataExt: Sealed { /// Gain a reference to the underlying `stat` structure which contains /// the raw information returned by the OS. /// diff --git a/library/std/src/os/ios/fs.rs b/library/std/src/os/ios/fs.rs index 2c5e38a803d30..f8769e36cb7cc 100644 --- a/library/std/src/os/ios/fs.rs +++ b/library/std/src/os/ios/fs.rs @@ -1,6 +1,7 @@ #![stable(feature = "metadata_ext", since = "1.1.0")] use crate::fs::Metadata; +use crate::sealed::Sealed; use crate::sys_common::AsInner; #[allow(deprecated)] @@ -10,7 +11,7 @@ use crate::os::ios::raw; /// /// [`fs::Metadata`]: crate::fs::Metadata #[stable(feature = "metadata_ext", since = "1.1.0")] -pub trait MetadataExt { +pub trait MetadataExt: Sealed { /// Gain a reference to the underlying `stat` structure which contains /// the raw information returned by the OS. /// diff --git a/library/std/src/os/linux/fs.rs b/library/std/src/os/linux/fs.rs index 9b7af97616c9d..69c0f80bd12c4 100644 --- a/library/std/src/os/linux/fs.rs +++ b/library/std/src/os/linux/fs.rs @@ -3,6 +3,7 @@ #![stable(feature = "metadata_ext", since = "1.1.0")] use crate::fs::Metadata; +use crate::sealed::Sealed; use crate::sys_common::AsInner; #[allow(deprecated)] @@ -12,7 +13,7 @@ use crate::os::linux::raw; /// /// [`fs::Metadata`]: crate::fs::Metadata #[stable(feature = "metadata_ext", since = "1.1.0")] -pub trait MetadataExt { +pub trait MetadataExt: Sealed { /// Gain a reference to the underlying `stat` structure which contains /// the raw information returned by the OS. /// diff --git a/library/std/src/os/macos/fs.rs b/library/std/src/os/macos/fs.rs index 4152c3529361d..00f94e5ef99a0 100644 --- a/library/std/src/os/macos/fs.rs +++ b/library/std/src/os/macos/fs.rs @@ -1,6 +1,7 @@ #![stable(feature = "metadata_ext", since = "1.1.0")] use crate::fs::Metadata; +use crate::sealed::Sealed; use crate::sys_common::AsInner; #[allow(deprecated)] @@ -10,7 +11,7 @@ use crate::os::macos::raw; /// /// [`fs::Metadata`]: crate::fs::Metadata #[stable(feature = "metadata_ext", since = "1.1.0")] -pub trait MetadataExt { +pub trait MetadataExt: Sealed { /// Gain a reference to the underlying `stat` structure which contains /// the raw information returned by the OS. /// diff --git a/library/std/src/os/netbsd/fs.rs b/library/std/src/os/netbsd/fs.rs index 6b29a40d2b545..c4952519baee7 100644 --- a/library/std/src/os/netbsd/fs.rs +++ b/library/std/src/os/netbsd/fs.rs @@ -1,6 +1,7 @@ #![stable(feature = "metadata_ext", since = "1.1.0")] use crate::fs::Metadata; +use crate::sealed::Sealed; use crate::sys_common::AsInner; #[allow(deprecated)] @@ -10,7 +11,7 @@ use crate::os::netbsd::raw; /// /// [`fs::Metadata`]: crate::fs::Metadata #[stable(feature = "metadata_ext", since = "1.1.0")] -pub trait MetadataExt { +pub trait MetadataExt: Sealed { /// Gain a reference to the underlying `stat` structure which contains /// the raw information returned by the OS. /// diff --git a/library/std/src/os/openbsd/fs.rs b/library/std/src/os/openbsd/fs.rs index 3143dc95fdf44..f919787f7625f 100644 --- a/library/std/src/os/openbsd/fs.rs +++ b/library/std/src/os/openbsd/fs.rs @@ -1,6 +1,7 @@ #![stable(feature = "metadata_ext", since = "1.1.0")] use crate::fs::Metadata; +use crate::sealed::Sealed; use crate::sys_common::AsInner; #[allow(deprecated)] @@ -10,7 +11,7 @@ use crate::os::openbsd::raw; /// /// [`fs::Metadata`]: crate::fs::Metadata #[stable(feature = "metadata_ext", since = "1.1.0")] -pub trait MetadataExt { +pub trait MetadataExt: Sealed { /// Gain a reference to the underlying `stat` structure which contains /// the raw information returned by the OS. /// diff --git a/library/std/src/os/redox/fs.rs b/library/std/src/os/redox/fs.rs index 0f179c8b837dd..e7eb142fc667c 100644 --- a/library/std/src/os/redox/fs.rs +++ b/library/std/src/os/redox/fs.rs @@ -1,6 +1,7 @@ #![stable(feature = "metadata_ext", since = "1.1.0")] use crate::fs::Metadata; +use crate::sealed::Sealed; use crate::sys_common::AsInner; #[allow(deprecated)] @@ -10,7 +11,7 @@ use crate::os::redox::raw; /// /// [`fs::Metadata`]: crate::fs::Metadata #[stable(feature = "metadata_ext", since = "1.1.0")] -pub trait MetadataExt { +pub trait MetadataExt: Sealed { /// Gain a reference to the underlying `stat` structure which contains /// the raw information returned by the OS. /// diff --git a/library/std/src/os/solaris/fs.rs b/library/std/src/os/solaris/fs.rs index 908c5c38a842e..6594a567f4c43 100644 --- a/library/std/src/os/solaris/fs.rs +++ b/library/std/src/os/solaris/fs.rs @@ -1,6 +1,7 @@ #![stable(feature = "metadata_ext", since = "1.1.0")] use crate::fs::Metadata; +use crate::sealed::Sealed; use crate::sys_common::AsInner; #[allow(deprecated)] @@ -10,7 +11,7 @@ use crate::os::solaris::raw; /// /// [`fs::Metadata`]: crate::fs::Metadata #[stable(feature = "metadata_ext", since = "1.1.0")] -pub trait MetadataExt { +pub trait MetadataExt: Sealed { /// Gain a reference to the underlying `stat` structure which contains /// the raw information returned by the OS. /// diff --git a/library/std/src/os/vxworks/fs.rs b/library/std/src/os/vxworks/fs.rs index 77e6238ca1f52..02653045a1986 100644 --- a/library/std/src/os/vxworks/fs.rs +++ b/library/std/src/os/vxworks/fs.rs @@ -1,12 +1,13 @@ #![stable(feature = "metadata_ext", since = "1.1.0")] use crate::fs::Metadata; +use crate::sealed::Sealed; use crate::sys_common::AsInner; /// /// [`fs::Metadata`]: crate::fs::Metadata #[stable(feature = "metadata_ext", since = "1.1.0")] -pub trait MetadataExt { +pub trait MetadataExt: Sealed { #[stable(feature = "metadata_ext2", since = "1.8.0")] fn st_dev(&self) -> u64; #[stable(feature = "metadata_ext2", since = "1.8.0")] diff --git a/library/std/src/sys/unix/ext/fs.rs b/library/std/src/sys/unix/ext/fs.rs index ba75b9bac8035..4940f014d9dab 100644 --- a/library/std/src/sys/unix/ext/fs.rs +++ b/library/std/src/sys/unix/ext/fs.rs @@ -5,6 +5,7 @@ use crate::fs::{self, OpenOptions, Permissions}; use crate::io; use crate::path::Path; +use crate::sealed::Sealed; use crate::sys; use crate::sys::platform::fs::MetadataExt as UnixMetadataExt; use crate::sys_common::{AsInner, AsInnerMut, FromInner}; @@ -14,7 +15,7 @@ use io::{Read, Write}; /// Unix-specific extensions to [`fs::File`]. #[stable(feature = "file_offset", since = "1.15.0")] -pub trait FileExt { +pub trait FileExt: Sealed { /// Reads a number of bytes starting from a given offset. /// /// Returns the number of bytes read. @@ -220,7 +221,7 @@ impl FileExt for fs::File { /// Unix-specific extensions to [`fs::Permissions`]. #[stable(feature = "fs_ext", since = "1.1.0")] -pub trait PermissionsExt { +pub trait PermissionsExt: Sealed { /// Returns the underlying raw `st_mode` bits that contain the standard /// Unix permissions for this file. /// @@ -297,7 +298,7 @@ impl PermissionsExt for Permissions { /// Unix-specific extensions to [`fs::OpenOptions`]. #[stable(feature = "fs_ext", since = "1.1.0")] -pub trait OpenOptionsExt { +pub trait OpenOptionsExt: Sealed { /// Sets the mode bits that a new file will be created with. /// /// If a new file is created as part of an `OpenOptions::open` call then this @@ -365,7 +366,7 @@ impl OpenOptionsExt for OpenOptions { /// Unix-specific extensions to [`fs::Metadata`]. #[stable(feature = "metadata_ext", since = "1.1.0")] -pub trait MetadataExt { +pub trait MetadataExt: Sealed { /// Returns the ID of the device containing the file. /// /// # Examples @@ -716,7 +717,7 @@ impl MetadataExt for fs::Metadata { /// Adds support for special Unix file types such as block/character devices, /// pipes, and sockets. #[stable(feature = "file_type_ext", since = "1.5.0")] -pub trait FileTypeExt { +pub trait FileTypeExt: Sealed { /// Returns `true` if this file type is a block device. /// /// # Examples @@ -809,7 +810,7 @@ impl FileTypeExt for fs::FileType { /// Unix-specific extension methods for [`fs::DirEntry`]. #[stable(feature = "dir_entry_ext", since = "1.1.0")] -pub trait DirEntryExt { +pub trait DirEntryExt: Sealed { /// Returns the underlying `d_ino` field in the contained `dirent` /// structure. /// @@ -860,7 +861,7 @@ pub fn symlink, Q: AsRef>(original: P, link: Q) -> io::Resu /// Unix-specific extensions to [`fs::DirBuilder`]. #[stable(feature = "dir_builder", since = "1.6.0")] -pub trait DirBuilderExt { +pub trait DirBuilderExt: Sealed { /// Sets the mode to create new directories with. This option defaults to /// 0o777. /// diff --git a/library/std/src/sys/wasi/ext/fs.rs b/library/std/src/sys/wasi/ext/fs.rs index 4f7cf6018d90f..8fbd78883c04b 100644 --- a/library/std/src/sys/wasi/ext/fs.rs +++ b/library/std/src/sys/wasi/ext/fs.rs @@ -6,11 +6,12 @@ use crate::fs::{self, File, Metadata, OpenOptions}; use crate::io::{self, IoSlice, IoSliceMut}; use crate::path::{Path, PathBuf}; +use crate::sealed::Sealed; use crate::sys::fs::osstr2str; use crate::sys_common::{AsInner, AsInnerMut, FromInner}; /// WASI-specific extensions to [`File`]. -pub trait FileExt { +pub trait FileExt: Sealed { /// Reads a number of bytes starting from a given offset. /// /// Returns the number of bytes read. @@ -275,7 +276,7 @@ impl FileExt for fs::File { } /// WASI-specific extensions to [`fs::OpenOptions`]. -pub trait OpenOptionsExt { +pub trait OpenOptionsExt: Sealed { /// Pass custom `dirflags` argument to `path_open`. /// /// This option configures the `dirflags` argument to the @@ -390,7 +391,7 @@ impl OpenOptionsExt for OpenOptions { } /// WASI-specific extensions to [`fs::Metadata`]. -pub trait MetadataExt { +pub trait MetadataExt: Sealed { /// Returns the `st_dev` field of the internal `filestat_t` fn dev(&self) -> u64; /// Returns the `st_ino` field of the internal `filestat_t` @@ -430,7 +431,7 @@ impl MetadataExt for fs::Metadata { /// /// Adds support for special WASI file types such as block/character devices, /// pipes, and sockets. -pub trait FileTypeExt { +pub trait FileTypeExt: Sealed { /// Returns `true` if this file type is a block device. fn is_block_device(&self) -> bool; /// Returns `true` if this file type is a character device. @@ -457,7 +458,7 @@ impl FileTypeExt for fs::FileType { } /// WASI-specific extension methods for [`fs::DirEntry`]. -pub trait DirEntryExt { +pub trait DirEntryExt: Sealed { /// Returns the underlying `d_ino` field of the `dirent_t` fn ino(&self) -> u64; } diff --git a/library/std/src/sys/windows/ext/fs.rs b/library/std/src/sys/windows/ext/fs.rs index b20eafb4d53a5..cb1ab97c8a50c 100644 --- a/library/std/src/sys/windows/ext/fs.rs +++ b/library/std/src/sys/windows/ext/fs.rs @@ -5,12 +5,13 @@ use crate::fs::{self, Metadata, OpenOptions}; use crate::io; use crate::path::Path; +use crate::sealed::Sealed; use crate::sys; use crate::sys_common::{AsInner, AsInnerMut}; /// Windows-specific extensions to [`fs::File`]. #[stable(feature = "file_offset", since = "1.15.0")] -pub trait FileExt { +pub trait FileExt: Sealed { /// Seeks to a given position and reads a number of bytes. /// /// Returns the number of bytes read. @@ -93,7 +94,7 @@ impl FileExt for fs::File { /// Windows-specific extensions to [`fs::OpenOptions`]. #[stable(feature = "open_options_ext", since = "1.10.0")] -pub trait OpenOptionsExt { +pub trait OpenOptionsExt: Sealed { /// Overrides the `dwDesiredAccess` argument to the call to [`CreateFile`] /// with the specified value. /// @@ -294,7 +295,7 @@ impl OpenOptionsExt for OpenOptions { /// [`BY_HANDLE_FILE_INFORMATION`]: /// https://docs.microsoft.com/en-us/windows/win32/api/fileapi/ns-fileapi-by_handle_file_information #[stable(feature = "metadata_ext", since = "1.1.0")] -pub trait MetadataExt { +pub trait MetadataExt: Sealed { /// Returns the value of the `dwFileAttributes` field of this metadata. /// /// This field contains the file system attribute information for a file @@ -498,7 +499,7 @@ impl MetadataExt for Metadata { /// /// On Windows, a symbolic link knows whether it is a file or directory. #[unstable(feature = "windows_file_type_ext", issue = "none")] -pub trait FileTypeExt { +pub trait FileTypeExt: Sealed { /// Returns `true` if this file type is a symbolic link that is also a directory. #[unstable(feature = "windows_file_type_ext", issue = "none")] fn is_symlink_dir(&self) -> bool;