Skip to content

Commit 4dd5578

Browse files
committed
Auto merge of #135567 - jhpratt:rollup-eu4os4b, r=jhpratt
Rollup of 5 pull requests Successful merges: - #134286 (Enable `unreachable_pub` lint in core) - #135249 (Fix overflows in the implementation of `overflowing_literals` lint's help) - #135534 (use indirect return for `i128` and `f128` on wasm32) - #135556 (Clarify note in `std::sync::LazyLock` example) - #135560 (Update `compiler-builtins` to 0.1.144) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 5cd16b7 + 41e4601 commit 4dd5578

File tree

37 files changed

+351
-152
lines changed

37 files changed

+351
-152
lines changed

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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 23 additions & 8 deletions
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

Lines changed: 12 additions & 0 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 11 additions & 11 deletions
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

Lines changed: 10 additions & 10 deletions
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

Lines changed: 3 additions & 1 deletion
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

Lines changed: 3 additions & 3 deletions
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 {

0 commit comments

Comments
 (0)