Skip to content

Commit d272d6a

Browse files
committed
Change some pub to pub(crate) in std
1 parent bda32a4 commit d272d6a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+343
-302
lines changed
+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
//! Unordered containers, implemented as hash-tables
22
3-
pub mod map;
4-
pub mod set;
3+
pub(crate) mod map;
4+
pub(crate) mod set;

library/std/src/error.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ mod private {
1515
// implementations, since that can enable unsound downcasting.
1616
#[unstable(feature = "error_type_id", issue = "60784")]
1717
#[derive(Debug)]
18-
pub struct Internal;
18+
pub(crate) struct Internal;
1919
}
2020

2121
/// An error reporter that prints an error and its sources.

library/std/src/fs/tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ macro_rules! error_contains {
7272
// have permission, and return otherwise. This way, we still don't run these
7373
// tests most of the time, but at least we do if the user has the right
7474
// permissions.
75-
pub fn got_symlink_permission(tmpdir: &TempDir) -> bool {
75+
pub(crate) fn got_symlink_permission(tmpdir: &TempDir) -> bool {
7676
if cfg!(unix) {
7777
return true;
7878
}

library/std/src/io/buffered/bufreader/buffer.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use crate::cmp;
1212
use crate::io::{self, BorrowedBuf, Read};
1313
use crate::mem::MaybeUninit;
1414

15-
pub struct Buffer {
15+
pub(crate) struct Buffer {
1616
// The buffer.
1717
buf: Box<[MaybeUninit<u8>]>,
1818
// The current seek offset into `buf`, must always be <= `filled`.
@@ -30,54 +30,54 @@ pub struct Buffer {
3030

3131
impl Buffer {
3232
#[inline]
33-
pub fn with_capacity(capacity: usize) -> Self {
33+
pub(crate) fn with_capacity(capacity: usize) -> Self {
3434
let buf = Box::new_uninit_slice(capacity);
3535
Self { buf, pos: 0, filled: 0, initialized: 0 }
3636
}
3737

3838
#[inline]
39-
pub fn buffer(&self) -> &[u8] {
39+
pub(crate) fn buffer(&self) -> &[u8] {
4040
// SAFETY: self.pos and self.cap are valid, and self.cap => self.pos, and
4141
// that region is initialized because those are all invariants of this type.
4242
unsafe { MaybeUninit::slice_assume_init_ref(self.buf.get_unchecked(self.pos..self.filled)) }
4343
}
4444

4545
#[inline]
46-
pub fn capacity(&self) -> usize {
46+
pub(crate) fn capacity(&self) -> usize {
4747
self.buf.len()
4848
}
4949

5050
#[inline]
51-
pub fn filled(&self) -> usize {
51+
pub(crate) fn filled(&self) -> usize {
5252
self.filled
5353
}
5454

5555
#[inline]
56-
pub fn pos(&self) -> usize {
56+
pub(crate) fn pos(&self) -> usize {
5757
self.pos
5858
}
5959

6060
// This is only used by a test which asserts that the initialization-tracking is correct.
6161
#[cfg(test)]
62-
pub fn initialized(&self) -> usize {
62+
pub(crate) fn initialized(&self) -> usize {
6363
self.initialized
6464
}
6565

6666
#[inline]
67-
pub fn discard_buffer(&mut self) {
67+
pub(crate) fn discard_buffer(&mut self) {
6868
self.pos = 0;
6969
self.filled = 0;
7070
}
7171

7272
#[inline]
73-
pub fn consume(&mut self, amt: usize) {
73+
pub(crate) fn consume(&mut self, amt: usize) {
7474
self.pos = cmp::min(self.pos + amt, self.filled);
7575
}
7676

7777
/// If there are `amt` bytes available in the buffer, pass a slice containing those bytes to
7878
/// `visitor` and return true. If there are not enough bytes available, return false.
7979
#[inline]
80-
pub fn consume_with<V>(&mut self, amt: usize, mut visitor: V) -> bool
80+
pub(crate) fn consume_with<V>(&mut self, amt: usize, mut visitor: V) -> bool
8181
where
8282
V: FnMut(&[u8]),
8383
{
@@ -92,12 +92,12 @@ impl Buffer {
9292
}
9393

9494
#[inline]
95-
pub fn unconsume(&mut self, amt: usize) {
95+
pub(crate) fn unconsume(&mut self, amt: usize) {
9696
self.pos = self.pos.saturating_sub(amt);
9797
}
9898

9999
#[inline]
100-
pub fn fill_buf(&mut self, mut reader: impl Read) -> io::Result<&[u8]> {
100+
pub(crate) fn fill_buf(&mut self, mut reader: impl Read) -> io::Result<&[u8]> {
101101
// If we've reached the end of our internal buffer then we need to fetch
102102
// some more data from the reader.
103103
// Branch using `>=` instead of the more correct `==`

library/std/src/io/buffered/linewritershim.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ use crate::sys_common::memchr;
1111
/// `BufWriters` to be temporarily given line-buffering logic; this is what
1212
/// enables Stdout to be alternately in line-buffered or block-buffered mode.
1313
#[derive(Debug)]
14-
pub struct LineWriterShim<'a, W: Write> {
14+
pub(crate) struct LineWriterShim<'a, W: Write> {
1515
buffer: &'a mut BufWriter<W>,
1616
}
1717

1818
impl<'a, W: Write> LineWriterShim<'a, W> {
19-
pub fn new(buffer: &'a mut BufWriter<W>) -> Self {
19+
pub(crate) fn new(buffer: &'a mut BufWriter<W>) -> Self {
2020
Self { buffer }
2121
}
2222

library/std/src/io/buffered/tests.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::sync::atomic::{AtomicUsize, Ordering};
88
use crate::thread;
99

1010
/// A dummy reader intended at testing short-reads propagation.
11-
pub struct ShortReader {
11+
pub(crate) struct ShortReader {
1212
lengths: Vec<usize>,
1313
}
1414

@@ -541,25 +541,25 @@ fn bench_buffered_writer(b: &mut test::Bencher) {
541541
#[derive(Default, Clone)]
542542
struct ProgrammableSink {
543543
// Writes append to this slice
544-
pub buffer: Vec<u8>,
544+
pub(crate) buffer: Vec<u8>,
545545

546546
// If true, writes will always be an error
547-
pub always_write_error: bool,
547+
pub(crate) always_write_error: bool,
548548

549549
// If true, flushes will always be an error
550-
pub always_flush_error: bool,
550+
pub(crate) always_flush_error: bool,
551551

552552
// If set, only up to this number of bytes will be written in a single
553553
// call to `write`
554-
pub accept_prefix: Option<usize>,
554+
pub(crate) accept_prefix: Option<usize>,
555555

556556
// If set, counts down with each write, and writes return an error
557557
// when it hits 0
558-
pub max_writes: Option<usize>,
558+
pub(crate) max_writes: Option<usize>,
559559

560560
// If set, attempting to write when max_writes == Some(0) will be an
561561
// error; otherwise, it will return Ok(0).
562-
pub error_after_max_writes: bool,
562+
pub(crate) error_after_max_writes: bool,
563563
}
564564

565565
impl Write for ProgrammableSink {
@@ -1006,7 +1006,7 @@ enum RecordedEvent {
10061006

10071007
#[derive(Debug, Clone, Default)]
10081008
struct WriteRecorder {
1009-
pub events: Vec<RecordedEvent>,
1009+
pub(crate) events: Vec<RecordedEvent>,
10101010
}
10111011

10121012
impl Write for WriteRecorder {

library/std/src/io/cursor/tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ fn test_partial_eq() {
518518

519519
#[test]
520520
fn test_eq() {
521-
struct AssertEq<T: Eq>(pub T);
521+
struct AssertEq<T: Eq>(pub(crate) T);
522522

523523
let _: AssertEq<Cursor<Vec<u8>>> = AssertEq(Cursor::new(Vec::new()));
524524
}

library/std/src/io/stdio.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,7 @@ pub fn stdout() -> Stdout {
610610
// Flush the data and disable buffering during shutdown
611611
// by replacing the line writer by one with zero
612612
// buffering capacity.
613-
pub fn cleanup() {
613+
pub(crate) fn cleanup() {
614614
let mut initialized = false;
615615
let stdout = STDOUT.get_or_init(|| {
616616
initialized = true;

library/std/src/lib.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@
221221
#![allow(unused_lifetimes)]
222222
#![deny(rustc::existing_doc_keyword)]
223223
#![deny(fuzzy_provenance_casts)]
224+
#![cfg_attr(not(test), warn(unreachable_pub))]
224225
// Ensure that std can be linked against panic_abort despite compiled with `-C panic=unwind`
225226
#![deny(ffi_unwind_calls)]
226227
// std may use features in a platform-specific way
@@ -518,6 +519,8 @@ pub mod fs;
518519
pub mod io;
519520
pub mod net;
520521
pub mod num;
522+
// os-specific code may be incorrectly detected as unreachable
523+
#[allow(unreachable_pub)]
521524
pub mod os;
522525
pub mod panic;
523526
pub mod path;
@@ -582,7 +585,10 @@ pub mod arch {
582585
pub use std_detect::is_x86_feature_detected;
583586

584587
// Platform-abstraction modules
588+
// platform-specific code may be incorrectly detected as unreachable
589+
#[allow(unreachable_pub)]
585590
mod sys;
591+
#[allow(unreachable_pub)]
586592
mod sys_common;
587593

588594
pub mod alloc;
@@ -592,7 +598,7 @@ mod panicking;
592598
mod personality;
593599

594600
#[path = "../../backtrace/src/lib.rs"]
595-
#[allow(dead_code, unused_attributes, fuzzy_provenance_casts)]
601+
#[allow(dead_code, unused_attributes, fuzzy_provenance_casts, unreachable_pub)]
596602
mod backtrace_rs;
597603

598604
// Re-export macros defined in core.

library/std/src/net/display_buffer.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@ use crate::mem::MaybeUninit;
33
use crate::str;
44

55
/// Used for slow path in `Display` implementations when alignment is required.
6-
pub struct DisplayBuffer<const SIZE: usize> {
6+
pub(crate) struct DisplayBuffer<const SIZE: usize> {
77
buf: [MaybeUninit<u8>; SIZE],
88
len: usize,
99
}
1010

1111
impl<const SIZE: usize> DisplayBuffer<SIZE> {
1212
#[inline]
13-
pub const fn new() -> Self {
13+
pub(crate) const fn new() -> Self {
1414
Self { buf: MaybeUninit::uninit_array(), len: 0 }
1515
}
1616

1717
#[inline]
18-
pub fn as_str(&self) -> &str {
18+
pub(crate) fn as_str(&self) -> &str {
1919
// SAFETY: `buf` is only written to by the `fmt::Write::write_str` implementation
2020
// which writes a valid UTF-8 string to `buf` and correctly sets `len`.
2121
unsafe {

library/std/src/net/test.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,25 @@ use crate::sync::atomic::{AtomicUsize, Ordering};
66

77
static PORT: AtomicUsize = AtomicUsize::new(0);
88

9-
pub fn next_test_ip4() -> SocketAddr {
9+
pub(crate) fn next_test_ip4() -> SocketAddr {
1010
let port = PORT.fetch_add(1, Ordering::SeqCst) as u16 + base_port();
1111
SocketAddr::V4(SocketAddrV4::new(Ipv4Addr::new(127, 0, 0, 1), port))
1212
}
1313

14-
pub fn next_test_ip6() -> SocketAddr {
14+
pub(crate) fn next_test_ip6() -> SocketAddr {
1515
let port = PORT.fetch_add(1, Ordering::SeqCst) as u16 + base_port();
1616
SocketAddr::V6(SocketAddrV6::new(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1), port, 0, 0))
1717
}
1818

19-
pub fn sa4(a: Ipv4Addr, p: u16) -> SocketAddr {
19+
pub(crate) fn sa4(a: Ipv4Addr, p: u16) -> SocketAddr {
2020
SocketAddr::V4(SocketAddrV4::new(a, p))
2121
}
2222

23-
pub fn sa6(a: Ipv6Addr, p: u16) -> SocketAddr {
23+
pub(crate) fn sa6(a: Ipv6Addr, p: u16) -> SocketAddr {
2424
SocketAddr::V6(SocketAddrV6::new(a, p, 0, 0))
2525
}
2626

27-
pub fn tsa<A: ToSocketAddrs>(a: A) -> Result<Vec<SocketAddr>, String> {
27+
pub(crate) fn tsa<A: ToSocketAddrs>(a: A) -> Result<Vec<SocketAddr>, String> {
2828
match a.to_socket_addrs() {
2929
Ok(a) => Ok(a.collect()),
3030
Err(e) => Err(e.to_string()),

library/std/src/os/unix/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ mod platform {
6060
#[cfg(target_os = "l4re")]
6161
pub use crate::os::l4re::*;
6262
#[cfg(target_os = "linux")]
63-
pub use crate::os::linux::*;
63+
pub(crate) use crate::os::linux::*;
6464
#[cfg(target_os = "macos")]
6565
pub use crate::os::macos::*;
6666
#[cfg(target_os = "netbsd")]

library/std/src/panicking.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ pub mod panic_count {
404404
pub use realstd::rt::panic_count;
405405

406406
/// Invoke a closure, capturing the cause of an unwinding panic if one occurs.
407-
pub unsafe fn r#try<R, F: FnOnce() -> R>(f: F) -> Result<R, Box<dyn Any + Send>> {
407+
pub(crate) unsafe fn r#try<R, F: FnOnce() -> R>(f: F) -> Result<R, Box<dyn Any + Send>> {
408408
union Data<F, R> {
409409
f: ManuallyDrop<F>,
410410
r: ManuallyDrop<R>,
@@ -517,14 +517,14 @@ pub unsafe fn r#try<R, F: FnOnce() -> R>(f: F) -> Result<R, Box<dyn Any + Send>>
517517

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

524524
/// Entry point of panics from the core crate (`panic_impl` lang item).
525525
#[cfg(not(test))]
526526
#[panic_handler]
527-
pub fn begin_panic_handler(info: &PanicInfo<'_>) -> ! {
527+
pub(crate) fn begin_panic_handler(info: &PanicInfo<'_>) -> ! {
528528
struct PanicPayload<'a> {
529529
inner: &'a fmt::Arguments<'a>,
530530
string: Option<String>,
@@ -716,7 +716,7 @@ fn rust_panic_with_hook(
716716

717717
/// This is the entry point for `resume_unwind`.
718718
/// It just forwards the payload to the panic runtime.
719-
pub fn rust_panic_without_hook(payload: Box<dyn Any + Send>) -> ! {
719+
pub(crate) fn rust_panic_without_hook(payload: Box<dyn Any + Send>) -> ! {
720720
panic_count::increase();
721721

722722
struct RewrapBox(Box<dyn Any + Send>);

0 commit comments

Comments
 (0)