Skip to content

Commit 98e2a42

Browse files
committed
Auto merge of rust-lang#140127 - ChrisDenton:rollup-2kye32h, r=ChrisDenton
Rollup of 11 pull requests Successful merges: - rust-lang#134213 (Stabilize `naked_functions`) - rust-lang#139711 (Hermit: Unify `std::env::args` with Unix) - rust-lang#139795 (Clarify why SGX code specifies linkage/symbol names for certain statics) - rust-lang#140036 (Advent of `tests/ui` (misc cleanups and improvements) [4/N]) - rust-lang#140047 (remove a couple clones) - rust-lang#140052 (Fix error when an intra doc link is trying to resolve an empty associated item) - rust-lang#140074 (rustdoc-json: Improve test for auto-trait impls) - rust-lang#140076 (jsondocck: Require command is at start of line) - rust-lang#140107 (rustc-dev-guide subtree update) - rust-lang#140111 (cleanup redundant pattern instances) - rust-lang#140118 ({B,C}Str: minor cleanup) r? `@ghost` `@rustbot` modify labels: rollup
2 parents e4a3c15 + 9be04dc commit 98e2a42

File tree

15 files changed

+35
-60
lines changed

15 files changed

+35
-60
lines changed

alloc/src/ffi/c_str.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ impl CString {
574574
#[stable(feature = "as_c_str", since = "1.20.0")]
575575
#[rustc_diagnostic_item = "cstring_as_c_str"]
576576
pub fn as_c_str(&self) -> &CStr {
577-
&*self
577+
unsafe { CStr::from_bytes_with_nul_unchecked(self.as_bytes_with_nul()) }
578578
}
579579

580580
/// Converts this `CString` into a boxed [`CStr`].
@@ -705,14 +705,14 @@ impl ops::Deref for CString {
705705

706706
#[inline]
707707
fn deref(&self) -> &CStr {
708-
unsafe { CStr::from_bytes_with_nul_unchecked(self.as_bytes_with_nul()) }
708+
self.as_c_str()
709709
}
710710
}
711711

712712
#[stable(feature = "rust1", since = "1.0.0")]
713713
impl fmt::Debug for CString {
714714
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
715-
fmt::Debug::fmt(&**self, f)
715+
fmt::Debug::fmt(self.as_c_str(), f)
716716
}
717717
}
718718

alloctests/tests/c_str2.rs

-6
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,6 @@ fn build_with_zero2() {
3333
assert!(CString::new(vec![0]).is_err());
3434
}
3535

36-
#[test]
37-
fn formatted() {
38-
let s = CString::new(&b"abc\x01\x02\n\xE2\x80\xA6\xFF"[..]).unwrap();
39-
assert_eq!(format!("{s:?}"), r#""abc\x01\x02\n\xe2\x80\xa6\xff""#);
40-
}
41-
4236
#[test]
4337
fn borrowed() {
4438
unsafe {

core/src/arch.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ pub macro asm("assembly template", $(operands,)* $(options($(option),*))?) {
3232
///
3333
/// [Rust By Example]: https://doc.rust-lang.org/nightly/rust-by-example/unsafe/asm.html
3434
/// [reference]: https://doc.rust-lang.org/nightly/reference/inline-assembly.html
35-
#[unstable(feature = "naked_functions", issue = "90957")]
35+
#[stable(feature = "naked_functions", since = "CURRENT_RUSTC_VERSION")]
3636
#[rustc_builtin_macro]
3737
pub macro naked_asm("assembly template", $(operands,)* $(options($(option),*))?) {
3838
/* compiler built-in */

core/src/bstr/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ use crate::ops::{Deref, DerefMut, DerefPure};
3636
/// presented as hex escape sequences.
3737
///
3838
/// The `Display` implementation behaves as if the `ByteStr` were first lossily converted to a
39-
/// `str`, with invalid UTF-8 presented as the Unicode replacement character: �
40-
///
39+
/// `str`, with invalid UTF-8 presented as the Unicode replacement character (�).
4140
#[unstable(feature = "bstr", issue = "134915")]
4241
#[repr(transparent)]
4342
#[doc(alias = "BStr")]

core/src/ffi/c_str.rs

-1
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,6 @@ impl Error for FromBytesWithNulError {
150150
/// within the slice.
151151
///
152152
/// This error is created by the [`CStr::from_bytes_until_nul`] method.
153-
///
154153
#[derive(Clone, PartialEq, Eq, Debug)]
155154
#[stable(feature = "cstr_from_bytes_until_nul", since = "1.69.0")]
156155
pub struct FromBytesUntilNulError(());

coretests/tests/ffi/cstr.rs

+6
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,9 @@ fn compares_as_u8s() {
1313
assert_eq!(Ord::cmp(a, b), Ord::cmp(a_bytes, b_bytes));
1414
assert_eq!(PartialOrd::partial_cmp(a, b), PartialOrd::partial_cmp(a_bytes, b_bytes));
1515
}
16+
17+
#[test]
18+
fn debug() {
19+
let s = c"abc\x01\x02\n\xE2\x80\xA6\xFF";
20+
assert_eq!(format!("{s:?}"), r#""abc\x01\x02\n\xe2\x80\xa6\xff""#);
21+
}

std/src/path.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3265,7 +3265,7 @@ impl Hash for Path {
32653265
if !verbatim {
32663266
component_start += match tail {
32673267
[b'.'] => 1,
3268-
[b'.', sep @ _, ..] if is_sep_byte(*sep) => 1,
3268+
[b'.', sep, ..] if is_sep_byte(*sep) => 1,
32693269
_ => 0,
32703270
};
32713271
}

std/src/sys/alloc/sgx.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ use crate::sys::pal::waitqueue::SpinMutex;
1010
// The current allocator here is the `dlmalloc` crate which we've got included
1111
// in the rust-lang/rust repository as a submodule. The crate is a port of
1212
// dlmalloc.c from C to Rust.
13+
//
14+
// Specifying linkage/symbol name is solely to ensure a single instance between this crate and its unit tests
1315
#[cfg_attr(test, linkage = "available_externally")]
14-
#[unsafe(export_name = "_ZN16__rust_internals3std3sys3sgx5alloc8DLMALLOCE")]
16+
#[unsafe(export_name = "_ZN16__rust_internals3std3sys5alloc3sgx8DLMALLOCE")]
1517
static DLMALLOC: SpinMutex<dlmalloc::Dlmalloc<Sgx>> =
1618
SpinMutex::new(dlmalloc::Dlmalloc::new_with_allocator(Sgx {}));
1719

std/src/sys/args/hermit.rs

-35
This file was deleted.

std/src/sys/args/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
#![forbid(unsafe_op_in_unsafe_fn)]
44

55
cfg_if::cfg_if! {
6-
if #[cfg(all(target_family = "unix", not(any(target_os = "espidf", target_os = "vita"))))] {
6+
if #[cfg(any(
7+
all(target_family = "unix", not(any(target_os = "espidf", target_os = "vita"))),
8+
target_os = "hermit",
9+
))] {
710
mod unix;
811
pub use unix::*;
912
} else if #[cfg(target_family = "windows")] {
1013
mod windows;
1114
pub use windows::*;
12-
} else if #[cfg(target_os = "hermit")] {
13-
mod hermit;
14-
pub use hermit::*;
1515
} else if #[cfg(all(target_vendor = "fortanix", target_env = "sgx"))] {
1616
mod sgx;
1717
pub use sgx::*;

std/src/sys/args/sgx.rs

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use crate::sys::pal::abi::usercalls::raw::ByteBuffer;
88
use crate::sys_common::FromInner;
99
use crate::{fmt, slice};
1010

11+
// Specifying linkage/symbol name is solely to ensure a single instance between this crate and its unit tests
1112
#[cfg_attr(test, linkage = "available_externally")]
1213
#[unsafe(export_name = "_ZN16__rust_internals3std3sys3sgx4args4ARGSE")]
1314
static ARGS: AtomicUsize = AtomicUsize::new(0);

std/src/sys/args/unix.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
#![allow(dead_code)] // runtime init functions not used during testing
77

88
use crate::ffi::CStr;
9+
#[cfg(target_os = "hermit")]
10+
use crate::os::hermit::ffi::OsStringExt;
11+
#[cfg(not(target_os = "hermit"))]
912
use crate::os::unix::ffi::OsStringExt;
1013

1114
#[path = "common.rs"]
@@ -73,6 +76,7 @@ pub fn args() -> Args {
7376
target_os = "illumos",
7477
target_os = "emscripten",
7578
target_os = "haiku",
79+
target_os = "hermit",
7680
target_os = "l4re",
7781
target_os = "fuchsia",
7882
target_os = "redox",
@@ -100,7 +104,7 @@ mod imp {
100104

101105
unsafe fn really_init(argc: isize, argv: *const *const u8) {
102106
// These don't need to be ordered with each other or other stores,
103-
// because they only hold the unmodified system-provide argv/argc.
107+
// because they only hold the unmodified system-provided argv/argc.
104108
ARGC.store(argc, Ordering::Relaxed);
105109
ARGV.store(argv as *mut _, Ordering::Relaxed);
106110
}

std/src/sys/pal/sgx/abi/tls/mod.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,17 @@ const USIZE_BITS: usize = 64;
1111
const TLS_KEYS: usize = 128; // Same as POSIX minimum
1212
const TLS_KEYS_BITSET_SIZE: usize = (TLS_KEYS + (USIZE_BITS - 1)) / USIZE_BITS;
1313

14+
// Specifying linkage/symbol name is solely to ensure a single instance between this crate and its unit tests
1415
#[cfg_attr(test, linkage = "available_externally")]
15-
#[unsafe(export_name = "_ZN16__rust_internals3std3sys3sgx3abi3tls14TLS_KEY_IN_USEE")]
16+
#[unsafe(export_name = "_ZN16__rust_internals3std3sys3pal3sgx3abi3tls14TLS_KEY_IN_USEE")]
1617
static TLS_KEY_IN_USE: SyncBitset = SYNC_BITSET_INIT;
1718
macro_rules! dup {
1819
((* $($exp:tt)*) $($val:tt)*) => (dup!( ($($exp)*) $($val)* $($val)* ));
1920
(() $($val:tt)*) => ([$($val),*])
2021
}
22+
// Specifying linkage/symbol name is solely to ensure a single instance between this crate and its unit tests
2123
#[cfg_attr(test, linkage = "available_externally")]
22-
#[unsafe(export_name = "_ZN16__rust_internals3std3sys3sgx3abi3tls14TLS_DESTRUCTORE")]
24+
#[unsafe(export_name = "_ZN16__rust_internals3std3sys3pal3sgx3abi3tls14TLS_DESTRUCTORE")]
2325
static TLS_DESTRUCTOR: [AtomicUsize; TLS_KEYS] = dup!((* * * * * * *) (AtomicUsize::new(0)));
2426

2527
unsafe extern "C" {

std/src/sys/pal/sgx/os.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,13 @@ pub fn current_exe() -> io::Result<PathBuf> {
7373
unsupported()
7474
}
7575

76+
// Specifying linkage/symbol name is solely to ensure a single instance between this crate and its unit tests
7677
#[cfg_attr(test, linkage = "available_externally")]
77-
#[unsafe(export_name = "_ZN16__rust_internals3std3sys3sgx2os3ENVE")]
78+
#[unsafe(export_name = "_ZN16__rust_internals3std3sys3pal3sgx2os3ENVE")]
7879
static ENV: AtomicUsize = AtomicUsize::new(0);
80+
// Specifying linkage/symbol name is solely to ensure a single instance between this crate and its unit tests
7981
#[cfg_attr(test, linkage = "available_externally")]
80-
#[unsafe(export_name = "_ZN16__rust_internals3std3sys3sgx2os8ENV_INITE")]
82+
#[unsafe(export_name = "_ZN16__rust_internals3std3sys3pal3sgx2os8ENV_INITE")]
8183
static ENV_INIT: Once = Once::new();
8284
type EnvStore = Mutex<HashMap<OsString, OsString>>;
8385

std/src/sys/pal/sgx/thread.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,9 @@ mod task_queue {
4545
}
4646
}
4747

48+
// Specifying linkage/symbol name is solely to ensure a single instance between this crate and its unit tests
4849
#[cfg_attr(test, linkage = "available_externally")]
49-
#[unsafe(export_name = "_ZN16__rust_internals3std3sys3sgx6thread10TASK_QUEUEE")]
50+
#[unsafe(export_name = "_ZN16__rust_internals3std3sys3pal3sgx6thread10TASK_QUEUEE")]
5051
static TASK_QUEUE: Mutex<Vec<Task>> = Mutex::new(Vec::new());
5152

5253
pub(super) fn lock() -> MutexGuard<'static, Vec<Task>> {

0 commit comments

Comments
 (0)