Skip to content

Commit

Permalink
Auto merge of rust-lang#135567 - jhpratt:rollup-eu4os4b, r=jhpratt
Browse files Browse the repository at this point in the history
Rollup of 5 pull requests

Successful merges:

 - rust-lang#134286 (Enable `unreachable_pub` lint in core)
 - rust-lang#135249 (Fix overflows in the implementation of `overflowing_literals` lint's help)
 - rust-lang#135534 (use indirect return for `i128` and `f128` on wasm32)
 - rust-lang#135556 (Clarify note in `std::sync::LazyLock` example)
 - rust-lang#135560 (Update `compiler-builtins` to 0.1.144)

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Jan 16, 2025
2 parents 5cd16b7 + 41e4601 commit 4dd5578
Show file tree
Hide file tree
Showing 37 changed files with 351 additions and 152 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ index 7165c3e48af..968552ad435 100644

[dependencies]
core = { path = "../core" }
-compiler_builtins = { version = "=0.1.143", features = ['rustc-dep-of-std'] }
+compiler_builtins = { version = "=0.1.143", features = ['rustc-dep-of-std', 'no-f16-f128'] }
-compiler_builtins = { version = "=0.1.144", features = ['rustc-dep-of-std'] }
+compiler_builtins = { version = "=0.1.144", features = ['rustc-dep-of-std', 'no-f16-f128'] }

[dev-dependencies]
rand = { version = "0.8.5", default-features = false, features = ["alloc"] }
Expand Down
31 changes: 23 additions & 8 deletions compiler/rustc_lint/src/types/literal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,20 +204,35 @@ fn get_type_suggestion(t: Ty<'_>, val: u128, negative: bool) -> Option<&'static
match t.kind() {
ty::Uint(ty::UintTy::Usize) | ty::Int(ty::IntTy::Isize) => None,
ty::Uint(_) => Some(Integer::fit_unsigned(val).uint_ty_str()),
ty::Int(_) if negative => Some(Integer::fit_signed(-(val as i128)).int_ty_str()),
ty::Int(int) => {
let signed = Integer::fit_signed(val as i128);
let unsigned = Integer::fit_unsigned(val);
Some(if Some(unsigned.size().bits()) == int.bit_width() {
unsigned.uint_ty_str()
ty::Int(_) => {
let signed = literal_to_i128(val, negative).map(Integer::fit_signed);
if negative {
signed.map(Integer::int_ty_str)
} else {
signed.int_ty_str()
})
let unsigned = Integer::fit_unsigned(val);
Some(if let Some(signed) = signed {
if unsigned.size() < signed.size() {
unsigned.uint_ty_str()
} else {
signed.int_ty_str()
}
} else {
unsigned.uint_ty_str()
})
}
}
_ => None,
}
}

fn literal_to_i128(val: u128, negative: bool) -> Option<i128> {
if negative {
(val <= i128::MAX as u128 + 1).then(|| val.wrapping_neg() as i128)
} else {
val.try_into().ok()
}
}

fn lint_int_literal<'tcx>(
cx: &LateContext<'tcx>,
type_limits: &TypeLimits,
Expand Down
12 changes: 12 additions & 0 deletions compiler/rustc_target/src/callconv/wasm.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use rustc_abi::{BackendRepr, Float, Integer, Primitive};

use crate::abi::call::{ArgAbi, FnAbi};
use crate::abi::{HasDataLayout, TyAbiInterface};

Expand Down Expand Up @@ -27,6 +29,16 @@ where
if ret.layout.is_aggregate() && !unwrap_trivial_aggregate(cx, ret) {
ret.make_indirect();
}

// `long double`, `__int128_t` and `__uint128_t` use an indirect return
if let BackendRepr::Scalar(scalar) = ret.layout.backend_repr {
match scalar.primitive() {
Primitive::Int(Integer::I128, _) | Primitive::Float(Float::F128) => {
ret.make_indirect();
}
_ => {}
}
}
}

fn classify_arg<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>)
Expand Down
4 changes: 2 additions & 2 deletions library/Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ dependencies = [

[[package]]
name = "compiler_builtins"
version = "0.1.143"
version = "0.1.144"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c85ba2077e3eab3dd81be4ece6b7fb2ad0887c1fb813e9a45400baf75c6c7c29"
checksum = "d18a7b7b5a56aa131e62314b4d862c9f6aa2860f615f3770094ec9064d7ec572"
dependencies = [
"cc",
"rustc-std-workspace-core",
Expand Down
2 changes: 1 addition & 1 deletion library/alloc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ edition = "2021"

[dependencies]
core = { path = "../core" }
compiler_builtins = { version = "=0.1.143", features = ['rustc-dep-of-std'] }
compiler_builtins = { version = "=0.1.144", features = ['rustc-dep-of-std'] }

[dev-dependencies]
rand = { version = "0.8.5", default-features = false, features = ["alloc"] }
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
)]
#[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
6 changes: 3 additions & 3 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 @@ -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

0 comments on commit 4dd5578

Please sign in to comment.