Skip to content

Commit bc97720

Browse files
committed
Auto merge of rust-lang#91959 - matthiaskrgr:rollup-rhajuvw, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - rust-lang#90521 (Stabilize `destructuring_assignment`) - rust-lang#91479 (Add `[T]::as_simd(_mut)`) - rust-lang#91584 (Improve code for rustdoc-gui tester) - rust-lang#91886 (core: minor `Option` doc correction) - rust-lang#91888 (Handle unordered const/ty generics for object lifetime defaults) - rust-lang#91905 (Fix source code page sidebar on mobile) - rust-lang#91906 (Removed `in_band_lifetimes` from `library\proc_macro`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 3e9c678 + 3d18e31 commit bc97720

File tree

7 files changed

+132
-14
lines changed

7 files changed

+132
-14
lines changed

alloc/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@
136136
#![feature(cfg_target_has_atomic)]
137137
#![feature(const_fn_trait_bound)]
138138
#![feature(const_trait_impl)]
139-
#![feature(destructuring_assignment)]
139+
#![cfg_attr(bootstrap, feature(destructuring_assignment))]
140140
#![feature(dropck_eyepatch)]
141141
#![feature(exclusive_range_pattern)]
142142
#![feature(fundamental)]

core/src/option.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -512,11 +512,11 @@ use crate::{
512512
#[rustc_diagnostic_item = "Option"]
513513
#[stable(feature = "rust1", since = "1.0.0")]
514514
pub enum Option<T> {
515-
/// No value
515+
/// No value.
516516
#[lang = "None"]
517517
#[stable(feature = "rust1", since = "1.0.0")]
518518
None,
519-
/// Some value `T`
519+
/// Some value of type `T`.
520520
#[lang = "Some"]
521521
#[stable(feature = "rust1", since = "1.0.0")]
522522
Some(#[stable(feature = "rust1", since = "1.0.0")] T),

core/src/slice/mod.rs

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ use crate::option::Option::{None, Some};
1616
use crate::ptr;
1717
use crate::result::Result;
1818
use crate::result::Result::{Err, Ok};
19+
#[cfg(not(miri))] // Miri does not support all SIMD intrinsics
20+
use crate::simd::{self, Simd};
1921
use crate::slice;
2022

2123
#[unstable(
@@ -3512,6 +3514,123 @@ impl<T> [T] {
35123514
}
35133515
}
35143516

3517+
/// Split a slice into a prefix, a middle of aligned SIMD types, and a suffix.
3518+
///
3519+
/// This is a safe wrapper around [`slice::align_to`], so has the same weak
3520+
/// postconditions as that method. You're only assured that
3521+
/// `self.len() == prefix.len() + middle.len() * LANES + suffix.len()`.
3522+
///
3523+
/// Notably, all of the following are possible:
3524+
/// - `prefix.len() >= LANES`.
3525+
/// - `middle.is_empty()` despite `self.len() >= 3 * LANES`.
3526+
/// - `suffix.len() >= LANES`.
3527+
///
3528+
/// That said, this is a safe method, so if you're only writing safe code,
3529+
/// then this can at most cause incorrect logic, not unsoundness.
3530+
///
3531+
/// # Panics
3532+
///
3533+
/// This will panic if the size of the SIMD type is different from
3534+
/// `LANES` times that of the scalar.
3535+
///
3536+
/// At the time of writing, the trait restrictions on `Simd<T, LANES>` keeps
3537+
/// that from ever happening, as only power-of-two numbers of lanes are
3538+
/// supported. It's possible that, in the future, those restrictions might
3539+
/// be lifted in a way that would make it possible to see panics from this
3540+
/// method for something like `LANES == 3`.
3541+
///
3542+
/// # Examples
3543+
///
3544+
/// ```
3545+
/// #![feature(portable_simd)]
3546+
///
3547+
/// let short = &[1, 2, 3];
3548+
/// let (prefix, middle, suffix) = short.as_simd::<4>();
3549+
/// assert_eq!(middle, []); // Not enough elements for anything in the middle
3550+
///
3551+
/// // They might be split in any possible way between prefix and suffix
3552+
/// let it = prefix.iter().chain(suffix).copied();
3553+
/// assert_eq!(it.collect::<Vec<_>>(), vec![1, 2, 3]);
3554+
///
3555+
/// fn basic_simd_sum(x: &[f32]) -> f32 {
3556+
/// use std::ops::Add;
3557+
/// use std::simd::f32x4;
3558+
/// let (prefix, middle, suffix) = x.as_simd();
3559+
/// let sums = f32x4::from_array([
3560+
/// prefix.iter().copied().sum(),
3561+
/// 0.0,
3562+
/// 0.0,
3563+
/// suffix.iter().copied().sum(),
3564+
/// ]);
3565+
/// let sums = middle.iter().copied().fold(sums, f32x4::add);
3566+
/// sums.horizontal_sum()
3567+
/// }
3568+
///
3569+
/// let numbers: Vec<f32> = (1..101).map(|x| x as _).collect();
3570+
/// assert_eq!(basic_simd_sum(&numbers[1..99]), 4949.0);
3571+
/// ```
3572+
#[unstable(feature = "portable_simd", issue = "86656")]
3573+
#[cfg(not(miri))] // Miri does not support all SIMD intrinsics
3574+
pub fn as_simd<const LANES: usize>(&self) -> (&[T], &[Simd<T, LANES>], &[T])
3575+
where
3576+
Simd<T, LANES>: AsRef<[T; LANES]>,
3577+
T: simd::SimdElement,
3578+
simd::LaneCount<LANES>: simd::SupportedLaneCount,
3579+
{
3580+
// These are expected to always match, as vector types are laid out like
3581+
// arrays per <https://llvm.org/docs/LangRef.html#vector-type>, but we
3582+
// might as well double-check since it'll optimize away anyhow.
3583+
assert_eq!(mem::size_of::<Simd<T, LANES>>(), mem::size_of::<[T; LANES]>());
3584+
3585+
// SAFETY: The simd types have the same layout as arrays, just with
3586+
// potentially-higher alignment, so the de-facto transmutes are sound.
3587+
unsafe { self.align_to() }
3588+
}
3589+
3590+
/// Split a slice into a prefix, a middle of aligned SIMD types, and a suffix.
3591+
///
3592+
/// This is a safe wrapper around [`slice::align_to_mut`], so has the same weak
3593+
/// postconditions as that method. You're only assured that
3594+
/// `self.len() == prefix.len() + middle.len() * LANES + suffix.len()`.
3595+
///
3596+
/// Notably, all of the following are possible:
3597+
/// - `prefix.len() >= LANES`.
3598+
/// - `middle.is_empty()` despite `self.len() >= 3 * LANES`.
3599+
/// - `suffix.len() >= LANES`.
3600+
///
3601+
/// That said, this is a safe method, so if you're only writing safe code,
3602+
/// then this can at most cause incorrect logic, not unsoundness.
3603+
///
3604+
/// This is the mutable version of [`slice::as_simd`]; see that for examples.
3605+
///
3606+
/// # Panics
3607+
///
3608+
/// This will panic if the size of the SIMD type is different from
3609+
/// `LANES` times that of the scalar.
3610+
///
3611+
/// At the time of writing, the trait restrictions on `Simd<T, LANES>` keeps
3612+
/// that from ever happening, as only power-of-two numbers of lanes are
3613+
/// supported. It's possible that, in the future, those restrictions might
3614+
/// be lifted in a way that would make it possible to see panics from this
3615+
/// method for something like `LANES == 3`.
3616+
#[unstable(feature = "portable_simd", issue = "86656")]
3617+
#[cfg(not(miri))] // Miri does not support all SIMD intrinsics
3618+
pub fn as_simd_mut<const LANES: usize>(&mut self) -> (&mut [T], &mut [Simd<T, LANES>], &mut [T])
3619+
where
3620+
Simd<T, LANES>: AsMut<[T; LANES]>,
3621+
T: simd::SimdElement,
3622+
simd::LaneCount<LANES>: simd::SupportedLaneCount,
3623+
{
3624+
// These are expected to always match, as vector types are laid out like
3625+
// arrays per <https://llvm.org/docs/LangRef.html#vector-type>, but we
3626+
// might as well double-check since it'll optimize away anyhow.
3627+
assert_eq!(mem::size_of::<Simd<T, LANES>>(), mem::size_of::<[T; LANES]>());
3628+
3629+
// SAFETY: The simd types have the same layout as arrays, just with
3630+
// potentially-higher alignment, so the de-facto transmutes are sound.
3631+
unsafe { self.align_to_mut() }
3632+
}
3633+
35153634
/// Checks if the elements of this slice are sorted.
35163635
///
35173636
/// That is, for each element `a` and its following element `b`, `a <= b` must hold. If the

proc_macro/src/bridge/client.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ macro_rules! define_handles {
7878
}
7979
}
8080

81-
impl<S: server::Types> Decode<'_, 's, HandleStore<server::MarkedTypes<S>>>
81+
impl<'s, S: server::Types> Decode<'_, 's, HandleStore<server::MarkedTypes<S>>>
8282
for &'s Marked<S::$oty, $oty>
8383
{
8484
fn decode(r: &mut Reader<'_>, s: &'s HandleStore<server::MarkedTypes<S>>) -> Self {
@@ -92,7 +92,7 @@ macro_rules! define_handles {
9292
}
9393
}
9494

95-
impl<S: server::Types> DecodeMut<'_, 's, HandleStore<server::MarkedTypes<S>>>
95+
impl<'s, S: server::Types> DecodeMut<'_, 's, HandleStore<server::MarkedTypes<S>>>
9696
for &'s mut Marked<S::$oty, $oty>
9797
{
9898
fn decode(

proc_macro/src/bridge/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -295,13 +295,13 @@ impl<T, M> Unmark for Marked<T, M> {
295295
self.value
296296
}
297297
}
298-
impl<T, M> Unmark for &'a Marked<T, M> {
298+
impl<'a, T, M> Unmark for &'a Marked<T, M> {
299299
type Unmarked = &'a T;
300300
fn unmark(self) -> Self::Unmarked {
301301
&self.value
302302
}
303303
}
304-
impl<T, M> Unmark for &'a mut Marked<T, M> {
304+
impl<'a, T, M> Unmark for &'a mut Marked<T, M> {
305305
type Unmarked = &'a mut T;
306306
fn unmark(self) -> Self::Unmarked {
307307
&mut self.value
@@ -356,8 +356,8 @@ mark_noop! {
356356
(),
357357
bool,
358358
char,
359-
&'a [u8],
360-
&'a str,
359+
&'_ [u8],
360+
&'_ str,
361361
String,
362362
usize,
363363
Delimiter,

proc_macro/src/bridge/rpc.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ macro_rules! rpc_encode_decode {
7979
}
8080
}
8181

82-
impl<S, $($($T: for<'s> DecodeMut<'a, 's, S>),+)?> DecodeMut<'a, '_, S>
82+
impl<'a, S, $($($T: for<'s> DecodeMut<'a, 's, S>),+)?> DecodeMut<'a, '_, S>
8383
for $name $(<$($T),+>)?
8484
{
8585
fn decode(r: &mut Reader<'a>, s: &mut S) -> Self {
@@ -176,7 +176,7 @@ impl<S, A: Encode<S>, B: Encode<S>> Encode<S> for (A, B) {
176176
}
177177
}
178178

179-
impl<S, A: for<'s> DecodeMut<'a, 's, S>, B: for<'s> DecodeMut<'a, 's, S>> DecodeMut<'a, '_, S>
179+
impl<'a, S, A: for<'s> DecodeMut<'a, 's, S>, B: for<'s> DecodeMut<'a, 's, S>> DecodeMut<'a, '_, S>
180180
for (A, B)
181181
{
182182
fn decode(r: &mut Reader<'a>, s: &mut S) -> Self {
@@ -213,7 +213,7 @@ impl<S> Encode<S> for &[u8] {
213213
}
214214
}
215215

216-
impl<S> DecodeMut<'a, '_, S> for &'a [u8] {
216+
impl<'a, S> DecodeMut<'a, '_, S> for &'a [u8] {
217217
fn decode(r: &mut Reader<'a>, s: &mut S) -> Self {
218218
let len = usize::decode(r, s);
219219
let xs = &r[..len];
@@ -228,7 +228,7 @@ impl<S> Encode<S> for &str {
228228
}
229229
}
230230

231-
impl<S> DecodeMut<'a, '_, S> for &'a str {
231+
impl<'a, S> DecodeMut<'a, '_, S> for &'a str {
232232
fn decode(r: &mut Reader<'a>, s: &mut S) -> Self {
233233
str::from_utf8(<&[u8]>::decode(r, s)).unwrap()
234234
}

proc_macro/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
#![feature(allow_internal_unstable)]
2626
#![feature(decl_macro)]
2727
#![feature(extern_types)]
28-
#![feature(in_band_lifetimes)]
2928
#![feature(negative_impls)]
3029
#![feature(auto_traits)]
3130
#![feature(restricted_std)]

0 commit comments

Comments
 (0)