Skip to content

Commit b3261df

Browse files
committed
Auto merge of rust-lang#94174 - matthiaskrgr:rollup-snyrlhy, r=matthiaskrgr
Rollup of 14 pull requests Successful merges: - rust-lang#93580 (Stabilize pin_static_ref.) - rust-lang#93639 (Release notes for 1.59) - rust-lang#93686 (core: Implement ASCII trim functions on byte slices) - rust-lang#94002 (rustdoc: Avoid duplicating macros in sidebar) - rust-lang#94019 (removing architecture requirements for RustyHermit) - rust-lang#94023 (adapt static-nobundle test to use llvm-nm) - rust-lang#94091 (Fix rustdoc const computed value) - rust-lang#94093 (Fix pretty printing of enums without variants) - rust-lang#94097 (Add module-level docs for `rustc_middle::query`) - rust-lang#94112 (Optimize char_try_from_u32) - rust-lang#94113 (document rustc_middle::mir::Field) - rust-lang#94122 (Fix miniz_oxide types showing up in std docs) - rust-lang#94142 (rustc_typeck: adopt let else in more places) - rust-lang#94146 (Adopt let else in more places) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 4b4f53f + 61f6664 commit b3261df

File tree

6 files changed

+101
-9
lines changed

6 files changed

+101
-9
lines changed

core/src/char/convert.rs

+14-3
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ use crate::fmt;
66
use crate::mem::transmute;
77
use crate::str::FromStr;
88

9-
use super::MAX;
10-
119
/// Converts a `u32` to a `char`.
1210
///
1311
/// Note that all [`char`]s are valid [`u32`]s, and can be cast to one with
@@ -271,7 +269,20 @@ impl FromStr for char {
271269

272270
#[inline]
273271
const fn char_try_from_u32(i: u32) -> Result<char, CharTryFromError> {
274-
if (i > MAX as u32) || (i >= 0xD800 && i <= 0xDFFF) {
272+
// This is an optimized version of the check
273+
// (i > MAX as u32) || (i >= 0xD800 && i <= 0xDFFF),
274+
// which can also be written as
275+
// i >= 0x110000 || (i >= 0xD800 && i < 0xE000).
276+
//
277+
// The XOR with 0xD800 permutes the ranges such that 0xD800..0xE000 is
278+
// mapped to 0x0000..0x0800, while keeping all the high bits outside 0xFFFF the same.
279+
// In particular, numbers >= 0x110000 stay in this range.
280+
//
281+
// Subtracting 0x800 causes 0x0000..0x0800 to wrap, meaning that a single
282+
// unsigned comparison against 0x110000 - 0x800 will detect both the wrapped
283+
// surrogate range as well as the numbers originally larger than 0x110000.
284+
//
285+
if (i ^ 0xD800).wrapping_sub(0x800) >= 0x110000 - 0x800 {
275286
Err(CharTryFromError(()))
276287
} else {
277288
// SAFETY: checked that it's a legal unicode value

core/src/pin.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -805,7 +805,7 @@ impl<T: ?Sized> Pin<&'static T> {
805805
///
806806
/// This is safe, because `T` is borrowed for the `'static` lifetime, which
807807
/// never ends.
808-
#[unstable(feature = "pin_static_ref", issue = "78186")]
808+
#[stable(feature = "pin_static_ref", since = "1.60.0")]
809809
#[rustc_const_unstable(feature = "const_pin", issue = "76654")]
810810
pub const fn static_ref(r: &'static T) -> Pin<&'static T> {
811811
// SAFETY: The 'static borrow guarantees the data will not be
@@ -858,7 +858,7 @@ impl<T: ?Sized> Pin<&'static mut T> {
858858
///
859859
/// This is safe, because `T` is borrowed for the `'static` lifetime, which
860860
/// never ends.
861-
#[unstable(feature = "pin_static_ref", issue = "78186")]
861+
#[stable(feature = "pin_static_ref", since = "1.60.0")]
862862
#[rustc_const_unstable(feature = "const_pin", issue = "76654")]
863863
pub const fn static_mut(r: &'static mut T) -> Pin<&'static mut T> {
864864
// SAFETY: The 'static borrow guarantees the data will not be

core/src/slice/ascii.rs

+78
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,84 @@ impl [u8] {
7979
pub fn escape_ascii(&self) -> EscapeAscii<'_> {
8080
EscapeAscii { inner: self.iter().flat_map(EscapeByte) }
8181
}
82+
83+
/// Returns a byte slice with leading ASCII whitespace bytes removed.
84+
///
85+
/// 'Whitespace' refers to the definition used by
86+
/// `u8::is_ascii_whitespace`.
87+
///
88+
/// # Examples
89+
///
90+
/// ```
91+
/// #![feature(byte_slice_trim_ascii)]
92+
///
93+
/// assert_eq!(b" \t hello world\n".trim_ascii_start(), b"hello world\n");
94+
/// assert_eq!(b" ".trim_ascii_start(), b"");
95+
/// assert_eq!(b"".trim_ascii_start(), b"");
96+
/// ```
97+
#[unstable(feature = "byte_slice_trim_ascii", issue = "94035")]
98+
pub const fn trim_ascii_start(&self) -> &[u8] {
99+
let mut bytes = self;
100+
// Note: A pattern matching based approach (instead of indexing) allows
101+
// making the function const.
102+
while let [first, rest @ ..] = bytes {
103+
if first.is_ascii_whitespace() {
104+
bytes = rest;
105+
} else {
106+
break;
107+
}
108+
}
109+
bytes
110+
}
111+
112+
/// Returns a byte slice with trailing ASCII whitespace bytes removed.
113+
///
114+
/// 'Whitespace' refers to the definition used by
115+
/// `u8::is_ascii_whitespace`.
116+
///
117+
/// # Examples
118+
///
119+
/// ```
120+
/// #![feature(byte_slice_trim_ascii)]
121+
///
122+
/// assert_eq!(b"\r hello world\n ".trim_ascii_end(), b"\r hello world");
123+
/// assert_eq!(b" ".trim_ascii_end(), b"");
124+
/// assert_eq!(b"".trim_ascii_end(), b"");
125+
/// ```
126+
#[unstable(feature = "byte_slice_trim_ascii", issue = "94035")]
127+
pub const fn trim_ascii_end(&self) -> &[u8] {
128+
let mut bytes = self;
129+
// Note: A pattern matching based approach (instead of indexing) allows
130+
// making the function const.
131+
while let [rest @ .., last] = bytes {
132+
if last.is_ascii_whitespace() {
133+
bytes = rest;
134+
} else {
135+
break;
136+
}
137+
}
138+
bytes
139+
}
140+
141+
/// Returns a byte slice with leading and trailing ASCII whitespace bytes
142+
/// removed.
143+
///
144+
/// 'Whitespace' refers to the definition used by
145+
/// `u8::is_ascii_whitespace`.
146+
///
147+
/// # Examples
148+
///
149+
/// ```
150+
/// #![feature(byte_slice_trim_ascii)]
151+
///
152+
/// assert_eq!(b"\r hello world\n ".trim_ascii(), b"hello world");
153+
/// assert_eq!(b" ".trim_ascii(), b"");
154+
/// assert_eq!(b"".trim_ascii(), b"");
155+
/// ```
156+
#[unstable(feature = "byte_slice_trim_ascii", issue = "94035")]
157+
pub const fn trim_ascii(&self) -> &[u8] {
158+
self.trim_ascii_start().trim_ascii_end()
159+
}
82160
}
83161

84162
impl_fn_for_zst! {

std/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ dlmalloc = { version = "0.2.3", features = ['rustc-dep-of-std'] }
4141
[target.x86_64-fortanix-unknown-sgx.dependencies]
4242
fortanix-sgx-abi = { version = "0.3.2", features = ['rustc-dep-of-std'] }
4343

44-
[target.'cfg(all(any(target_arch = "x86_64", target_arch = "aarch64"), target_os = "hermit"))'.dependencies]
45-
hermit-abi = { version = "0.1.19", features = ['rustc-dep-of-std'] }
44+
[target.'cfg(target_os = "hermit")'.dependencies]
45+
hermit-abi = { version = "0.2.0", features = ['rustc-dep-of-std'] }
4646

4747
[target.wasm32-wasi.dependencies]
4848
wasi = { version = "0.11.0", features = ['rustc-dep-of-std'], default-features = false }

std/src/lib.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,6 @@
311311
#![feature(panic_internals)]
312312
#![feature(panic_can_unwind)]
313313
#![feature(panic_unwind)]
314-
#![feature(pin_static_ref)]
315314
#![feature(platform_intrinsics)]
316315
#![feature(portable_simd)]
317316
#![feature(prelude_import)]
@@ -365,6 +364,10 @@ extern crate libc;
365364
#[allow(unused_extern_crates)]
366365
extern crate unwind;
367366

367+
#[doc(masked)]
368+
#[allow(unused_extern_crates)]
369+
extern crate miniz_oxide;
370+
368371
// During testing, this crate is not actually the "real" std library, but rather
369372
// it links to the real std library, which was compiled from this same source
370373
// code. So any lang items std defines are conditionally excluded (or else they

std/src/sys/hermit/fd.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#![unstable(reason = "not public", issue = "none", feature = "fd")]
22

3-
use crate::io::{self, Read, ReadBuf};
3+
use crate::io::{self, Read};
44
use crate::mem;
55
use crate::sys::cvt;
66
use crate::sys::hermit::abi;

0 commit comments

Comments
 (0)