Skip to content

Commit cfb0556

Browse files
committed
Merge Apple std::os extensions modules into std::os::darwin
The functionality available on Apple platforms are very similar, and were duplicated for each platform. Additionally, this fixes a warning when compiling the standard library for tvOS, watchOS and visionOS by marking the corresponding code as dead code.
1 parent 12ec5b7 commit cfb0556

File tree

16 files changed

+86
-797
lines changed

16 files changed

+86
-797
lines changed

std/src/fs/tests.rs

+3-20
Original file line numberDiff line numberDiff line change
@@ -1638,16 +1638,8 @@ fn rename_directory() {
16381638

16391639
#[test]
16401640
fn test_file_times() {
1641-
#[cfg(target_os = "ios")]
1642-
use crate::os::ios::fs::FileTimesExt;
1643-
#[cfg(target_os = "macos")]
1644-
use crate::os::macos::fs::FileTimesExt;
1645-
#[cfg(target_os = "tvos")]
1646-
use crate::os::tvos::fs::FileTimesExt;
1647-
#[cfg(target_os = "visionos")]
1648-
use crate::os::visionos::fs::FileTimesExt;
1649-
#[cfg(target_os = "watchos")]
1650-
use crate::os::watchos::fs::FileTimesExt;
1641+
#[cfg(target_vendor = "apple")]
1642+
use crate::os::darwin::fs::FileTimesExt;
16511643
#[cfg(windows)]
16521644
use crate::os::windows::fs::FileTimesExt;
16531645

@@ -1693,16 +1685,7 @@ fn test_file_times() {
16931685
#[test]
16941686
#[cfg(target_vendor = "apple")]
16951687
fn test_file_times_pre_epoch_with_nanos() {
1696-
#[cfg(target_os = "ios")]
1697-
use crate::os::ios::fs::FileTimesExt;
1698-
#[cfg(target_os = "macos")]
1699-
use crate::os::macos::fs::FileTimesExt;
1700-
#[cfg(target_os = "tvos")]
1701-
use crate::os::tvos::fs::FileTimesExt;
1702-
#[cfg(target_os = "visionos")]
1703-
use crate::os::visionos::fs::FileTimesExt;
1704-
#[cfg(target_os = "watchos")]
1705-
use crate::os::watchos::fs::FileTimesExt;
1688+
use crate::os::darwin::fs::FileTimesExt;
17061689

17071690
let tmp = tmpdir();
17081691
let file = File::create(tmp.join("foo")).unwrap();

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

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
#![stable(feature = "metadata_ext", since = "1.1.0")]
1+
#![allow(dead_code)]
22

33
use crate::fs::{self, Metadata};
44
use crate::sealed::Sealed;
55
use crate::sys_common::{AsInner, AsInnerMut, IntoInner};
66
use crate::time::SystemTime;
77

88
#[allow(deprecated)]
9-
use crate::os::macos::raw;
9+
use super::raw;
1010

1111
/// OS-specific extensions to [`fs::Metadata`].
1212
///
@@ -70,6 +70,7 @@ pub trait MetadataExt {
7070
fn st_gen(&self) -> u32;
7171
#[stable(feature = "metadata_ext2", since = "1.8.0")]
7272
fn st_lspare(&self) -> u32;
73+
#[cfg(target_os = "macos")]
7374
#[stable(feature = "metadata_ext2", since = "1.8.0")]
7475
fn st_qspare(&self) -> [u64; 2];
7576
}
@@ -143,6 +144,7 @@ impl MetadataExt for Metadata {
143144
fn st_lspare(&self) -> u32 {
144145
self.as_inner().as_inner().st_lspare as u32
145146
}
147+
#[cfg(target_os = "macos")]
146148
fn st_qspare(&self) -> [u64; 2] {
147149
let qspare = self.as_inner().as_inner().st_qspare;
148150
[qspare[0] as u64, qspare[1] as u64]

std/src/os/darwin/mod.rs

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//! Platform-specific extensions to `std` for Darwin / Apple platforms.
2+
//!
3+
//! This is available on the following operating systems:
4+
//! - macOS
5+
//! - iOS
6+
//! - tvOS
7+
//! - watchOS
8+
//! - visionOS
9+
//!
10+
//! Note: This module is called "Darwin" as that's the name of the underlying
11+
//! core OS of the above operating systems, but it should not be confused with
12+
//! the `-darwin` suffix in the `x86_64-apple-darwin` and
13+
//! `aarch64-apple-darwin` target names, which are mostly named that way for
14+
//! legacy reasons.
15+
16+
pub(crate) mod fs;
17+
// deprecated, but used for public reexport under `std::os::unix::raw`, as
18+
// well as `std::os::macos`/`std::os::ios`, because those modules precede the
19+
// decision to remove these.
20+
pub(super) mod raw;

std/src/os/ios/raw.rs std/src/os/darwin/raw.rs

+2-12
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,4 @@
1-
//! iOS-specific raw type definitions
2-
3-
#![stable(feature = "raw_ext", since = "1.1.0")]
4-
#![deprecated(
5-
since = "1.8.0",
6-
note = "these type aliases are no longer supported by \
7-
the standard library, the `libc` crate on \
8-
crates.io should be used instead for the correct \
9-
definitions"
10-
)]
11-
#![allow(deprecated)]
12-
1+
//! Apple-specific raw type definitions
132
use crate::os::raw::c_long;
143

154
#[stable(feature = "raw_ext", since = "1.1.0")]
@@ -35,6 +24,7 @@ pub type pthread_t = usize;
3524
#[repr(C)]
3625
#[derive(Clone)]
3726
#[stable(feature = "raw_ext", since = "1.1.0")]
27+
#[allow(dead_code)]
3828
pub struct stat {
3929
#[stable(feature = "raw_ext", since = "1.1.0")]
4030
pub st_dev: i32,

std/src/os/ios/fs.rs

-160
This file was deleted.

std/src/os/ios/mod.rs

+26-2
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,29 @@
22
33
#![stable(feature = "raw_ext", since = "1.1.0")]
44

5-
pub mod fs;
6-
pub mod raw;
5+
#[stable(feature = "metadata_ext", since = "1.1.0")]
6+
pub mod fs {
7+
#[doc(inline)]
8+
#[stable(feature = "file_set_times", since = "1.75.0")]
9+
pub use crate::os::darwin::fs::FileTimesExt;
10+
11+
#[doc(inline)]
12+
#[stable(feature = "metadata_ext", since = "1.1.0")]
13+
pub use crate::os::darwin::fs::MetadataExt;
14+
}
15+
16+
/// iOS-specific raw type definitions
17+
#[stable(feature = "raw_ext", since = "1.1.0")]
18+
#[deprecated(
19+
since = "1.8.0",
20+
note = "these type aliases are no longer supported by \
21+
the standard library, the `libc` crate on \
22+
crates.io should be used instead for the correct \
23+
definitions"
24+
)]
25+
#[allow(deprecated)]
26+
pub mod raw {
27+
#[doc(inline)]
28+
#[stable(feature = "raw_ext", since = "1.1.0")]
29+
pub use crate::os::darwin::raw::*;
30+
}

std/src/os/macos/mod.rs

+26-2
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,29 @@
22
33
#![stable(feature = "raw_ext", since = "1.1.0")]
44

5-
pub mod fs;
6-
pub mod raw;
5+
#[stable(feature = "metadata_ext", since = "1.1.0")]
6+
pub mod fs {
7+
#[doc(inline)]
8+
#[stable(feature = "file_set_times", since = "1.75.0")]
9+
pub use crate::os::darwin::fs::FileTimesExt;
10+
11+
#[doc(inline)]
12+
#[stable(feature = "metadata_ext", since = "1.1.0")]
13+
pub use crate::os::darwin::fs::MetadataExt;
14+
}
15+
16+
/// macOS-specific raw type definitions
17+
#[stable(feature = "raw_ext", since = "1.1.0")]
18+
#[deprecated(
19+
since = "1.8.0",
20+
note = "these type aliases are no longer supported by \
21+
the standard library, the `libc` crate on \
22+
crates.io should be used instead for the correct \
23+
definitions"
24+
)]
25+
#[allow(deprecated)]
26+
pub mod raw {
27+
#[doc(inline)]
28+
#[stable(feature = "raw_ext", since = "1.1.0")]
29+
pub use crate::os::darwin::raw::*;
30+
}

0 commit comments

Comments
 (0)