Skip to content

Commit b7f7e50

Browse files
committed
Auto merge of rust-lang#95223 - Dylan-DPC:rollup-idpb7ka, r=Dylan-DPC
Rollup of 6 pull requests Successful merges: - rust-lang#91608 (Fold aarch64 feature +fp into +neon) - rust-lang#92955 (add perf side effect docs to `Iterator::cloned()`) - rust-lang#94713 (Add u16::is_utf16_surrogate) - rust-lang#95212 (Replace `this.clone()` with `this.create_snapshot_for_diagnostic()`) - rust-lang#95219 (Modernize `alloc-no-oom-handling` test) - rust-lang#95222 (interpret/validity: improve clarity) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents aaf2c55 + dcc3c17 commit b7f7e50

File tree

5 files changed

+46
-4
lines changed

5 files changed

+46
-4
lines changed

core/src/char/decode.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ impl<I: Iterator<Item = u16>> Iterator for DecodeUtf16<I> {
9191
None => self.iter.next()?,
9292
};
9393

94-
if u < 0xD800 || 0xDFFF < u {
94+
if !u.is_utf16_surrogate() {
9595
// SAFETY: not a surrogate
9696
Some(Ok(unsafe { from_u32_unchecked(u as u32) }))
9797
} else if u >= 0xDC00 {
@@ -125,7 +125,7 @@ impl<I: Iterator<Item = u16>> Iterator for DecodeUtf16<I> {
125125
// buf is empty, no additional elements from it.
126126
None => (0, 0),
127127
// `u` is a non surrogate, so it's always an additional character.
128-
Some(u) if u < 0xD800 || 0xDFFF < u => (1, 1),
128+
Some(u) if !u.is_utf16_surrogate() => (1, 1),
129129
// `u` is a leading surrogate (it can never be a trailing surrogate and
130130
// it's a surrogate due to the previous branch) and `self.iter` is empty.
131131
//

core/src/iter/traits/iterator.rs

+16
Original file line numberDiff line numberDiff line change
@@ -3189,6 +3189,10 @@ pub trait Iterator {
31893189
/// This is useful when you have an iterator over `&T`, but you need an
31903190
/// iterator over `T`.
31913191
///
3192+
/// There is no guarantee whatsoever about the `clone` method actually
3193+
/// being called *or* optimized away. So code should not depend on
3194+
/// either.
3195+
///
31923196
/// [`clone`]: Clone::clone
31933197
///
31943198
/// # Examples
@@ -3206,6 +3210,18 @@ pub trait Iterator {
32063210
/// assert_eq!(v_cloned, vec![1, 2, 3]);
32073211
/// assert_eq!(v_map, vec![1, 2, 3]);
32083212
/// ```
3213+
///
3214+
/// To get the best performance, try to clone late:
3215+
///
3216+
/// ```
3217+
/// let a = [vec![0_u8, 1, 2], vec![3, 4], vec![23]];
3218+
/// // don't do this:
3219+
/// let slower: Vec<_> = a.iter().cloned().filter(|s| s.len() == 1).collect();
3220+
/// assert_eq!(&[vec![23]], &slower[..]);
3221+
/// // instead call `cloned` late
3222+
/// let faster: Vec<_> = a.iter().filter(|s| s.len() == 1).cloned().collect();
3223+
/// assert_eq!(&[vec![23]], &faster[..]);
3224+
/// ```
32093225
#[stable(feature = "rust1", since = "1.0.0")]
32103226
fn cloned<'a, T: 'a>(self) -> Cloned<Self>
32113227
where

core/src/lib.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393
#![warn(missing_docs)]
9494
#![allow(explicit_outlives_requirements)]
9595
//
96-
// Library features for const fns:
96+
// Library features:
9797
#![feature(const_align_offset)]
9898
#![feature(const_align_of_val)]
9999
#![feature(const_alloc_layout)]
@@ -146,6 +146,8 @@
146146
#![feature(ptr_metadata)]
147147
#![feature(slice_ptr_get)]
148148
#![feature(str_internals)]
149+
#![feature(utf16_extra)]
150+
#![feature(utf16_extra_const)]
149151
#![feature(variant_count)]
150152
#![feature(const_array_from_ref)]
151153
#![feature(const_slice_from_ref)]

core/src/num/mod.rs

+25
Original file line numberDiff line numberDiff line change
@@ -820,6 +820,31 @@ impl u16 {
820820
uint_impl! { u16, u16, i16, NonZeroU16, 16, 65535, 4, "0xa003", "0x3a", "0x1234", "0x3412", "0x2c48",
821821
"[0x34, 0x12]", "[0x12, 0x34]", "", "" }
822822
widening_impl! { u16, u32, 16, unsigned }
823+
824+
/// Checks if the value is a Unicode surrogate code point, which are disallowed values for [`char`].
825+
///
826+
/// # Examples
827+
///
828+
/// ```
829+
/// #![feature(utf16_extra)]
830+
///
831+
/// let low_non_surrogate = 0xA000u16;
832+
/// let low_surrogate = 0xD800u16;
833+
/// let high_surrogate = 0xDC00u16;
834+
/// let high_non_surrogate = 0xE000u16;
835+
///
836+
/// assert!(!low_non_surrogate.is_utf16_surrogate());
837+
/// assert!(low_surrogate.is_utf16_surrogate());
838+
/// assert!(high_surrogate.is_utf16_surrogate());
839+
/// assert!(!high_non_surrogate.is_utf16_surrogate());
840+
/// ```
841+
#[must_use]
842+
#[unstable(feature = "utf16_extra", issue = "94919")]
843+
#[rustc_const_unstable(feature = "utf16_extra_const", issue = "94919")]
844+
#[inline]
845+
pub const fn is_utf16_surrogate(self) -> bool {
846+
matches!(self, 0xD800..=0xDFFF)
847+
}
823848
}
824849

825850
#[lang = "u32"]

std/tests/run-time-detect.rs

-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ fn aarch64_linux() {
2929
println!("neon: {}", is_aarch64_feature_detected!("neon"));
3030
println!("asimd: {}", is_aarch64_feature_detected!("asimd"));
3131
println!("pmull: {}", is_aarch64_feature_detected!("pmull"));
32-
println!("fp: {}", is_aarch64_feature_detected!("fp"));
3332
println!("fp16: {}", is_aarch64_feature_detected!("fp16"));
3433
println!("sve: {}", is_aarch64_feature_detected!("sve"));
3534
println!("crc: {}", is_aarch64_feature_detected!("crc"));

0 commit comments

Comments
 (0)