summary refs log tree commit diff
path: root/library/std/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2025-04-21 19:28:16 +0000
committerbors <bors@rust-lang.org>2025-04-21 19:28:16 +0000
commitd6c1e454aa8af5e7e59fbf5c4e7d3128d2f99582 (patch)
treee12c3de53a1d961026e0de6bd56a3662aa88723e /library/std/src
parent8f2819b0e3428d0aee05fa60e91e0211c2aea053 (diff)
parent1cb9a0d450c935cda211bb970446d7e8cf504311 (diff)
downloadrust-d6c1e454aa8af5e7e59fbf5c4e7d3128d2f99582.tar.gz
rust-d6c1e454aa8af5e7e59fbf5c4e7d3128d2f99582.zip
Auto merge of #140127 - ChrisDenton:rollup-2kye32h, r=ChrisDenton
Rollup of 11 pull requests

Successful merges:

 - #134213 (Stabilize `naked_functions`)
 - #139711 (Hermit: Unify `std::env::args` with Unix)
 - #139795 (Clarify why SGX code specifies linkage/symbol names for certain statics)
 - #140036 (Advent of `tests/ui` (misc cleanups and improvements) [4/N])
 - #140047 (remove a couple clones)
 - #140052 (Fix error when an intra doc link is trying to resolve an empty associated item)
 - #140074 (rustdoc-json: Improve test for auto-trait impls)
 - #140076 (jsondocck: Require command is at start of line)
 - #140107 (rustc-dev-guide subtree update)
 - #140111 (cleanup redundant pattern instances)
 - #140118 ({B,C}Str: minor cleanup)

r? `@ghost`
`@rustbot` modify labels: rollup
Diffstat (limited to 'library/std/src')
-rw-r--r--library/std/src/path.rs2
-rw-r--r--library/std/src/sys/alloc/sgx.rs4
-rw-r--r--library/std/src/sys/args/hermit.rs35
-rw-r--r--library/std/src/sys/args/mod.rs8
-rw-r--r--library/std/src/sys/args/sgx.rs1
-rw-r--r--library/std/src/sys/args/unix.rs6
-rw-r--r--library/std/src/sys/pal/sgx/abi/tls/mod.rs6
-rw-r--r--library/std/src/sys/pal/sgx/os.rs6
-rw-r--r--library/std/src/sys/pal/sgx/thread.rs3
9 files changed, 24 insertions, 47 deletions
diff --git a/library/std/src/path.rs b/library/std/src/path.rs
index 980213be7ea..50f403ba411 100644
--- a/library/std/src/path.rs
+++ b/library/std/src/path.rs
@@ -3265,7 +3265,7 @@ impl Hash for Path {
                 if !verbatim {
                     component_start += match tail {
                         [b'.'] => 1,
-                        [b'.', sep @ _, ..] if is_sep_byte(*sep) => 1,
+                        [b'.', sep, ..] if is_sep_byte(*sep) => 1,
                         _ => 0,
                     };
                 }
diff --git a/library/std/src/sys/alloc/sgx.rs b/library/std/src/sys/alloc/sgx.rs
index f5c27688fbc..7a846e2376b 100644
--- a/library/std/src/sys/alloc/sgx.rs
+++ b/library/std/src/sys/alloc/sgx.rs
@@ -10,8 +10,10 @@ use crate::sys::pal::waitqueue::SpinMutex;
 // The current allocator here is the `dlmalloc` crate which we've got included
 // in the rust-lang/rust repository as a submodule. The crate is a port of
 // dlmalloc.c from C to Rust.
+//
+// Specifying linkage/symbol name is solely to ensure a single instance between this crate and its unit tests
 #[cfg_attr(test, linkage = "available_externally")]
-#[unsafe(export_name = "_ZN16__rust_internals3std3sys3sgx5alloc8DLMALLOCE")]
+#[unsafe(export_name = "_ZN16__rust_internals3std3sys5alloc3sgx8DLMALLOCE")]
 static DLMALLOC: SpinMutex<dlmalloc::Dlmalloc<Sgx>> =
     SpinMutex::new(dlmalloc::Dlmalloc::new_with_allocator(Sgx {}));
 
diff --git a/library/std/src/sys/args/hermit.rs b/library/std/src/sys/args/hermit.rs
deleted file mode 100644
index ddd644a5540..00000000000
--- a/library/std/src/sys/args/hermit.rs
+++ /dev/null
@@ -1,35 +0,0 @@
-use crate::ffi::{CStr, OsString, c_char};
-use crate::os::hermit::ffi::OsStringExt;
-use crate::ptr;
-use crate::sync::atomic::Ordering::{Acquire, Relaxed, Release};
-use crate::sync::atomic::{AtomicIsize, AtomicPtr};
-
-#[path = "common.rs"]
-mod common;
-pub use common::Args;
-
-static ARGC: AtomicIsize = AtomicIsize::new(0);
-static ARGV: AtomicPtr<*const u8> = AtomicPtr::new(ptr::null_mut());
-
-/// One-time global initialization.
-pub unsafe fn init(argc: isize, argv: *const *const u8) {
-    ARGC.store(argc, Relaxed);
-    // Use release ordering here to broadcast writes by the OS.
-    ARGV.store(argv as *mut *const u8, Release);
-}
-
-/// Returns the command line arguments
-pub fn args() -> Args {
-    // Synchronize with the store above.
-    let argv = ARGV.load(Acquire);
-    // If argv has not been initialized yet, do not return any arguments.
-    let argc = if argv.is_null() { 0 } else { ARGC.load(Relaxed) };
-    let args: Vec<OsString> = (0..argc)
-        .map(|i| unsafe {
-            let cstr = CStr::from_ptr(*argv.offset(i) as *const c_char);
-            OsStringExt::from_vec(cstr.to_bytes().to_vec())
-        })
-        .collect();
-
-    Args::new(args)
-}
diff --git a/library/std/src/sys/args/mod.rs b/library/std/src/sys/args/mod.rs
index f24d6eb123e..6a37b32d229 100644
--- a/library/std/src/sys/args/mod.rs
+++ b/library/std/src/sys/args/mod.rs
@@ -3,15 +3,15 @@
 #![forbid(unsafe_op_in_unsafe_fn)]
 
 cfg_if::cfg_if! {
-    if #[cfg(all(target_family = "unix", not(any(target_os = "espidf", target_os = "vita"))))] {
+    if #[cfg(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")] {
         mod windows;
         pub use windows::*;
-    } else if #[cfg(target_os = "hermit")] {
-        mod hermit;
-        pub use hermit::*;
     } else if #[cfg(all(target_vendor = "fortanix", target_env = "sgx"))] {
         mod sgx;
         pub use sgx::*;
diff --git a/library/std/src/sys/args/sgx.rs b/library/std/src/sys/args/sgx.rs
index efc4b791852..0185a8a6000 100644
--- a/library/std/src/sys/args/sgx.rs
+++ b/library/std/src/sys/args/sgx.rs
@@ -8,6 +8,7 @@ use crate::sys::pal::abi::usercalls::raw::ByteBuffer;
 use crate::sys_common::FromInner;
 use crate::{fmt, slice};
 
+// Specifying linkage/symbol name is solely to ensure a single instance between this crate and its unit tests
 #[cfg_attr(test, linkage = "available_externally")]
 #[unsafe(export_name = "_ZN16__rust_internals3std3sys3sgx4args4ARGSE")]
 static ARGS: AtomicUsize = AtomicUsize::new(0);
diff --git a/library/std/src/sys/args/unix.rs b/library/std/src/sys/args/unix.rs
index 7d7815c6dff..c087fd62965 100644
--- a/library/std/src/sys/args/unix.rs
+++ b/library/std/src/sys/args/unix.rs
@@ -6,6 +6,9 @@
 #![allow(dead_code)] // runtime init functions not used during testing
 
 use crate::ffi::CStr;
+#[cfg(target_os = "hermit")]
+use crate::os::hermit::ffi::OsStringExt;
+#[cfg(not(target_os = "hermit"))]
 use crate::os::unix::ffi::OsStringExt;
 
 #[path = "common.rs"]
@@ -73,6 +76,7 @@ pub fn args() -> Args {
     target_os = "illumos",
     target_os = "emscripten",
     target_os = "haiku",
+    target_os = "hermit",
     target_os = "l4re",
     target_os = "fuchsia",
     target_os = "redox",
@@ -100,7 +104,7 @@ mod imp {
 
     unsafe fn really_init(argc: isize, argv: *const *const u8) {
         // These don't need to be ordered with each other or other stores,
-        // because they only hold the unmodified system-provide argv/argc.
+        // because they only hold the unmodified system-provided argv/argc.
         ARGC.store(argc, Ordering::Relaxed);
         ARGV.store(argv as *mut _, Ordering::Relaxed);
     }
diff --git a/library/std/src/sys/pal/sgx/abi/tls/mod.rs b/library/std/src/sys/pal/sgx/abi/tls/mod.rs
index 8e2b271f1c9..f082d94614b 100644
--- a/library/std/src/sys/pal/sgx/abi/tls/mod.rs
+++ b/library/std/src/sys/pal/sgx/abi/tls/mod.rs
@@ -11,15 +11,17 @@ const USIZE_BITS: usize = 64;
 const TLS_KEYS: usize = 128; // Same as POSIX minimum
 const TLS_KEYS_BITSET_SIZE: usize = (TLS_KEYS + (USIZE_BITS - 1)) / USIZE_BITS;
 
+// Specifying linkage/symbol name is solely to ensure a single instance between this crate and its unit tests
 #[cfg_attr(test, linkage = "available_externally")]
-#[unsafe(export_name = "_ZN16__rust_internals3std3sys3sgx3abi3tls14TLS_KEY_IN_USEE")]
+#[unsafe(export_name = "_ZN16__rust_internals3std3sys3pal3sgx3abi3tls14TLS_KEY_IN_USEE")]
 static TLS_KEY_IN_USE: SyncBitset = SYNC_BITSET_INIT;
 macro_rules! dup {
     ((* $($exp:tt)*) $($val:tt)*) => (dup!( ($($exp)*) $($val)* $($val)* ));
     (() $($val:tt)*) => ([$($val),*])
 }
+// Specifying linkage/symbol name is solely to ensure a single instance between this crate and its unit tests
 #[cfg_attr(test, linkage = "available_externally")]
-#[unsafe(export_name = "_ZN16__rust_internals3std3sys3sgx3abi3tls14TLS_DESTRUCTORE")]
+#[unsafe(export_name = "_ZN16__rust_internals3std3sys3pal3sgx3abi3tls14TLS_DESTRUCTORE")]
 static TLS_DESTRUCTOR: [AtomicUsize; TLS_KEYS] = dup!((* * * * * * *) (AtomicUsize::new(0)));
 
 unsafe extern "C" {
diff --git a/library/std/src/sys/pal/sgx/os.rs b/library/std/src/sys/pal/sgx/os.rs
index b1ec2afd764..010634cf310 100644
--- a/library/std/src/sys/pal/sgx/os.rs
+++ b/library/std/src/sys/pal/sgx/os.rs
@@ -73,11 +73,13 @@ pub fn current_exe() -> io::Result<PathBuf> {
     unsupported()
 }
 
+// Specifying linkage/symbol name is solely to ensure a single instance between this crate and its unit tests
 #[cfg_attr(test, linkage = "available_externally")]
-#[unsafe(export_name = "_ZN16__rust_internals3std3sys3sgx2os3ENVE")]
+#[unsafe(export_name = "_ZN16__rust_internals3std3sys3pal3sgx2os3ENVE")]
 static ENV: AtomicUsize = AtomicUsize::new(0);
+// Specifying linkage/symbol name is solely to ensure a single instance between this crate and its unit tests
 #[cfg_attr(test, linkage = "available_externally")]
-#[unsafe(export_name = "_ZN16__rust_internals3std3sys3sgx2os8ENV_INITE")]
+#[unsafe(export_name = "_ZN16__rust_internals3std3sys3pal3sgx2os8ENV_INITE")]
 static ENV_INIT: Once = Once::new();
 type EnvStore = Mutex<HashMap<OsString, OsString>>;
 
diff --git a/library/std/src/sys/pal/sgx/thread.rs b/library/std/src/sys/pal/sgx/thread.rs
index b6932df431f..219ef1b7a98 100644
--- a/library/std/src/sys/pal/sgx/thread.rs
+++ b/library/std/src/sys/pal/sgx/thread.rs
@@ -45,8 +45,9 @@ mod task_queue {
         }
     }
 
+    // Specifying linkage/symbol name is solely to ensure a single instance between this crate and its unit tests
     #[cfg_attr(test, linkage = "available_externally")]
-    #[unsafe(export_name = "_ZN16__rust_internals3std3sys3sgx6thread10TASK_QUEUEE")]
+    #[unsafe(export_name = "_ZN16__rust_internals3std3sys3pal3sgx6thread10TASK_QUEUEE")]
     static TASK_QUEUE: Mutex<Vec<Task>> = Mutex::new(Vec::new());
 
     pub(super) fn lock() -> MutexGuard<'static, Vec<Task>> {