Skip to content

Commit 0556414

Browse files
committed
Auto merge of rust-lang#84440 - Dylan-DPC:rollup-0xjb8oi, r=Dylan-DPC
Rollup of 7 pull requests Successful merges: - rust-lang#84343 (Remove `ScopeTree::closure_tree`) - rust-lang#84376 (Uses flex to fix formatting of h1 at any width) - rust-lang#84377 (Followup to rust-lang#83944) - rust-lang#84396 (Update LLVM submodule) - rust-lang#84402 (Move `sys_common::rwlock::StaticRWLock` etc. to `sys::unix::rwlock`) - rust-lang#84404 (Check for intrinsics before coercing to a function pointer) - rust-lang#84413 (Remove `sys::args::Args::inner_debug` and use `Debug` instead) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents cbc8587 + 376f6cb commit 0556414

File tree

11 files changed

+80
-92
lines changed

11 files changed

+80
-92
lines changed

std/src/env.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -799,7 +799,7 @@ impl DoubleEndedIterator for Args {
799799
#[stable(feature = "std_debug", since = "1.16.0")]
800800
impl fmt::Debug for Args {
801801
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
802-
f.debug_struct("Args").field("inner", &self.inner.inner.inner_debug()).finish()
802+
f.debug_struct("Args").field("inner", &self.inner.inner).finish()
803803
}
804804
}
805805

@@ -840,7 +840,7 @@ impl DoubleEndedIterator for ArgsOs {
840840
#[stable(feature = "std_debug", since = "1.16.0")]
841841
impl fmt::Debug for ArgsOs {
842842
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
843-
f.debug_struct("ArgsOs").field("inner", &self.inner.inner_debug()).finish()
843+
f.debug_struct("ArgsOs").field("inner", &self.inner).finish()
844844
}
845845
}
846846

std/src/sys/hermit/args.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::ffi::OsString;
2+
use crate::fmt;
23
use crate::marker::PhantomData;
34
use crate::vec;
45

@@ -22,9 +23,9 @@ pub struct Args {
2223
_dont_send_or_sync_me: PhantomData<*mut ()>,
2324
}
2425

25-
impl Args {
26-
pub fn inner_debug(&self) -> &[OsString] {
27-
self.iter.as_slice()
26+
impl fmt::Debug for Args {
27+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
28+
self.iter.as_slice().fmt(f)
2829
}
2930
}
3031

std/src/sys/sgx/args.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use super::abi::usercalls::{alloc, raw::ByteBuffer};
22
use crate::ffi::OsString;
3+
use crate::fmt;
34
use crate::slice;
45
use crate::sync::atomic::{AtomicUsize, Ordering};
56
use crate::sys::os_str::Buf;
@@ -31,9 +32,9 @@ pub fn args() -> Args {
3132

3233
pub struct Args(slice::Iter<'static, OsString>);
3334

34-
impl Args {
35-
pub fn inner_debug(&self) -> &[OsString] {
36-
self.0.as_slice()
35+
impl fmt::Debug for Args {
36+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
37+
self.0.as_slice().fmt(f)
3738
}
3839
}
3940

std/src/sys/unix/args.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#![allow(dead_code)] // runtime init functions not used during testing
77

88
use crate::ffi::OsString;
9+
use crate::fmt;
910
use crate::marker::PhantomData;
1011
use crate::vec;
1112

@@ -29,9 +30,9 @@ pub struct Args {
2930
_dont_send_or_sync_me: PhantomData<*mut ()>,
3031
}
3132

32-
impl Args {
33-
pub fn inner_debug(&self) -> &[OsString] {
34-
self.iter.as_slice()
33+
impl fmt::Debug for Args {
34+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
35+
self.iter.as_slice().fmt(f)
3536
}
3637
}
3738

std/src/sys/unix/os.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ use crate::slice;
2121
use crate::str;
2222
use crate::sys::cvt;
2323
use crate::sys::fd;
24+
use crate::sys::rwlock::{RWLockReadGuard, StaticRWLock};
2425
use crate::sys_common::mutex::{StaticMutex, StaticMutexGuard};
25-
use crate::sys_common::rwlock::{RWLockReadGuard, StaticRWLock};
2626
use crate::vec;
2727

2828
use libc::{c_char, c_int, c_void};

std/src/sys/unix/rwlock.rs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,3 +139,55 @@ impl RWLock {
139139
}
140140
}
141141
}
142+
143+
pub struct StaticRWLock(RWLock);
144+
145+
impl StaticRWLock {
146+
pub const fn new() -> StaticRWLock {
147+
StaticRWLock(RWLock::new())
148+
}
149+
150+
/// Acquires shared access to the underlying lock, blocking the current
151+
/// thread to do so.
152+
///
153+
/// The lock is automatically unlocked when the returned guard is dropped.
154+
#[inline]
155+
pub fn read_with_guard(&'static self) -> RWLockReadGuard {
156+
// SAFETY: All methods require static references, therefore self
157+
// cannot be moved between invocations.
158+
unsafe {
159+
self.0.read();
160+
}
161+
RWLockReadGuard(&self.0)
162+
}
163+
164+
/// Acquires write access to the underlying lock, blocking the current thread
165+
/// to do so.
166+
///
167+
/// The lock is automatically unlocked when the returned guard is dropped.
168+
#[inline]
169+
pub fn write_with_guard(&'static self) -> RWLockWriteGuard {
170+
// SAFETY: All methods require static references, therefore self
171+
// cannot be moved between invocations.
172+
unsafe {
173+
self.0.write();
174+
}
175+
RWLockWriteGuard(&self.0)
176+
}
177+
}
178+
179+
pub struct RWLockReadGuard(&'static RWLock);
180+
181+
impl Drop for RWLockReadGuard {
182+
fn drop(&mut self) {
183+
unsafe { self.0.read_unlock() }
184+
}
185+
}
186+
187+
pub struct RWLockWriteGuard(&'static RWLock);
188+
189+
impl Drop for RWLockWriteGuard {
190+
fn drop(&mut self) {
191+
unsafe { self.0.write_unlock() }
192+
}
193+
}

std/src/sys/unsupported/args.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ pub fn args() -> Args {
99
Args {}
1010
}
1111

12-
impl Args {
13-
pub fn inner_debug(&self) -> &[OsString] {
14-
&[]
12+
impl fmt::Debug for Args {
13+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
14+
f.debug_list().finish()
1515
}
1616
}
1717

std/src/sys/wasi/args.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#![deny(unsafe_op_in_unsafe_fn)]
22

33
use crate::ffi::{CStr, OsStr, OsString};
4+
use crate::fmt;
45
use crate::marker::PhantomData;
56
use crate::os::wasi::ffi::OsStrExt;
67
use crate::vec;
@@ -38,9 +39,9 @@ fn maybe_args() -> Option<Vec<OsString>> {
3839
}
3940
}
4041

41-
impl Args {
42-
pub fn inner_debug(&self) -> &[OsString] {
43-
self.iter.as_slice()
42+
impl fmt::Debug for Args {
43+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
44+
self.iter.as_slice().fmt(f)
4445
}
4546
}
4647

std/src/sys/wasm/args.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::ffi::OsString;
2+
use crate::fmt;
23
use crate::marker::PhantomData;
34
use crate::vec;
45

@@ -17,9 +18,9 @@ pub struct Args {
1718
_dont_send_or_sync_me: PhantomData<*mut ()>,
1819
}
1920

20-
impl Args {
21-
pub fn inner_debug(&self) -> &[OsString] {
22-
self.iter.as_slice()
21+
impl fmt::Debug for Args {
22+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
23+
self.iter.as_slice().fmt(f)
2324
}
2425
}
2526

std/src/sys/windows/args.rs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -164,19 +164,9 @@ pub struct Args {
164164
parsed_args_list: vec::IntoIter<OsString>,
165165
}
166166

167-
pub struct ArgsInnerDebug<'a> {
168-
args: &'a Args,
169-
}
170-
171-
impl<'a> fmt::Debug for ArgsInnerDebug<'a> {
167+
impl fmt::Debug for Args {
172168
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
173-
self.args.parsed_args_list.as_slice().fmt(f)
174-
}
175-
}
176-
177-
impl Args {
178-
pub fn inner_debug(&self) -> ArgsInnerDebug<'_> {
179-
ArgsInnerDebug { args: self }
169+
self.parsed_args_list.as_slice().fmt(f)
180170
}
181171
}
182172

0 commit comments

Comments
 (0)