Skip to content

Commit 3d5258f

Browse files
committed
Auto merge of #118916 - ChrisDenton:metadataext, r=<try>
Seal `MetadataExt` on all platforms The Windows flavour of [`MetadataExt`](https://doc.rust-lang.org/std/os/windows/fs/trait.MetadataExt.html) is currently unimplementable on stable because of unstable methods. Therefore anyone making a cross-platform library that implements `MetadataExt` will fail on Windows. So let's see if we can seal it for all platforms. [Last time this was tried](#81213 (comment)), sealing `MetadataExt` only caused a problem for one old version of one crate.
2 parents c3def26 + a0572b3 commit 3d5258f

File tree

27 files changed

+51
-27
lines changed

27 files changed

+51
-27
lines changed

library/std/src/fs.rs

+4
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,10 @@ pub struct File {
111111
#[derive(Clone)]
112112
pub struct Metadata(fs_imp::FileAttr);
113113

114+
/// Allows extension traits within `std`.
115+
#[unstable(feature = "sealed", issue = "none")]
116+
impl crate::sealed::Sealed for Metadata {}
117+
114118
/// Iterator over the entries in a directory.
115119
///
116120
/// This iterator is returned from the [`read_dir`] function of this module and

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@
55
#![stable(feature = "metadata_ext", since = "1.1.0")]
66

77
use crate::fs::Metadata;
8+
use crate::sealed::Sealed;
89
use crate::sys_common::AsInner;
910

1011
/// OS-specific extensions to [`fs::Metadata`].
1112
///
1213
/// [`fs::Metadata`]: crate::fs::Metadata
1314
#[stable(feature = "metadata_ext", since = "1.1.0")]
14-
pub trait MetadataExt {
15+
pub trait MetadataExt: Sealed {
1516
/// Returns the device ID on which this file resides.
1617
///
1718
/// # Examples

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

+2-1
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

+2-1
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

+2-1
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/espidf/fs.rs

+2-1
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::espidf::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
#[stable(feature = "metadata_ext", since = "1.1.0")]
1516
#[deprecated(
1617
since = "1.8.0",

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

+2-1
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

+2-1
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

+2-1
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/horizon/fs.rs

+2-1
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/hurd/fs.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@
55
#![stable(feature = "metadata_ext", since = "1.1.0")]
66

77
use crate::fs::Metadata;
8+
use crate::sealed::Sealed;
89
use crate::sys_common::AsInner;
910

1011
/// OS-specific extensions to [`fs::Metadata`].
1112
///
1213
/// [`fs::Metadata`]: crate::fs::Metadata
1314
#[stable(feature = "metadata_ext", since = "1.1.0")]
14-
pub trait MetadataExt {
15+
pub trait MetadataExt: Sealed {
1516
/// Returns the device ID on which this file resides.
1617
///
1718
/// # Examples

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

+2-1
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

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use super::raw;
1212
///
1313
/// [`fs::Metadata`]: crate::fs::Metadata
1414
#[stable(feature = "metadata_ext", since = "1.1.0")]
15-
pub trait MetadataExt {
15+
pub trait MetadataExt: Sealed {
1616
/// Gain a reference to the underlying `stat` structure which contains
1717
/// the raw information returned by the OS.
1818
///

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#![stable(feature = "metadata_ext", since = "1.1.0")]
66

77
use crate::fs::Metadata;
8+
use crate::sealed::Sealed;
89
use crate::sys_common::AsInner;
910

1011
#[allow(deprecated)]
@@ -14,7 +15,7 @@ use crate::os::l4re::raw;
1415
///
1516
/// [`fs::Metadata`]: crate::fs::Metadata
1617
#[stable(feature = "metadata_ext", since = "1.1.0")]
17-
pub trait MetadataExt {
18+
pub trait MetadataExt: Sealed {
1819
/// Gain a reference to the underlying `stat` structure which contains
1920
/// the raw information returned by the OS.
2021
///

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#![stable(feature = "metadata_ext", since = "1.1.0")]
66

77
use crate::fs::Metadata;
8+
use crate::sealed::Sealed;
89
use crate::sys_common::AsInner;
910

1011
#[allow(deprecated)]
@@ -14,7 +15,7 @@ use crate::os::linux::raw;
1415
///
1516
/// [`fs::Metadata`]: crate::fs::Metadata
1617
#[stable(feature = "metadata_ext", since = "1.1.0")]
17-
pub trait MetadataExt {
18+
pub trait MetadataExt: Sealed {
1819
/// Gain a reference to the underlying `stat` structure which contains
1920
/// the raw information returned by the OS.
2021
///

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use crate::os::macos::raw;
1212
///
1313
/// [`fs::Metadata`]: crate::fs::Metadata
1414
#[stable(feature = "metadata_ext", since = "1.1.0")]
15-
pub trait MetadataExt {
15+
pub trait MetadataExt: Sealed {
1616
/// Gain a reference to the underlying `stat` structure which contains
1717
/// the raw information returned by the OS.
1818
///

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

+2-1
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/nto/fs.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
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
#[stable(feature = "metadata_ext", since = "1.1.0")]
7-
pub trait MetadataExt {
8+
pub trait MetadataExt: Sealed {
89
#[stable(feature = "metadata_ext2", since = "1.8.0")]
910
fn st_dev(&self) -> u64;
1011
#[stable(feature = "metadata_ext2", since = "1.8.0")]

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

+2-1
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

+2-1
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

+2-1
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/unix/fs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ impl OpenOptionsExt for OpenOptions {
429429

430430
/// Unix-specific extensions to [`fs::Metadata`].
431431
#[stable(feature = "metadata_ext", since = "1.1.0")]
432-
pub trait MetadataExt {
432+
pub trait MetadataExt: Sealed {
433433
/// Returns the ID of the device containing the file.
434434
///
435435
/// # Examples

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

+2-1
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/vxworks/fs.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
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;
5-
66
///
77
/// [`fs::Metadata`]: crate::fs::Metadata
88
#[stable(feature = "metadata_ext", since = "1.1.0")]
9-
pub trait MetadataExt {
9+
pub trait MetadataExt: Sealed {
1010
#[stable(feature = "metadata_ext2", since = "1.8.0")]
1111
fn st_dev(&self) -> u64;
1212
#[stable(feature = "metadata_ext2", since = "1.8.0")]

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use crate::ffi::OsStr;
99
use crate::fs::{self, File, Metadata, OpenOptions};
1010
use crate::io::{self, IoSlice, IoSliceMut};
1111
use crate::path::{Path, PathBuf};
12+
use crate::sealed::Sealed;
1213
use crate::sys_common::{AsInner, AsInnerMut, FromInner};
1314
// Used for `File::read` on intra-doc links
1415
#[allow(unused_imports)]
@@ -410,7 +411,7 @@ impl OpenOptionsExt for OpenOptions {
410411
}
411412

412413
/// WASI-specific extensions to [`fs::Metadata`].
413-
pub trait MetadataExt {
414+
pub trait MetadataExt: Sealed {
414415
/// Returns the `st_dev` field of the internal `filestat_t`
415416
fn dev(&self) -> u64;
416417
/// Returns the `st_ino` field of the internal `filestat_t`

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use crate::os::watchos::raw;
1212
///
1313
/// [`fs::Metadata`]: crate::fs::Metadata
1414
#[stable(feature = "metadata_ext", since = "1.1.0")]
15-
pub trait MetadataExt {
15+
pub trait MetadataExt: Sealed {
1616
/// Gain a reference to the underlying `stat` structure which contains
1717
/// the raw information returned by the OS.
1818
///

0 commit comments

Comments
 (0)