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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions library/std/src/collections/hash/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! Unordered containers, implemented as hash-tables

pub mod map;
pub mod set;
pub(crate) mod map;
pub(crate) mod set;
2 changes: 1 addition & 1 deletion library/std/src/fs/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ macro_rules! error_contains {
// have permission, and return otherwise. This way, we still don't run these
// tests most of the time, but at least we do if the user has the right
// permissions.
pub fn got_symlink_permission(tmpdir: &TempDir) -> bool {
pub(crate) fn got_symlink_permission(tmpdir: &TempDir) -> bool {
if cfg!(not(windows)) || env::var_os("CI").is_some() {
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion library/std/src/io/stdio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,7 @@ pub fn stdout() -> Stdout {
// Flush the data and disable buffering during shutdown
// by replacing the line writer by one with zero
// buffering capacity.
pub fn cleanup() {
pub(crate) fn cleanup() {
let mut initialized = false;
let stdout = STDOUT.get_or_init(|| {
initialized = true;
Expand Down
3 changes: 3 additions & 0 deletions library/std/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@
// Lints:
#![warn(deprecated_in_future)]
#![warn(missing_docs)]
#![warn(unreachable_pub)]
#![warn(missing_debug_implementations)]
#![allow(explicit_outlives_requirements)]
#![allow(unused_lifetimes)]
Expand Down Expand Up @@ -641,6 +642,7 @@ pub mod hash;
pub mod io;
pub mod net;
pub mod num;
#[allow(unreachable_pub)]
pub mod os;
pub mod panic;
#[unstable(feature = "pattern_type_macro", issue = "123646")]
Expand Down Expand Up @@ -731,6 +733,7 @@ pub mod arch {
#[stable(feature = "simd_x86", since = "1.27.0")]
pub use std_detect::is_x86_feature_detected;

#[allow(unreachable_pub)]
mod sys;

pub mod alloc;
Expand Down
10 changes: 5 additions & 5 deletions library/std/src/panicking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ use crate::{fmt, intrinsics, process, thread};
#[doc(hidden)]
#[allow(dead_code)]
#[used(compiler)]
pub static EMPTY_PANIC: fn(&'static str) -> ! =
pub(crate) static EMPTY_PANIC: fn(&'static str) -> ! =
begin_panic::<&'static str> as fn(&'static str) -> !;

// Binary interface to the panic runtime that the standard library depends on.
Expand Down Expand Up @@ -495,7 +495,7 @@ pub unsafe fn catch_unwind<R, F: FnOnce() -> R>(f: F) -> Result<R, Box<dyn Any +

/// Invoke a closure, capturing the cause of an unwinding panic if one occurs.
#[cfg(not(panic = "immediate-abort"))]
pub unsafe fn catch_unwind<R, F: FnOnce() -> R>(f: F) -> Result<R, Box<dyn Any + Send>> {
pub(crate) unsafe fn catch_unwind<R, F: FnOnce() -> R>(f: F) -> Result<R, Box<dyn Any + Send>> {
union Data<F, R> {
f: ManuallyDrop<F>,
r: ManuallyDrop<R>,
Expand Down Expand Up @@ -599,14 +599,14 @@ pub unsafe fn catch_unwind<R, F: FnOnce() -> R>(f: F) -> Result<R, Box<dyn Any +

/// Determines whether the current thread is unwinding because of panic.
#[inline]
pub fn panicking() -> bool {
pub(crate) fn panicking() -> bool {
!panic_count::count_is_zero()
}

/// Entry point of panics from the core crate (`panic_impl` lang item).
#[cfg(not(any(test, doctest)))]
#[panic_handler]
pub fn panic_handler(info: &core::panic::PanicInfo<'_>) -> ! {
pub(crate) fn panic_handler(info: &core::panic::PanicInfo<'_>) -> ! {
struct FormatStringPayload<'a> {
inner: &'a core::panic::PanicMessage<'a>,
string: Option<String>,
Expand Down Expand Up @@ -839,7 +839,7 @@ fn panic_with_hook(
/// This is the entry point for `resume_unwind`.
/// It just forwards the payload to the panic runtime.
#[cfg_attr(panic = "immediate-abort", inline)]
pub fn resume_unwind(payload: Box<dyn Any + Send>) -> ! {
pub(crate) fn resume_unwind(payload: Box<dyn Any + Send>) -> ! {
if let Some(must_abort) = panic_count::increase(false) {
match must_abort {
panic_count::MustAbort::PanicInHook => {
Expand Down
4 changes: 2 additions & 2 deletions library/std/src/process/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ fn signal_reported_right() {
}
}

pub fn run_output(mut cmd: Command) -> String {
pub(crate) fn run_output(mut cmd: Command) -> String {
let p = cmd.spawn();
assert!(p.is_ok());
let mut p = p.unwrap();
Expand Down Expand Up @@ -361,7 +361,7 @@ fn test_wait_with_output_once() {
}

#[cfg(all(unix, not(target_os = "android")))]
pub fn env_cmd() -> Command {
pub(crate) fn env_cmd() -> Command {
Command::new("env")
}
#[cfg(target_os = "android")]
Expand Down
14 changes: 7 additions & 7 deletions library/std/src/sync/mpmc/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::time::Instant;

/// Thread-local context.
#[derive(Debug, Clone)]
pub struct Context {
pub(crate) struct Context {
inner: Arc<Inner>,
}

Expand All @@ -34,7 +34,7 @@ struct Inner {
impl Context {
/// Creates a new context for the duration of the closure.
#[inline]
pub fn with<F, R>(f: F) -> R
pub(crate) fn with<F, R>(f: F) -> R
where
F: FnOnce(&Context) -> R,
{
Expand Down Expand Up @@ -86,7 +86,7 @@ impl Context {
///
/// On failure, the previously selected operation is returned.
#[inline]
pub fn try_select(&self, select: Selected) -> Result<(), Selected> {
pub(crate) fn try_select(&self, select: Selected) -> Result<(), Selected> {
self.inner
.select
.compare_exchange(
Expand All @@ -103,7 +103,7 @@ impl Context {
///
/// This method must be called after `try_select` succeeds and there is a packet to provide.
#[inline]
pub fn store_packet(&self, packet: *mut ()) {
pub(crate) fn store_packet(&self, packet: *mut ()) {
if !packet.is_null() {
self.inner.packet.store(packet, Ordering::Release);
}
Expand All @@ -116,7 +116,7 @@ impl Context {
/// # Safety
/// This may only be called from the thread this `Context` belongs to.
#[inline]
pub unsafe fn wait_until(&self, deadline: Option<Instant>) -> Selected {
pub(crate) unsafe fn wait_until(&self, deadline: Option<Instant>) -> Selected {
loop {
// Check whether an operation has been selected.
let sel = Selected::from(self.inner.select.load(Ordering::Acquire));
Expand Down Expand Up @@ -147,13 +147,13 @@ impl Context {

/// Unparks the thread this context belongs to.
#[inline]
pub fn unpark(&self) {
pub(crate) fn unpark(&self) {
self.inner.thread.unpark();
}

/// Returns the id of the thread this context belongs to.
#[inline]
pub fn thread_id(&self) -> usize {
pub(crate) fn thread_id(&self) -> usize {
self.inner.thread_id
}
}
8 changes: 4 additions & 4 deletions library/std/src/sync/mpmc/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
///
/// Each field contains data associated with a specific channel flavor.
#[derive(Debug, Default)]
pub struct Token {
pub(crate) struct Token {
pub(crate) array: super::array::ArrayToken,
pub(crate) list: super::list::ListToken,
#[allow(dead_code)]
Expand All @@ -12,7 +12,7 @@ pub struct Token {

/// Identifier associated with an operation by a specific thread on a specific channel.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Operation(usize);
pub(crate) struct Operation(usize);

impl Operation {
/// Creates an operation identifier from a mutable reference.
Expand All @@ -21,7 +21,7 @@ impl Operation {
/// reference should point to a variable that is specific to the thread and the operation,
/// and is alive for the entire duration of a blocking operation.
#[inline]
pub fn hook<T>(r: &mut T) -> Operation {
pub(crate) fn hook<T>(r: &mut T) -> Operation {
let val = (r as *mut T).addr();
// Make sure that the pointer address doesn't equal the numerical representation of
// `Selected::{Waiting, Aborted, Disconnected}`.
Expand All @@ -32,7 +32,7 @@ impl Operation {

/// Current state of a blocking operation.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Selected {
pub(crate) enum Selected {
/// Still waiting for an operation.
Waiting,

Expand Down
12 changes: 6 additions & 6 deletions library/std/src/sync/mpmc/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@ use crate::ops::{Deref, DerefMut};
)),
repr(align(64))
)]
pub struct CachePadded<T> {
pub(crate) struct CachePadded<T> {
value: T,
}

impl<T> CachePadded<T> {
/// Pads and aligns a value to the length of a cache line.
pub fn new(value: T) -> CachePadded<T> {
pub(crate) fn new(value: T) -> CachePadded<T> {
CachePadded::<T> { value }
}
}
Expand All @@ -95,13 +95,13 @@ impl<T> DerefMut for CachePadded<T> {
const SPIN_LIMIT: u32 = 6;

/// Performs quadratic backoff in spin loops.
pub struct Backoff {
pub(crate) struct Backoff {
step: Cell<u32>,
}

impl Backoff {
/// Creates a new `Backoff`.
pub fn new() -> Self {
pub(crate) fn new() -> Self {
Backoff { step: Cell::new(0) }
}

Expand All @@ -110,7 +110,7 @@ impl Backoff {
/// This method should be used for retrying an operation because another thread made
/// progress. i.e. on CAS failure.
#[inline]
pub fn spin_light(&self) {
pub(crate) fn spin_light(&self) {
let step = self.step.get().min(SPIN_LIMIT);
for _ in 0..step.pow(2) {
crate::hint::spin_loop();
Expand All @@ -123,7 +123,7 @@ impl Backoff {
///
/// This method should be used in blocking loops where parking the thread is not an option.
#[inline]
pub fn spin_heavy(&self) {
pub(crate) fn spin_heavy(&self) {
if self.step.get() <= SPIN_LIMIT {
for _ in 0..self.step.get().pow(2) {
crate::hint::spin_loop()
Expand Down
2 changes: 1 addition & 1 deletion library/std/src/sync/mpmc/waker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ impl Drop for SyncWaker {

/// Returns a unique id for the current thread.
#[inline]
pub fn current_thread_id() -> usize {
pub(crate) fn current_thread_id() -> usize {
// `u8` is not drop so this variable will be available during thread destruction,
// whereas `thread::current()` would not be
thread_local! { static DUMMY: u8 = const { 0 } }
Expand Down
16 changes: 8 additions & 8 deletions library/std/src/sync/poison.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ pub(crate) struct Flag {

impl Flag {
#[inline]
pub const fn new() -> Flag {
pub(crate) const fn new() -> Flag {
Flag {
#[cfg(panic = "unwind")]
failed: AtomicBool::new(false),
Expand All @@ -106,13 +106,13 @@ impl Flag {

/// Checks the flag for an unguarded borrow, where we only care about existing poison.
#[inline]
pub fn borrow(&self) -> LockResult<()> {
pub(crate) fn borrow(&self) -> LockResult<()> {
if self.get() { Err(PoisonError::new(())) } else { Ok(()) }
}

/// Checks the flag for a guarded borrow, where we may also set poison when `done`.
#[inline]
pub fn guard(&self) -> LockResult<Guard> {
pub(crate) fn guard(&self) -> LockResult<Guard> {
let ret = Guard {
#[cfg(panic = "unwind")]
panicking: thread::panicking(),
Expand All @@ -122,30 +122,30 @@ impl Flag {

#[inline]
#[cfg(panic = "unwind")]
pub fn done(&self, guard: &Guard) {
pub(crate) fn done(&self, guard: &Guard) {
if !guard.panicking && thread::panicking() {
self.failed.store(true, Ordering::Relaxed);
}
}

#[inline]
#[cfg(not(panic = "unwind"))]
pub fn done(&self, _guard: &Guard) {}
pub(crate) fn done(&self, _guard: &Guard) {}

#[inline]
#[cfg(panic = "unwind")]
pub fn get(&self) -> bool {
pub(crate) fn get(&self) -> bool {
self.failed.load(Ordering::Relaxed)
}

#[inline(always)]
#[cfg(not(panic = "unwind"))]
pub fn get(&self) -> bool {
pub(crate) fn get(&self) -> bool {
false
}

#[inline]
pub fn clear(&self) {
pub(crate) fn clear(&self) {
#[cfg(panic = "unwind")]
self.failed.store(false, Ordering::Relaxed)
}
Expand Down
8 changes: 4 additions & 4 deletions library/std/src/test_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ pub(crate) fn test_rng() -> rand_xorshift::XorShiftRng {
SeedableRng::from_seed(seed)
}

pub struct TempDir(PathBuf);
pub(crate) struct TempDir(PathBuf);

impl TempDir {
pub fn join(&self, path: &str) -> PathBuf {
pub(crate) fn join(&self, path: &str) -> PathBuf {
let TempDir(ref p) = *self;
p.join(path)
}

pub fn path(&self) -> &Path {
pub(crate) fn path(&self) -> &Path {
let TempDir(ref p) = *self;
p
}
Expand All @@ -56,7 +56,7 @@ impl Drop for TempDir {
}

#[track_caller] // for `test_rng`
pub fn tmpdir() -> TempDir {
pub(crate) fn tmpdir() -> TempDir {
let p = env::temp_dir();
let mut r = test_rng();
let ret = p.join(&format!("rust-{}", r.next_u32()));
Expand Down
2 changes: 1 addition & 1 deletion library/std/src/thread/lifecycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ pub(crate) struct ThreadInit {
impl ThreadInit {
/// Initialize the 'current thread' mechanism on this thread, returning the
/// Rust entry point.
pub fn init(self: Box<Self>) -> Box<dyn FnOnce() + Send> {
pub(crate) fn init(self: Box<Self>) -> Box<dyn FnOnce() + Send> {
// Set the current thread before any (de)allocations on the global allocator occur,
// so that it may call std::thread::current() in its implementation. This is also
// why we take Box<Self>, to ensure the Box is not destroyed until after this point.
Expand Down
4 changes: 2 additions & 2 deletions library/std/src/thread/thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ mod thread_name_string {
}

impl ThreadNameString {
pub fn as_cstr(&self) -> &CStr {
pub(crate) fn as_cstr(&self) -> &CStr {
&self.inner
}

pub fn as_str(&self) -> &str {
pub(crate) fn as_str(&self) -> &str {
// SAFETY: `ThreadNameString` is guaranteed to be UTF-8.
unsafe { str::from_utf8_unchecked(self.inner.to_bytes()) }
}
Expand Down
Loading