Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions std/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ crate-type = ["dylib", "rlib"]

[dependencies]
alloc = { path = "../alloc", public = true }
# std no longer uses cfg-if directly, but the included copy of backtrace does.
cfg-if = { version = "1.0", features = ['rustc-dep-of-std'] }
panic_unwind = { path = "../panic_unwind", optional = true }
panic_abort = { path = "../panic_abort" }
Expand Down
2 changes: 1 addition & 1 deletion std/src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3119,7 +3119,7 @@ pub fn read_dir<P: AsRef<Path>>(path: P) -> io::Result<ReadDir> {
/// On UNIX-like systems, this function will update the permission bits
/// of the file pointed to by the symlink.
///
/// Note that this behavior can lead to privalage escalation vulnerabilities,
/// Note that this behavior can lead to privilege escalation vulnerabilities,
/// where the ability to create a symlink in one directory allows you to
/// cause the permissions of another file or directory to be modified.
///
Expand Down
7 changes: 4 additions & 3 deletions std/src/io/copy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,11 @@ where
R: Read,
W: Write,
{
cfg_if::cfg_if! {
if #[cfg(any(target_os = "linux", target_os = "android"))] {
cfg_select! {
any(target_os = "linux", target_os = "android") => {
crate::sys::kernel_copy::copy_spec(reader, writer)
} else {
}
_ => {
generic_copy(reader, writer)
}
}
Expand Down
1 change: 1 addition & 0 deletions std/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@
#![feature(bstr)]
#![feature(bstr_internals)]
#![feature(cast_maybe_uninit)]
#![feature(cfg_select)]
#![feature(char_internals)]
#![feature(clone_to_uninit)]
#![feature(const_cmp)]
Expand Down
10 changes: 6 additions & 4 deletions std/src/os/unix/net/stream.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
cfg_if::cfg_if! {
if #[cfg(any(
cfg_select! {
any(
target_os = "linux", target_os = "android",
target_os = "hurd",
target_os = "dragonfly", target_os = "freebsd",
target_os = "openbsd", target_os = "netbsd",
target_os = "solaris", target_os = "illumos",
target_os = "haiku", target_os = "nto",
target_os = "cygwin"))] {
target_os = "cygwin",
) => {
use libc::MSG_NOSIGNAL;
} else {
}
_ => {
const MSG_NOSIGNAL: core::ffi::c_int = 0x0;
}
}
Expand Down
12 changes: 6 additions & 6 deletions std/src/os/unix/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,26 @@

#![stable(feature = "rust1", since = "1.0.0")]

use cfg_if::cfg_if;

use crate::ffi::OsStr;
use crate::os::unix::io::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, OwnedFd, RawFd};
use crate::path::Path;
use crate::sealed::Sealed;
use crate::sys_common::{AsInner, AsInnerMut, FromInner, IntoInner};
use crate::{io, process, sys};

cfg_if! {
if #[cfg(any(target_os = "vxworks", target_os = "espidf", target_os = "horizon", target_os = "vita"))] {
cfg_select! {
any(target_os = "vxworks", target_os = "espidf", target_os = "horizon", target_os = "vita") => {
type UserId = u16;
type GroupId = u16;
} else if #[cfg(target_os = "nto")] {
}
target_os = "nto" => {
// Both IDs are signed, see `sys/target_nto.h` of the QNX Neutrino SDP.
// Only positive values should be used, see e.g.
// https://www.qnx.com/developers/docs/7.1/#com.qnx.doc.neutrino.lib_ref/topic/s/setuid.html
type UserId = i32;
type GroupId = i32;
} else {
}
_ => {
type UserId = u32;
type GroupId = u32;
}
Expand Down
9 changes: 4 additions & 5 deletions std/src/sync/reentrant_lock.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use cfg_if::cfg_if;

use crate::cell::UnsafeCell;
use crate::fmt;
use crate::ops::Deref;
Expand Down Expand Up @@ -87,8 +85,8 @@ pub struct ReentrantLock<T: ?Sized> {
data: T,
}

cfg_if!(
if #[cfg(target_has_atomic = "64")] {
cfg_select!(
target_has_atomic = "64" => {
use crate::sync::atomic::{Atomic, AtomicU64, Ordering::Relaxed};

struct Tid(Atomic<u64>);
Expand All @@ -110,7 +108,8 @@ cfg_if!(
self.0.store(value, Relaxed);
}
}
} else {
}
_ => {
/// Returns the address of a TLS variable. This is guaranteed to
/// be unique across all currently alive threads.
fn tls_addr() -> usize {
Expand Down
30 changes: 19 additions & 11 deletions std/src/sys/alloc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,29 +68,37 @@ unsafe fn realloc_fallback(
}
}

cfg_if::cfg_if! {
if #[cfg(any(
cfg_select! {
any(
target_family = "unix",
target_os = "wasi",
target_os = "teeos",
target_os = "trusty",
))] {
) => {
mod unix;
} else if #[cfg(target_os = "windows")] {
}
target_os = "windows" => {
mod windows;
} else if #[cfg(target_os = "hermit")] {
}
target_os = "hermit" => {
mod hermit;
} else if #[cfg(all(target_vendor = "fortanix", target_env = "sgx"))] {
}
all(target_vendor = "fortanix", target_env = "sgx") => {
mod sgx;
} else if #[cfg(target_os = "solid_asp3")] {
}
target_os = "solid_asp3" => {
mod solid;
} else if #[cfg(target_os = "uefi")] {
}
target_os = "uefi" => {
mod uefi;
} else if #[cfg(target_family = "wasm")] {
}
target_family = "wasm" => {
mod wasm;
} else if #[cfg(target_os = "xous")] {
}
target_os = "xous" => {
mod xous;
} else if #[cfg(target_os = "zkvm")] {
}
target_os = "zkvm" => {
mod zkvm;
}
}
10 changes: 4 additions & 6 deletions std/src/sys/alloc/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,16 @@ unsafe impl GlobalAlloc for System {
}
}

cfg_if::cfg_if! {
cfg_select! {
// We use posix_memalign wherever possible, but some targets have very incomplete POSIX coverage
// so we need a fallback for those.
if #[cfg(any(
target_os = "horizon",
target_os = "vita",
))] {
any(target_os = "horizon", target_os = "vita") => {
#[inline]
unsafe fn aligned_malloc(layout: &Layout) -> *mut u8 {
unsafe { libc::memalign(layout.align(), layout.size()) as *mut u8 }
}
} else {
}
_ => {
#[inline]
#[cfg_attr(target_os = "vxworks", allow(unused_unsafe))]
unsafe fn aligned_malloc(layout: &Layout) -> *mut u8 {
Expand Down
10 changes: 6 additions & 4 deletions std/src/sys/anonymous_pipe/mod.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
#![forbid(unsafe_op_in_unsafe_fn)]

cfg_if::cfg_if! {
if #[cfg(unix)] {
cfg_select! {
unix => {
mod unix;
pub use unix::{AnonPipe, pipe};
} else if #[cfg(windows)] {
}
windows => {
mod windows;
pub use windows::{AnonPipe, pipe};
} else {
}
_ => {
mod unsupported;
pub use unsupported::{AnonPipe, pipe};
}
Expand Down
27 changes: 17 additions & 10 deletions std/src/sys/args/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,39 @@
))]
mod common;

cfg_if::cfg_if! {
if #[cfg(any(
cfg_select! {
any(
all(target_family = "unix", not(any(target_os = "espidf", target_os = "vita"))),
target_os = "hermit",
))] {
) => {
mod unix;
pub use unix::*;
} else if #[cfg(target_family = "windows")] {
}
target_family = "windows" => {
mod windows;
pub use windows::*;
} else if #[cfg(all(target_vendor = "fortanix", target_env = "sgx"))] {
}
all(target_vendor = "fortanix", target_env = "sgx") => {
mod sgx;
pub use sgx::*;
} else if #[cfg(target_os = "uefi")] {
}
target_os = "uefi" => {
mod uefi;
pub use uefi::*;
} else if #[cfg(target_os = "wasi")] {
}
target_os = "wasi" => {
mod wasi;
pub use wasi::*;
} else if #[cfg(target_os = "xous")] {
}
target_os = "xous" => {
mod xous;
pub use xous::*;
} else if #[cfg(target_os = "zkvm")] {
}
target_os = "zkvm" => {
mod zkvm;
pub use zkvm::*;
} else {
}
_ => {
mod unsupported;
pub use unsupported::*;
}
Expand Down
Loading