Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable unreachable_pub lint in core #134286

Merged
merged 4 commits into from
Jan 21, 2025
Merged
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
10 changes: 9 additions & 1 deletion library/core/src/arch.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
#![doc = include_str!("../../stdarch/crates/core_arch/src/core_arch_docs.md")]

#[allow(unused_imports)]
#[allow(
// some targets don't have anything to reexport, which
// makes the `pub use` unused and unreachable, allow
// both lints as to not have `#[cfg]`s
//
// cf. https://github.com/rust-lang/rust/pull/116033#issuecomment-1760085575
unused_imports,
unreachable_pub
)]
#[stable(feature = "simd_arch", since = "1.27.0")]
pub use crate::core_arch::arch::*;

Expand Down
2 changes: 1 addition & 1 deletion library/core/src/array/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -893,7 +893,7 @@ impl<T> Guard<'_, T> {
///
/// No more than N elements must be initialized.
#[inline]
pub unsafe fn push_unchecked(&mut self, item: T) {
pub(crate) unsafe fn push_unchecked(&mut self, item: T) {
// SAFETY: If `initialized` was correct before and the caller does not
// invoke this method more than N times then writes will be in-bounds
// and slots will not be initialized more than once.
Expand Down
22 changes: 11 additions & 11 deletions library/core/src/escape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,63 +163,63 @@ pub(crate) struct EscapeIterInner<const N: usize> {
}

impl<const N: usize> EscapeIterInner<N> {
pub const fn backslash(c: ascii::Char) -> Self {
pub(crate) const fn backslash(c: ascii::Char) -> Self {
let (data, range) = backslash(c);
Self { data, alive: range }
}

pub const fn ascii(c: u8) -> Self {
pub(crate) const fn ascii(c: u8) -> Self {
let (data, range) = escape_ascii(c);
Self { data, alive: range }
}

pub const fn unicode(c: char) -> Self {
pub(crate) const fn unicode(c: char) -> Self {
let (data, range) = escape_unicode(c);
Self { data, alive: range }
}

#[inline]
pub const fn empty() -> Self {
pub(crate) const fn empty() -> Self {
Self { data: [ascii::Char::Null; N], alive: 0..0 }
}

#[inline]
pub fn as_ascii(&self) -> &[ascii::Char] {
pub(crate) fn as_ascii(&self) -> &[ascii::Char] {
// SAFETY: `self.alive` is guaranteed to be a valid range for indexing `self.data`.
unsafe {
self.data.get_unchecked(usize::from(self.alive.start)..usize::from(self.alive.end))
}
}

#[inline]
pub fn as_str(&self) -> &str {
pub(crate) fn as_str(&self) -> &str {
self.as_ascii().as_str()
}

#[inline]
pub fn len(&self) -> usize {
pub(crate) fn len(&self) -> usize {
usize::from(self.alive.end - self.alive.start)
}

pub fn next(&mut self) -> Option<u8> {
pub(crate) fn next(&mut self) -> Option<u8> {
let i = self.alive.next()?;

// SAFETY: `i` is guaranteed to be a valid index for `self.data`.
unsafe { Some(self.data.get_unchecked(usize::from(i)).to_u8()) }
}

pub fn next_back(&mut self) -> Option<u8> {
pub(crate) fn next_back(&mut self) -> Option<u8> {
let i = self.alive.next_back()?;

// SAFETY: `i` is guaranteed to be a valid index for `self.data`.
unsafe { Some(self.data.get_unchecked(usize::from(i)).to_u8()) }
}

pub fn advance_by(&mut self, n: usize) -> Result<(), NonZero<usize>> {
pub(crate) fn advance_by(&mut self, n: usize) -> Result<(), NonZero<usize>> {
self.alive.advance_by(n)
}

pub fn advance_back_by(&mut self, n: usize) -> Result<(), NonZero<usize>> {
pub(crate) fn advance_back_by(&mut self, n: usize) -> Result<(), NonZero<usize>> {
self.alive.advance_back_by(n)
}
}
20 changes: 10 additions & 10 deletions library/core/src/ffi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,35 +172,35 @@ mod c_char_definition {
target_arch = "xtensa",
)
))] {
pub type c_char = u8;
pub(super) type c_char = u8;
} else {
// On every other target, c_char is signed.
pub type c_char = i8;
pub(super) type c_char = i8;
}
}
}

mod c_int_definition {
cfg_if! {
if #[cfg(any(target_arch = "avr", target_arch = "msp430"))] {
pub type c_int = i16;
pub type c_uint = u16;
pub(super) type c_int = i16;
pub(super) type c_uint = u16;
} else {
pub type c_int = i32;
pub type c_uint = u32;
pub(super) type c_int = i32;
pub(super) type c_uint = u32;
}
}
}

mod c_long_definition {
cfg_if! {
if #[cfg(all(target_pointer_width = "64", not(windows)))] {
pub type c_long = i64;
pub type c_ulong = u64;
pub(super) type c_long = i64;
pub(super) type c_ulong = u64;
} else {
// The minimal size of `long` in the C standard is 32 bits
pub type c_long = i32;
pub type c_ulong = u32;
pub(super) type c_long = i32;
pub(super) type c_ulong = u32;
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion library/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
#![warn(multiple_supertrait_upcastable)]
#![allow(internal_features)]
#![deny(ffi_unwind_calls)]
#![warn(unreachable_pub)]
// Do not check link redundancy on bootstraping phase
#![allow(rustdoc::redundant_explicit_links)]
#![warn(rustdoc::unescaped_backticks)]
Expand Down Expand Up @@ -396,7 +397,8 @@ pub mod primitive;
unused_imports,
unsafe_op_in_unsafe_fn,
ambiguous_glob_reexports,
deprecated_in_future
deprecated_in_future,
unreachable_pub
Urgau marked this conversation as resolved.
Show resolved Hide resolved
)]
#[allow(rustdoc::bare_urls)]
mod core_arch;
Expand Down
6 changes: 3 additions & 3 deletions library/core/src/net/display_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ use crate::mem::MaybeUninit;
use crate::{fmt, str};

/// Used for slow path in `Display` implementations when alignment is required.
pub struct DisplayBuffer<const SIZE: usize> {
pub(super) struct DisplayBuffer<const SIZE: usize> {
buf: [MaybeUninit<u8>; SIZE],
len: usize,
}

impl<const SIZE: usize> DisplayBuffer<SIZE> {
#[inline]
pub const fn new() -> Self {
pub(super) const fn new() -> Self {
Self { buf: [MaybeUninit::uninit(); SIZE], len: 0 }
}

#[inline]
pub fn as_str(&self) -> &str {
pub(super) fn as_str(&self) -> &str {
// SAFETY: `buf` is only written to by the `fmt::Write::write_str` implementation
// which writes a valid UTF-8 string to `buf` and correctly sets `len`.
unsafe {
Expand Down
20 changes: 10 additions & 10 deletions library/core/src/num/dec2flt/decimal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use crate::num::dec2flt::common::{ByteSlice, is_8digits};

#[derive(Clone)]
pub struct Decimal {
pub(super) struct Decimal {
/// The number of significant digits in the decimal.
pub num_digits: usize,
/// The offset of the decimal point in the significant digits.
Expand Down Expand Up @@ -55,21 +55,21 @@ impl Decimal {
///
/// In Python:
/// `-emin + p2 + math.floor((emin+ 1)*math.log(2, b)-math.log(1-2**(-p2), b))`
pub const MAX_DIGITS: usize = 768;
pub(super) const MAX_DIGITS: usize = 768;
/// The max digits that can be exactly represented in a 64-bit integer.
pub const MAX_DIGITS_WITHOUT_OVERFLOW: usize = 19;
pub const DECIMAL_POINT_RANGE: i32 = 2047;
pub(super) const MAX_DIGITS_WITHOUT_OVERFLOW: usize = 19;
pub(super) const DECIMAL_POINT_RANGE: i32 = 2047;

/// Append a digit to the buffer.
pub fn try_add_digit(&mut self, digit: u8) {
pub(super) fn try_add_digit(&mut self, digit: u8) {
if self.num_digits < Self::MAX_DIGITS {
self.digits[self.num_digits] = digit;
}
self.num_digits += 1;
}

/// Trim trailing zeros from the buffer.
pub fn trim(&mut self) {
pub(super) fn trim(&mut self) {
// All of the following calls to `Decimal::trim` can't panic because:
//
// 1. `parse_decimal` sets `num_digits` to a max of `Decimal::MAX_DIGITS`.
Expand All @@ -83,7 +83,7 @@ impl Decimal {
}
}

pub fn round(&self) -> u64 {
pub(super) fn round(&self) -> u64 {
if self.num_digits == 0 || self.decimal_point < 0 {
return 0;
} else if self.decimal_point > 18 {
Expand Down Expand Up @@ -111,7 +111,7 @@ impl Decimal {
}

/// Computes decimal * 2^shift.
pub fn left_shift(&mut self, shift: usize) {
pub(super) fn left_shift(&mut self, shift: usize) {
if self.num_digits == 0 {
return;
}
Expand Down Expand Up @@ -152,7 +152,7 @@ impl Decimal {
}

/// Computes decimal * 2^-shift.
pub fn right_shift(&mut self, shift: usize) {
pub(super) fn right_shift(&mut self, shift: usize) {
let mut read_index = 0;
let mut write_index = 0;
let mut n = 0_u64;
Expand Down Expand Up @@ -202,7 +202,7 @@ impl Decimal {
}

/// Parse a big integer representation of the float as a decimal.
pub fn parse_decimal(mut s: &[u8]) -> Decimal {
pub(super) fn parse_decimal(mut s: &[u8]) -> Decimal {
let mut d = Decimal::default();
let start = s;

Expand Down
8 changes: 4 additions & 4 deletions library/core/src/num/dec2flt/fpu.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Platform-specific, assembly instructions to avoid
//! intermediate rounding on architectures with FPUs.

pub use fpu_precision::set_precision;
pub(super) use fpu_precision::set_precision;

// On x86, the x87 FPU is used for float operations if the SSE/SSE2 extensions are not available.
// The x87 FPU operates with 80 bits of precision by default, which means that operations will
Expand Down Expand Up @@ -42,7 +42,7 @@ mod fpu_precision {
/// - 0b10, double precision i.e., 64-bits
/// - 0b11, double extended precision i.e., 80-bits (default state)
/// The 0b01 value is reserved and should not be used.
pub struct FPUControlWord(u16);
pub(crate) struct FPUControlWord(u16);

fn set_cw(cw: u16) {
// SAFETY: the `fldcw` instruction has been audited to be able to work correctly with
Expand All @@ -57,7 +57,7 @@ mod fpu_precision {
}

/// Sets the precision field of the FPU to `T` and returns a `FPUControlWord`.
pub fn set_precision<T>() -> FPUControlWord {
pub(crate) fn set_precision<T>() -> FPUControlWord {
let mut cw = 0_u16;

// Compute the value for the Precision Control field that is appropriate for `T`.
Expand Down Expand Up @@ -97,5 +97,5 @@ mod fpu_precision {
// precision of the computation is determined on a per-operation basis.
#[cfg(any(not(target_arch = "x86"), target_feature = "sse2"))]
mod fpu_precision {
pub fn set_precision<T>() {}
pub(crate) fn set_precision<T>() {}
}
9 changes: 5 additions & 4 deletions library/core/src/num/dec2flt/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@
//!
//! DO NOT MODIFY: Generated by `src/etc/dec2flt_table.py`

pub const SMALLEST_POWER_OF_FIVE: i32 = -342;
pub const LARGEST_POWER_OF_FIVE: i32 = 308;
pub const N_POWERS_OF_FIVE: usize = (LARGEST_POWER_OF_FIVE - SMALLEST_POWER_OF_FIVE + 1) as usize;
pub(super) const SMALLEST_POWER_OF_FIVE: i32 = -342;
pub(super) const LARGEST_POWER_OF_FIVE: i32 = 308;
pub(super) const N_POWERS_OF_FIVE: usize =
(LARGEST_POWER_OF_FIVE - SMALLEST_POWER_OF_FIVE + 1) as usize;

// Use static to avoid long compile times: Rust compiler errors
// can have the entire table compiled multiple times, and then
// emit code multiple times, even if it's stripped out in
// the final binary.
#[rustfmt::skip]
pub static POWER_OF_FIVE_128: [(u64, u64); N_POWERS_OF_FIVE] = [
pub(super) static POWER_OF_FIVE_128: [(u64, u64); N_POWERS_OF_FIVE] = [
(0xeef453d6923bd65a, 0x113faa2906a13b3f), // 5^-342
(0x9558b4661b6565f8, 0x4ac7ca59a424c507), // 5^-341
(0xbaaee17fa23ebf76, 0x5d79bcf00d2df649), // 5^-340
Expand Down
Loading
Loading