Skip to content

Commit 4dd5578

Browse files
committed
Auto merge of rust-lang#135567 - jhpratt:rollup-eu4os4b, r=jhpratt
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
2 parents 5cd16b7 + 41e4601 commit 4dd5578

37 files changed

+351
-152
lines changed

compiler/rustc_codegen_cranelift/patches/0029-stdlib-Disable-f16-and-f128-in-compiler-builtins.patch

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ index 7165c3e48af..968552ad435 100644
1616

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

2222
[dev-dependencies]
2323
rand = { version = "0.8.5", default-features = false, features = ["alloc"] }

compiler/rustc_lint/src/types/literal.rs

+23-8
Original file line numberDiff line numberDiff line change
@@ -204,20 +204,35 @@ fn get_type_suggestion(t: Ty<'_>, val: u128, negative: bool) -> Option<&'static
204204
match t.kind() {
205205
ty::Uint(ty::UintTy::Usize) | ty::Int(ty::IntTy::Isize) => None,
206206
ty::Uint(_) => Some(Integer::fit_unsigned(val).uint_ty_str()),
207-
ty::Int(_) if negative => Some(Integer::fit_signed(-(val as i128)).int_ty_str()),
208-
ty::Int(int) => {
209-
let signed = Integer::fit_signed(val as i128);
210-
let unsigned = Integer::fit_unsigned(val);
211-
Some(if Some(unsigned.size().bits()) == int.bit_width() {
212-
unsigned.uint_ty_str()
207+
ty::Int(_) => {
208+
let signed = literal_to_i128(val, negative).map(Integer::fit_signed);
209+
if negative {
210+
signed.map(Integer::int_ty_str)
213211
} else {
214-
signed.int_ty_str()
215-
})
212+
let unsigned = Integer::fit_unsigned(val);
213+
Some(if let Some(signed) = signed {
214+
if unsigned.size() < signed.size() {
215+
unsigned.uint_ty_str()
216+
} else {
217+
signed.int_ty_str()
218+
}
219+
} else {
220+
unsigned.uint_ty_str()
221+
})
222+
}
216223
}
217224
_ => None,
218225
}
219226
}
220227

228+
fn literal_to_i128(val: u128, negative: bool) -> Option<i128> {
229+
if negative {
230+
(val <= i128::MAX as u128 + 1).then(|| val.wrapping_neg() as i128)
231+
} else {
232+
val.try_into().ok()
233+
}
234+
}
235+
221236
fn lint_int_literal<'tcx>(
222237
cx: &LateContext<'tcx>,
223238
type_limits: &TypeLimits,

compiler/rustc_target/src/callconv/wasm.rs

+12
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use rustc_abi::{BackendRepr, Float, Integer, Primitive};
2+
13
use crate::abi::call::{ArgAbi, FnAbi};
24
use crate::abi::{HasDataLayout, TyAbiInterface};
35

@@ -27,6 +29,16 @@ where
2729
if ret.layout.is_aggregate() && !unwrap_trivial_aggregate(cx, ret) {
2830
ret.make_indirect();
2931
}
32+
33+
// `long double`, `__int128_t` and `__uint128_t` use an indirect return
34+
if let BackendRepr::Scalar(scalar) = ret.layout.backend_repr {
35+
match scalar.primitive() {
36+
Primitive::Int(Integer::I128, _) | Primitive::Float(Float::F128) => {
37+
ret.make_indirect();
38+
}
39+
_ => {}
40+
}
41+
}
3042
}
3143

3244
fn classify_arg<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>)

library/Cargo.lock

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ dependencies = [
6161

6262
[[package]]
6363
name = "compiler_builtins"
64-
version = "0.1.143"
64+
version = "0.1.144"
6565
source = "registry+https://github.com/rust-lang/crates.io-index"
66-
checksum = "c85ba2077e3eab3dd81be4ece6b7fb2ad0887c1fb813e9a45400baf75c6c7c29"
66+
checksum = "d18a7b7b5a56aa131e62314b4d862c9f6aa2860f615f3770094ec9064d7ec572"
6767
dependencies = [
6868
"cc",
6969
"rustc-std-workspace-core",

library/alloc/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ edition = "2021"
1010

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

1515
[dev-dependencies]
1616
rand = { version = "0.8.5", default-features = false, features = ["alloc"] }

library/core/src/array/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -893,7 +893,7 @@ impl<T> Guard<'_, T> {
893893
///
894894
/// No more than N elements must be initialized.
895895
#[inline]
896-
pub unsafe fn push_unchecked(&mut self, item: T) {
896+
pub(crate) unsafe fn push_unchecked(&mut self, item: T) {
897897
// SAFETY: If `initialized` was correct before and the caller does not
898898
// invoke this method more than N times then writes will be in-bounds
899899
// and slots will not be initialized more than once.

library/core/src/escape.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -163,63 +163,63 @@ pub(crate) struct EscapeIterInner<const N: usize> {
163163
}
164164

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

171-
pub const fn ascii(c: u8) -> Self {
171+
pub(crate) const fn ascii(c: u8) -> Self {
172172
let (data, range) = escape_ascii(c);
173173
Self { data, alive: range }
174174
}
175175

176-
pub const fn unicode(c: char) -> Self {
176+
pub(crate) const fn unicode(c: char) -> Self {
177177
let (data, range) = escape_unicode(c);
178178
Self { data, alive: range }
179179
}
180180

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

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

194194
#[inline]
195-
pub fn as_str(&self) -> &str {
195+
pub(crate) fn as_str(&self) -> &str {
196196
self.as_ascii().as_str()
197197
}
198198

199199
#[inline]
200-
pub fn len(&self) -> usize {
200+
pub(crate) fn len(&self) -> usize {
201201
usize::from(self.alive.end - self.alive.start)
202202
}
203203

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

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

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

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

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

222-
pub fn advance_back_by(&mut self, n: usize) -> Result<(), NonZero<usize>> {
222+
pub(crate) fn advance_back_by(&mut self, n: usize) -> Result<(), NonZero<usize>> {
223223
self.alive.advance_back_by(n)
224224
}
225225
}

library/core/src/ffi/mod.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -172,35 +172,35 @@ mod c_char_definition {
172172
target_arch = "xtensa",
173173
)
174174
))] {
175-
pub type c_char = u8;
175+
pub(super) type c_char = u8;
176176
} else {
177177
// On every other target, c_char is signed.
178-
pub type c_char = i8;
178+
pub(super) type c_char = i8;
179179
}
180180
}
181181
}
182182

183183
mod c_int_definition {
184184
cfg_if! {
185185
if #[cfg(any(target_arch = "avr", target_arch = "msp430"))] {
186-
pub type c_int = i16;
187-
pub type c_uint = u16;
186+
pub(super) type c_int = i16;
187+
pub(super) type c_uint = u16;
188188
} else {
189-
pub type c_int = i32;
190-
pub type c_uint = u32;
189+
pub(super) type c_int = i32;
190+
pub(super) type c_uint = u32;
191191
}
192192
}
193193
}
194194

195195
mod c_long_definition {
196196
cfg_if! {
197197
if #[cfg(all(target_pointer_width = "64", not(windows)))] {
198-
pub type c_long = i64;
199-
pub type c_ulong = u64;
198+
pub(super) type c_long = i64;
199+
pub(super) type c_ulong = u64;
200200
} else {
201201
// The minimal size of `long` in the C standard is 32 bits
202-
pub type c_long = i32;
203-
pub type c_ulong = u32;
202+
pub(super) type c_long = i32;
203+
pub(super) type c_ulong = u32;
204204
}
205205
}
206206
}

library/core/src/lib.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@
101101
#![warn(multiple_supertrait_upcastable)]
102102
#![allow(internal_features)]
103103
#![deny(ffi_unwind_calls)]
104+
#![warn(unreachable_pub)]
104105
// Do not check link redundancy on bootstraping phase
105106
#![allow(rustdoc::redundant_explicit_links)]
106107
#![warn(rustdoc::unescaped_backticks)]
@@ -396,7 +397,8 @@ pub mod primitive;
396397
unused_imports,
397398
unsafe_op_in_unsafe_fn,
398399
ambiguous_glob_reexports,
399-
deprecated_in_future
400+
deprecated_in_future,
401+
unreachable_pub
400402
)]
401403
#[allow(rustdoc::bare_urls)]
402404
mod core_arch;

library/core/src/net/display_buffer.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@ use crate::mem::MaybeUninit;
22
use crate::{fmt, str};
33

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

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

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

library/core/src/num/dec2flt/decimal.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
use crate::num::dec2flt::common::{ByteSlice, is_8digits};
1313

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

6363
/// Append a digit to the buffer.
64-
pub fn try_add_digit(&mut self, digit: u8) {
64+
pub(super) fn try_add_digit(&mut self, digit: u8) {
6565
if self.num_digits < Self::MAX_DIGITS {
6666
self.digits[self.num_digits] = digit;
6767
}
6868
self.num_digits += 1;
6969
}
7070

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

86-
pub fn round(&self) -> u64 {
86+
pub(super) fn round(&self) -> u64 {
8787
if self.num_digits == 0 || self.decimal_point < 0 {
8888
return 0;
8989
} else if self.decimal_point > 18 {
@@ -111,7 +111,7 @@ impl Decimal {
111111
}
112112

113113
/// Computes decimal * 2^shift.
114-
pub fn left_shift(&mut self, shift: usize) {
114+
pub(super) fn left_shift(&mut self, shift: usize) {
115115
if self.num_digits == 0 {
116116
return;
117117
}
@@ -152,7 +152,7 @@ impl Decimal {
152152
}
153153

154154
/// Computes decimal * 2^-shift.
155-
pub fn right_shift(&mut self, shift: usize) {
155+
pub(super) fn right_shift(&mut self, shift: usize) {
156156
let mut read_index = 0;
157157
let mut write_index = 0;
158158
let mut n = 0_u64;
@@ -202,7 +202,7 @@ impl Decimal {
202202
}
203203

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

library/core/src/num/dec2flt/fpu.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Platform-specific, assembly instructions to avoid
22
//! intermediate rounding on architectures with FPUs.
33
4-
pub use fpu_precision::set_precision;
4+
pub(super) use fpu_precision::set_precision;
55

66
// On x86, the x87 FPU is used for float operations if the SSE/SSE2 extensions are not available.
77
// The x87 FPU operates with 80 bits of precision by default, which means that operations will
@@ -57,7 +57,7 @@ mod fpu_precision {
5757
}
5858

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

6363
// Compute the value for the Precision Control field that is appropriate for `T`.
@@ -97,5 +97,5 @@ mod fpu_precision {
9797
// precision of the computation is determined on a per-operation basis.
9898
#[cfg(any(not(target_arch = "x86"), target_feature = "sse2"))]
9999
mod fpu_precision {
100-
pub fn set_precision<T>() {}
100+
pub(crate) fn set_precision<T>() {}
101101
}

library/core/src/num/dec2flt/table.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,17 @@
66
//!
77
//! DO NOT MODIFY: Generated by `src/etc/dec2flt_table.py`
88
9-
pub const SMALLEST_POWER_OF_FIVE: i32 = -342;
10-
pub const LARGEST_POWER_OF_FIVE: i32 = 308;
11-
pub const N_POWERS_OF_FIVE: usize = (LARGEST_POWER_OF_FIVE - SMALLEST_POWER_OF_FIVE + 1) as usize;
9+
pub(super) const SMALLEST_POWER_OF_FIVE: i32 = -342;
10+
pub(super) const LARGEST_POWER_OF_FIVE: i32 = 308;
11+
pub(super) const N_POWERS_OF_FIVE: usize =
12+
(LARGEST_POWER_OF_FIVE - SMALLEST_POWER_OF_FIVE + 1) as usize;
1213

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

0 commit comments

Comments
 (0)