Skip to content

Commit

Permalink
Auto merge of rust-lang#118916 - ChrisDenton:metadataext, r=<try>
Browse files Browse the repository at this point in the history
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](rust-lang#81213 (comment)), sealing `MetadataExt` only caused a problem for one old version of one crate.
  • Loading branch information
bors committed Dec 13, 2023
2 parents c3def26 + a0572b3 commit 3d5258f
Show file tree
Hide file tree
Showing 27 changed files with 51 additions and 27 deletions.
4 changes: 4 additions & 0 deletions library/std/src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,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
Expand Down
3 changes: 2 additions & 1 deletion library/std/src/os/aix/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,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 {
/// Returns the device ID on which this file resides.
///
/// # Examples
Expand Down
3 changes: 2 additions & 1 deletion library/std/src/os/android/fs.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand All @@ -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.
///
Expand Down
3 changes: 2 additions & 1 deletion library/std/src/os/dragonfly/fs.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand All @@ -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.
///
Expand Down
3 changes: 2 additions & 1 deletion library/std/src/os/emscripten/fs.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand All @@ -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.
///
Expand Down
3 changes: 2 additions & 1 deletion library/std/src/os/espidf/fs.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand All @@ -10,7 +11,7 @@ use crate::os::espidf::raw;
///
/// [`fs::Metadata`]: crate::fs::Metadata
#[stable(feature = "metadata_ext", since = "1.1.0")]
pub trait MetadataExt {
pub trait MetadataExt: Sealed {
#[stable(feature = "metadata_ext", since = "1.1.0")]
#[deprecated(
since = "1.8.0",
Expand Down
3 changes: 2 additions & 1 deletion library/std/src/os/freebsd/fs.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand All @@ -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.
///
Expand Down
3 changes: 2 additions & 1 deletion library/std/src/os/fuchsia/fs.rs
Original file line number Diff line number Diff line change
@@ -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")]
Expand Down
3 changes: 2 additions & 1 deletion library/std/src/os/haiku/fs.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand All @@ -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.
///
Expand Down
3 changes: 2 additions & 1 deletion library/std/src/os/horizon/fs.rs
Original file line number Diff line number Diff line change
@@ -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")]
Expand Down
3 changes: 2 additions & 1 deletion library/std/src/os/hurd/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,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 {
/// Returns the device ID on which this file resides.
///
/// # Examples
Expand Down
3 changes: 2 additions & 1 deletion library/std/src/os/illumos/fs.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand All @@ -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.
///
Expand Down
2 changes: 1 addition & 1 deletion library/std/src/os/ios/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use super::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.
///
Expand Down
3 changes: 2 additions & 1 deletion library/std/src/os/l4re/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#![stable(feature = "metadata_ext", since = "1.1.0")]

use crate::fs::Metadata;
use crate::sealed::Sealed;
use crate::sys_common::AsInner;

#[allow(deprecated)]
Expand All @@ -14,7 +15,7 @@ use crate::os::l4re::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.
///
Expand Down
3 changes: 2 additions & 1 deletion library/std/src/os/linux/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#![stable(feature = "metadata_ext", since = "1.1.0")]

use crate::fs::Metadata;
use crate::sealed::Sealed;
use crate::sys_common::AsInner;

#[allow(deprecated)]
Expand All @@ -14,7 +15,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.
///
Expand Down
2 changes: 1 addition & 1 deletion library/std/src/os/macos/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,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.
///
Expand Down
3 changes: 2 additions & 1 deletion library/std/src/os/netbsd/fs.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand All @@ -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.
///
Expand Down
3 changes: 2 additions & 1 deletion library/std/src/os/nto/fs.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#![stable(feature = "metadata_ext", since = "1.1.0")]

use crate::fs::Metadata;
use crate::sealed::Sealed;
use crate::sys_common::AsInner;

#[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")]
Expand Down
3 changes: 2 additions & 1 deletion library/std/src/os/openbsd/fs.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand All @@ -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.
///
Expand Down
3 changes: 2 additions & 1 deletion library/std/src/os/redox/fs.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand All @@ -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.
///
Expand Down
3 changes: 2 additions & 1 deletion library/std/src/os/solaris/fs.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand All @@ -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.
///
Expand Down
2 changes: 1 addition & 1 deletion library/std/src/os/unix/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,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
Expand Down
3 changes: 2 additions & 1 deletion library/std/src/os/vita/fs.rs
Original file line number Diff line number Diff line change
@@ -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")]
Expand Down
4 changes: 2 additions & 2 deletions library/std/src/os/vxworks/fs.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#![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")]
Expand Down
3 changes: 2 additions & 1 deletion library/std/src/os/wasi/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use crate::ffi::OsStr;
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_common::{AsInner, AsInnerMut, FromInner};
// Used for `File::read` on intra-doc links
#[allow(unused_imports)]
Expand Down Expand Up @@ -410,7 +411,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`
Expand Down
2 changes: 1 addition & 1 deletion library/std/src/os/watchos/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::os::watchos::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.
///
Expand Down
Loading

0 comments on commit 3d5258f

Please sign in to comment.