Skip to content

Commit 229c004

Browse files
committed
Seal all filesystem related extension traits.
1 parent 5f22daa commit 229c004

File tree

19 files changed

+77
-31
lines changed

19 files changed

+77
-31
lines changed

library/std/src/fs.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ pub struct File {
9292
inner: fs_imp::File,
9393
}
9494

95+
/// Allows extension traits within `std`.
96+
#[unstable(feature = "sealed", issue = "none")]
97+
impl crate::sealed::Sealed for File {}
98+
9599
/// Metadata information about a file.
96100
///
97101
/// This structure is returned from the [`metadata`] or
@@ -102,6 +106,10 @@ pub struct File {
102106
#[derive(Clone)]
103107
pub struct Metadata(fs_imp::FileAttr);
104108

109+
/// Allows extension traits within `std`.
110+
#[unstable(feature = "sealed", issue = "none")]
111+
impl crate::sealed::Sealed for Metadata {}
112+
105113
/// Iterator over the entries in a directory.
106114
///
107115
/// This iterator is returned from the [`read_dir`] function of this module and
@@ -128,6 +136,10 @@ pub struct ReadDir(fs_imp::ReadDir);
128136
#[stable(feature = "rust1", since = "1.0.0")]
129137
pub struct DirEntry(fs_imp::DirEntry);
130138

139+
/// Allows extension traits within `std`.
140+
#[unstable(feature = "sealed", issue = "none")]
141+
impl crate::sealed::Sealed for DirEntry {}
142+
131143
/// Options and flags which can be used to configure how a file is opened.
132144
///
133145
/// This builder exposes the ability to configure how a [`File`] is opened and
@@ -167,6 +179,10 @@ pub struct DirEntry(fs_imp::DirEntry);
167179
#[stable(feature = "rust1", since = "1.0.0")]
168180
pub struct OpenOptions(fs_imp::OpenOptions);
169181

182+
/// Allows extension traits within `std`.
183+
#[unstable(feature = "sealed", issue = "none")]
184+
impl crate::sealed::Sealed for OpenOptions {}
185+
170186
/// Representation of the various permissions on a file.
171187
///
172188
/// This module only currently provides one bit of information,
@@ -179,12 +195,20 @@ pub struct OpenOptions(fs_imp::OpenOptions);
179195
#[stable(feature = "rust1", since = "1.0.0")]
180196
pub struct Permissions(fs_imp::FilePermissions);
181197

198+
/// Allows extension traits within `std`.
199+
#[unstable(feature = "sealed", issue = "none")]
200+
impl crate::sealed::Sealed for Permissions {}
201+
182202
/// A structure representing a type of file with accessors for each file type.
183203
/// It is returned by [`Metadata::file_type`] method.
184204
#[stable(feature = "file_type", since = "1.1.0")]
185205
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
186206
pub struct FileType(fs_imp::FileType);
187207

208+
/// Allows extension traits within `std`.
209+
#[unstable(feature = "sealed", issue = "none")]
210+
impl crate::sealed::Sealed for FileType {}
211+
188212
/// A builder used to create directories in various manners.
189213
///
190214
/// This builder also supports platform-specific options.
@@ -195,6 +219,10 @@ pub struct DirBuilder {
195219
recursive: bool,
196220
}
197221

222+
/// Allows extension traits within `std`.
223+
#[unstable(feature = "sealed", issue = "none")]
224+
impl crate::sealed::Sealed for DirBuilder {}
225+
198226
/// Indicates how large a buffer to pre-allocate before reading the entire file.
199227
fn initial_buffer_size(file: &File) -> usize {
200228
// Allocate one extra byte so the buffer doesn't need to grow before the

library/std/src/os/android/fs.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#![stable(feature = "metadata_ext", since = "1.1.0")]
22

33
use crate::fs::Metadata;
4+
use crate::sealed::Sealed;
45
use crate::sys_common::AsInner;
56

67
#[allow(deprecated)]
@@ -10,7 +11,7 @@ use crate::os::android::raw;
1011
///
1112
/// [`fs::Metadata`]: crate::fs::Metadata
1213
#[stable(feature = "metadata_ext", since = "1.1.0")]
13-
pub trait MetadataExt {
14+
pub trait MetadataExt: Sealed {
1415
/// Gain a reference to the underlying `stat` structure which contains
1516
/// the raw information returned by the OS.
1617
///

library/std/src/os/dragonfly/fs.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#![stable(feature = "metadata_ext", since = "1.1.0")]
22

33
use crate::fs::Metadata;
4+
use crate::sealed::Sealed;
45
use crate::sys_common::AsInner;
56

67
#[allow(deprecated)]
@@ -10,7 +11,7 @@ use crate::os::dragonfly::raw;
1011
///
1112
/// [`fs::Metadata`]: crate::fs::Metadata
1213
#[stable(feature = "metadata_ext", since = "1.1.0")]
13-
pub trait MetadataExt {
14+
pub trait MetadataExt: Sealed {
1415
/// Gain a reference to the underlying `stat` structure which contains
1516
/// the raw information returned by the OS.
1617
///

library/std/src/os/emscripten/fs.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#![stable(feature = "metadata_ext", since = "1.1.0")]
22

33
use crate::fs::Metadata;
4+
use crate::sealed::Sealed;
45
use crate::sys_common::AsInner;
56

67
#[allow(deprecated)]
@@ -10,7 +11,7 @@ use crate::os::emscripten::raw;
1011
///
1112
/// [`fs::Metadata`]: crate::fs::Metadata
1213
#[stable(feature = "metadata_ext", since = "1.1.0")]
13-
pub trait MetadataExt {
14+
pub trait MetadataExt: Sealed {
1415
/// Gain a reference to the underlying `stat` structure which contains
1516
/// the raw information returned by the OS.
1617
///

library/std/src/os/freebsd/fs.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#![stable(feature = "metadata_ext", since = "1.1.0")]
22

33
use crate::fs::Metadata;
4+
use crate::sealed::Sealed;
45
use crate::sys_common::AsInner;
56

67
#[allow(deprecated)]
@@ -10,7 +11,7 @@ use crate::os::freebsd::raw;
1011
///
1112
/// [`fs::Metadata`]: crate::fs::Metadata
1213
#[stable(feature = "metadata_ext", since = "1.1.0")]
13-
pub trait MetadataExt {
14+
pub trait MetadataExt: Sealed {
1415
/// Gain a reference to the underlying `stat` structure which contains
1516
/// the raw information returned by the OS.
1617
///

library/std/src/os/fuchsia/fs.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
#![stable(feature = "metadata_ext", since = "1.1.0")]
22

33
use crate::fs::Metadata;
4+
use crate::sealed::Sealed;
45
use crate::sys_common::AsInner;
56

67
/// OS-specific extensions to [`fs::Metadata`].
78
///
89
/// [`fs::Metadata`]: crate::fs::Metadata
910
#[stable(feature = "metadata_ext", since = "1.1.0")]
10-
pub trait MetadataExt {
11+
pub trait MetadataExt: Sealed {
1112
#[stable(feature = "metadata_ext2", since = "1.8.0")]
1213
fn st_dev(&self) -> u64;
1314
#[stable(feature = "metadata_ext2", since = "1.8.0")]

library/std/src/os/haiku/fs.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#![stable(feature = "metadata_ext", since = "1.1.0")]
22

33
use crate::fs::Metadata;
4+
use crate::sealed::Sealed;
45
use crate::sys_common::AsInner;
56

67
#[allow(deprecated)]
@@ -10,7 +11,7 @@ use crate::os::haiku::raw;
1011
///
1112
/// [`fs::Metadata`]: crate::fs::Metadata
1213
#[stable(feature = "metadata_ext", since = "1.1.0")]
13-
pub trait MetadataExt {
14+
pub trait MetadataExt: Sealed {
1415
/// Gain a reference to the underlying `stat` structure which contains
1516
/// the raw information returned by the OS.
1617
///

library/std/src/os/illumos/fs.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#![stable(feature = "metadata_ext", since = "1.1.0")]
22

33
use crate::fs::Metadata;
4+
use crate::sealed::Sealed;
45
use crate::sys_common::AsInner;
56

67
#[allow(deprecated)]
@@ -10,7 +11,7 @@ use crate::os::illumos::raw;
1011
///
1112
/// [`fs::Metadata`]: crate::fs::Metadata
1213
#[stable(feature = "metadata_ext", since = "1.1.0")]
13-
pub trait MetadataExt {
14+
pub trait MetadataExt: Sealed {
1415
/// Gain a reference to the underlying `stat` structure which contains
1516
/// the raw information returned by the OS.
1617
///

library/std/src/os/ios/fs.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#![stable(feature = "metadata_ext", since = "1.1.0")]
22

33
use crate::fs::Metadata;
4+
use crate::sealed::Sealed;
45
use crate::sys_common::AsInner;
56

67
#[allow(deprecated)]
@@ -10,7 +11,7 @@ use crate::os::ios::raw;
1011
///
1112
/// [`fs::Metadata`]: crate::fs::Metadata
1213
#[stable(feature = "metadata_ext", since = "1.1.0")]
13-
pub trait MetadataExt {
14+
pub trait MetadataExt: Sealed {
1415
/// Gain a reference to the underlying `stat` structure which contains
1516
/// the raw information returned by the OS.
1617
///

library/std/src/os/linux/fs.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#![stable(feature = "metadata_ext", since = "1.1.0")]
44

55
use crate::fs::Metadata;
6+
use crate::sealed::Sealed;
67
use crate::sys_common::AsInner;
78

89
#[allow(deprecated)]
@@ -12,7 +13,7 @@ use crate::os::linux::raw;
1213
///
1314
/// [`fs::Metadata`]: crate::fs::Metadata
1415
#[stable(feature = "metadata_ext", since = "1.1.0")]
15-
pub trait MetadataExt {
16+
pub trait MetadataExt: Sealed {
1617
/// Gain a reference to the underlying `stat` structure which contains
1718
/// the raw information returned by the OS.
1819
///

library/std/src/os/macos/fs.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#![stable(feature = "metadata_ext", since = "1.1.0")]
22

33
use crate::fs::Metadata;
4+
use crate::sealed::Sealed;
45
use crate::sys_common::AsInner;
56

67
#[allow(deprecated)]
@@ -10,7 +11,7 @@ use crate::os::macos::raw;
1011
///
1112
/// [`fs::Metadata`]: crate::fs::Metadata
1213
#[stable(feature = "metadata_ext", since = "1.1.0")]
13-
pub trait MetadataExt {
14+
pub trait MetadataExt: Sealed {
1415
/// Gain a reference to the underlying `stat` structure which contains
1516
/// the raw information returned by the OS.
1617
///

library/std/src/os/netbsd/fs.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#![stable(feature = "metadata_ext", since = "1.1.0")]
22

33
use crate::fs::Metadata;
4+
use crate::sealed::Sealed;
45
use crate::sys_common::AsInner;
56

67
#[allow(deprecated)]
@@ -10,7 +11,7 @@ use crate::os::netbsd::raw;
1011
///
1112
/// [`fs::Metadata`]: crate::fs::Metadata
1213
#[stable(feature = "metadata_ext", since = "1.1.0")]
13-
pub trait MetadataExt {
14+
pub trait MetadataExt: Sealed {
1415
/// Gain a reference to the underlying `stat` structure which contains
1516
/// the raw information returned by the OS.
1617
///

library/std/src/os/openbsd/fs.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#![stable(feature = "metadata_ext", since = "1.1.0")]
22

33
use crate::fs::Metadata;
4+
use crate::sealed::Sealed;
45
use crate::sys_common::AsInner;
56

67
#[allow(deprecated)]
@@ -10,7 +11,7 @@ use crate::os::openbsd::raw;
1011
///
1112
/// [`fs::Metadata`]: crate::fs::Metadata
1213
#[stable(feature = "metadata_ext", since = "1.1.0")]
13-
pub trait MetadataExt {
14+
pub trait MetadataExt: Sealed {
1415
/// Gain a reference to the underlying `stat` structure which contains
1516
/// the raw information returned by the OS.
1617
///

library/std/src/os/redox/fs.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#![stable(feature = "metadata_ext", since = "1.1.0")]
22

33
use crate::fs::Metadata;
4+
use crate::sealed::Sealed;
45
use crate::sys_common::AsInner;
56

67
#[allow(deprecated)]
@@ -10,7 +11,7 @@ use crate::os::redox::raw;
1011
///
1112
/// [`fs::Metadata`]: crate::fs::Metadata
1213
#[stable(feature = "metadata_ext", since = "1.1.0")]
13-
pub trait MetadataExt {
14+
pub trait MetadataExt: Sealed {
1415
/// Gain a reference to the underlying `stat` structure which contains
1516
/// the raw information returned by the OS.
1617
///

library/std/src/os/solaris/fs.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#![stable(feature = "metadata_ext", since = "1.1.0")]
22

33
use crate::fs::Metadata;
4+
use crate::sealed::Sealed;
45
use crate::sys_common::AsInner;
56

67
#[allow(deprecated)]
@@ -10,7 +11,7 @@ use crate::os::solaris::raw;
1011
///
1112
/// [`fs::Metadata`]: crate::fs::Metadata
1213
#[stable(feature = "metadata_ext", since = "1.1.0")]
13-
pub trait MetadataExt {
14+
pub trait MetadataExt: Sealed {
1415
/// Gain a reference to the underlying `stat` structure which contains
1516
/// the raw information returned by the OS.
1617
///

library/std/src/os/vxworks/fs.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
#![stable(feature = "metadata_ext", since = "1.1.0")]
22

33
use crate::fs::Metadata;
4+
use crate::sealed::Sealed;
45
use crate::sys_common::AsInner;
56

67
///
78
/// [`fs::Metadata`]: crate::fs::Metadata
89
#[stable(feature = "metadata_ext", since = "1.1.0")]
9-
pub trait MetadataExt {
10+
pub trait MetadataExt: Sealed {
1011
#[stable(feature = "metadata_ext2", since = "1.8.0")]
1112
fn st_dev(&self) -> u64;
1213
#[stable(feature = "metadata_ext2", since = "1.8.0")]

library/std/src/sys/unix/ext/fs.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use crate::fs::{self, OpenOptions, Permissions};
66
use crate::io;
77
use crate::path::Path;
8+
use crate::sealed::Sealed;
89
use crate::sys;
910
use crate::sys::platform::fs::MetadataExt as UnixMetadataExt;
1011
use crate::sys_common::{AsInner, AsInnerMut, FromInner};
@@ -14,7 +15,7 @@ use io::{Read, Write};
1415

1516
/// Unix-specific extensions to [`fs::File`].
1617
#[stable(feature = "file_offset", since = "1.15.0")]
17-
pub trait FileExt {
18+
pub trait FileExt: Sealed {
1819
/// Reads a number of bytes starting from a given offset.
1920
///
2021
/// Returns the number of bytes read.
@@ -220,7 +221,7 @@ impl FileExt for fs::File {
220221

221222
/// Unix-specific extensions to [`fs::Permissions`].
222223
#[stable(feature = "fs_ext", since = "1.1.0")]
223-
pub trait PermissionsExt {
224+
pub trait PermissionsExt: Sealed {
224225
/// Returns the underlying raw `st_mode` bits that contain the standard
225226
/// Unix permissions for this file.
226227
///
@@ -297,7 +298,7 @@ impl PermissionsExt for Permissions {
297298

298299
/// Unix-specific extensions to [`fs::OpenOptions`].
299300
#[stable(feature = "fs_ext", since = "1.1.0")]
300-
pub trait OpenOptionsExt {
301+
pub trait OpenOptionsExt: Sealed {
301302
/// Sets the mode bits that a new file will be created with.
302303
///
303304
/// If a new file is created as part of an `OpenOptions::open` call then this
@@ -365,7 +366,7 @@ impl OpenOptionsExt for OpenOptions {
365366

366367
/// Unix-specific extensions to [`fs::Metadata`].
367368
#[stable(feature = "metadata_ext", since = "1.1.0")]
368-
pub trait MetadataExt {
369+
pub trait MetadataExt: Sealed {
369370
/// Returns the ID of the device containing the file.
370371
///
371372
/// # Examples
@@ -716,7 +717,7 @@ impl MetadataExt for fs::Metadata {
716717
/// Adds support for special Unix file types such as block/character devices,
717718
/// pipes, and sockets.
718719
#[stable(feature = "file_type_ext", since = "1.5.0")]
719-
pub trait FileTypeExt {
720+
pub trait FileTypeExt: Sealed {
720721
/// Returns `true` if this file type is a block device.
721722
///
722723
/// # Examples
@@ -809,7 +810,7 @@ impl FileTypeExt for fs::FileType {
809810

810811
/// Unix-specific extension methods for [`fs::DirEntry`].
811812
#[stable(feature = "dir_entry_ext", since = "1.1.0")]
812-
pub trait DirEntryExt {
813+
pub trait DirEntryExt: Sealed {
813814
/// Returns the underlying `d_ino` field in the contained `dirent`
814815
/// structure.
815816
///
@@ -860,7 +861,7 @@ pub fn symlink<P: AsRef<Path>, Q: AsRef<Path>>(original: P, link: Q) -> io::Resu
860861

861862
/// Unix-specific extensions to [`fs::DirBuilder`].
862863
#[stable(feature = "dir_builder", since = "1.6.0")]
863-
pub trait DirBuilderExt {
864+
pub trait DirBuilderExt: Sealed {
864865
/// Sets the mode to create new directories with. This option defaults to
865866
/// 0o777.
866867
///

0 commit comments

Comments
 (0)