diff options
| author | bors <bors@rust-lang.org> | 2022-03-23 03:31:20 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-03-23 03:31:20 +0000 |
| commit | 7b0bf9efc939341b48c6e9a335dee8a280085100 (patch) | |
| tree | 8daa45d4c70bfbd9213d6a04908ff8eb43f130df /library | |
| parent | 2b50739b4978936750a0c8de404ff184e49114f9 (diff) | |
| parent | 2f24923ab3f38e33a2ad98618852e0089d63ba7d (diff) | |
| download | rust-7b0bf9efc939341b48c6e9a335dee8a280085100.tar.gz rust-7b0bf9efc939341b48c6e9a335dee8a280085100.zip | |
Auto merge of #95223 - Dylan-DPC:rollup-idpb7ka, r=Dylan-DPC
Rollup of 6 pull requests Successful merges: - #91608 (Fold aarch64 feature +fp into +neon) - #92955 (add perf side effect docs to `Iterator::cloned()`) - #94713 (Add u16::is_utf16_surrogate) - #95212 (Replace `this.clone()` with `this.create_snapshot_for_diagnostic()`) - #95219 (Modernize `alloc-no-oom-handling` test) - #95222 (interpret/validity: improve clarity) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Diffstat (limited to 'library')
| -rw-r--r-- | library/core/src/char/decode.rs | 4 | ||||
| -rw-r--r-- | library/core/src/iter/traits/iterator.rs | 16 | ||||
| -rw-r--r-- | library/core/src/lib.rs | 4 | ||||
| -rw-r--r-- | library/core/src/num/mod.rs | 25 | ||||
| -rw-r--r-- | library/std/tests/run-time-detect.rs | 1 |
5 files changed, 46 insertions, 4 deletions
diff --git a/library/core/src/char/decode.rs b/library/core/src/char/decode.rs index 8b9f979b573..794c9c13cc3 100644 --- a/library/core/src/char/decode.rs +++ b/library/core/src/char/decode.rs @@ -91,7 +91,7 @@ impl<I: Iterator<Item = u16>> Iterator for DecodeUtf16<I> { None => self.iter.next()?, }; - if u < 0xD800 || 0xDFFF < u { + if !u.is_utf16_surrogate() { // SAFETY: not a surrogate Some(Ok(unsafe { from_u32_unchecked(u as u32) })) } else if u >= 0xDC00 { @@ -125,7 +125,7 @@ impl<I: Iterator<Item = u16>> Iterator for DecodeUtf16<I> { // buf is empty, no additional elements from it. None => (0, 0), // `u` is a non surrogate, so it's always an additional character. - Some(u) if u < 0xD800 || 0xDFFF < u => (1, 1), + Some(u) if !u.is_utf16_surrogate() => (1, 1), // `u` is a leading surrogate (it can never be a trailing surrogate and // it's a surrogate due to the previous branch) and `self.iter` is empty. // diff --git a/library/core/src/iter/traits/iterator.rs b/library/core/src/iter/traits/iterator.rs index b62e8dfe1d6..53fbe4cbc42 100644 --- a/library/core/src/iter/traits/iterator.rs +++ b/library/core/src/iter/traits/iterator.rs @@ -3189,6 +3189,10 @@ pub trait Iterator { /// This is useful when you have an iterator over `&T`, but you need an /// iterator over `T`. /// + /// There is no guarantee whatsoever about the `clone` method actually + /// being called *or* optimized away. So code should not depend on + /// either. + /// /// [`clone`]: Clone::clone /// /// # Examples @@ -3206,6 +3210,18 @@ pub trait Iterator { /// assert_eq!(v_cloned, vec![1, 2, 3]); /// assert_eq!(v_map, vec![1, 2, 3]); /// ``` + /// + /// To get the best performance, try to clone late: + /// + /// ``` + /// let a = [vec![0_u8, 1, 2], vec![3, 4], vec![23]]; + /// // don't do this: + /// let slower: Vec<_> = a.iter().cloned().filter(|s| s.len() == 1).collect(); + /// assert_eq!(&[vec![23]], &slower[..]); + /// // instead call `cloned` late + /// let faster: Vec<_> = a.iter().filter(|s| s.len() == 1).cloned().collect(); + /// assert_eq!(&[vec![23]], &faster[..]); + /// ``` #[stable(feature = "rust1", since = "1.0.0")] fn cloned<'a, T: 'a>(self) -> Cloned<Self> where diff --git a/library/core/src/lib.rs b/library/core/src/lib.rs index 0860e1bf4ca..1a85e2ef7b6 100644 --- a/library/core/src/lib.rs +++ b/library/core/src/lib.rs @@ -93,7 +93,7 @@ #![warn(missing_docs)] #![allow(explicit_outlives_requirements)] // -// Library features for const fns: +// Library features: #![feature(const_align_offset)] #![feature(const_align_of_val)] #![feature(const_alloc_layout)] @@ -146,6 +146,8 @@ #![feature(ptr_metadata)] #![feature(slice_ptr_get)] #![feature(str_internals)] +#![feature(utf16_extra)] +#![feature(utf16_extra_const)] #![feature(variant_count)] #![feature(const_array_from_ref)] #![feature(const_slice_from_ref)] diff --git a/library/core/src/num/mod.rs b/library/core/src/num/mod.rs index 07fd317e074..dca8ffa4e2c 100644 --- a/library/core/src/num/mod.rs +++ b/library/core/src/num/mod.rs @@ -820,6 +820,31 @@ impl u16 { uint_impl! { u16, u16, i16, NonZeroU16, 16, 65535, 4, "0xa003", "0x3a", "0x1234", "0x3412", "0x2c48", "[0x34, 0x12]", "[0x12, 0x34]", "", "" } widening_impl! { u16, u32, 16, unsigned } + + /// Checks if the value is a Unicode surrogate code point, which are disallowed values for [`char`]. + /// + /// # Examples + /// + /// ``` + /// #![feature(utf16_extra)] + /// + /// let low_non_surrogate = 0xA000u16; + /// let low_surrogate = 0xD800u16; + /// let high_surrogate = 0xDC00u16; + /// let high_non_surrogate = 0xE000u16; + /// + /// assert!(!low_non_surrogate.is_utf16_surrogate()); + /// assert!(low_surrogate.is_utf16_surrogate()); + /// assert!(high_surrogate.is_utf16_surrogate()); + /// assert!(!high_non_surrogate.is_utf16_surrogate()); + /// ``` + #[must_use] + #[unstable(feature = "utf16_extra", issue = "94919")] + #[rustc_const_unstable(feature = "utf16_extra_const", issue = "94919")] + #[inline] + pub const fn is_utf16_surrogate(self) -> bool { + matches!(self, 0xD800..=0xDFFF) + } } #[lang = "u32"] diff --git a/library/std/tests/run-time-detect.rs b/library/std/tests/run-time-detect.rs index 54873f5549b..a57a52d9bb0 100644 --- a/library/std/tests/run-time-detect.rs +++ b/library/std/tests/run-time-detect.rs @@ -29,7 +29,6 @@ fn aarch64_linux() { println!("neon: {}", is_aarch64_feature_detected!("neon")); println!("asimd: {}", is_aarch64_feature_detected!("asimd")); println!("pmull: {}", is_aarch64_feature_detected!("pmull")); - println!("fp: {}", is_aarch64_feature_detected!("fp")); println!("fp16: {}", is_aarch64_feature_detected!("fp16")); println!("sve: {}", is_aarch64_feature_detected!("sve")); println!("crc: {}", is_aarch64_feature_detected!("crc")); |
