Skip to content

Commit

Permalink
Auto merge of rust-lang#134812 - jhpratt:rollup-a9klvez, r=jhpratt
Browse files Browse the repository at this point in the history
Rollup of 8 pull requests

Successful merges:

 - rust-lang#131522 ([macro_metavar_expr_concat] Fix rust-lang#128346)
 - rust-lang#134379 (Add `into_array` conversion destructors for `Box`, `Rc`, and `Arc`.)
 - rust-lang#134644 (Document collection `From` and `FromIterator` impls that drop duplicate keys.)
 - rust-lang#134649 (Fix forgetting to save statx availability on success)
 - rust-lang#134728 (Use scoped threads in `std::sync::Barrier` examples)
 - rust-lang#134782 (Update Code Example for `Iterator::rposition`)
 - rust-lang#134789 (unwinding: bump version to fix naked_asm on Xous)
 - rust-lang#134791 (docs: inline `std::ffi::c_str` types to `std::ffi`)

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors authored and poliorcetics committed Dec 28, 2024
2 parents 071a62b + 901f178 commit 63c3fa8
Show file tree
Hide file tree
Showing 18 changed files with 175 additions and 63 deletions.
6 changes: 4 additions & 2 deletions compiler/rustc_expand/src/mbe/transcribe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -697,8 +697,10 @@ fn transcribe_metavar_expr<'a>(
MetaVarExprConcatElem::Var(ident) => {
match matched_from_ident(dcx, *ident, interp)? {
NamedMatch::MatchedSeq(named_matches) => {
let curr_idx = repeats.last().unwrap().0;
match &named_matches[curr_idx] {
let Some((curr_idx, _)) = repeats.last() else {
return Err(dcx.struct_span_err(sp.entire(), "invalid syntax"));
};
match &named_matches[*curr_idx] {
// FIXME(c410-f3r) Nested repetitions are unimplemented
MatchedSeq(_) => unimplemented!(),
MatchedSingle(pnr) => {
Expand Down
4 changes: 2 additions & 2 deletions library/Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -403,9 +403,9 @@ dependencies = [

[[package]]
name = "unwinding"
version = "0.2.4"
version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2c6cb20f236dae10c69b0b45d82ef50af8b7e45c10e429e7901d26b49b4dbf3"
checksum = "51f06a05848f650946acef3bf525fe96612226b61f74ae23ffa4e98bfbb8ab3c"
dependencies = [
"compiler_builtins",
"gimli 0.31.1",
Expand Down
20 changes: 20 additions & 0 deletions library/alloc/src/boxed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,26 @@ impl<T> Box<[T]> {
};
unsafe { Ok(RawVec::from_raw_parts_in(ptr.as_ptr(), len, Global).into_box(len)) }
}

/// Converts the boxed slice into a boxed array.
///
/// This operation does not reallocate; the underlying array of the slice is simply reinterpreted as an array type.
///
/// If `N` is not exactly equal to the length of `self`, then this method returns `None`.
#[unstable(feature = "slice_as_array", issue = "133508")]
#[inline]
#[must_use]
pub fn into_array<const N: usize>(self) -> Option<Box<[T; N]>> {
if self.len() == N {
let ptr = Self::into_raw(self) as *mut [T; N];

// SAFETY: The underlying array of a slice has the exact same layout as an actual array `[T; N]` if `N` is equal to the slice's length.
let me = unsafe { Box::from_raw(ptr) };
Some(me)
} else {
None
}
}
}

impl<T, A: Allocator> Box<[T], A> {
Expand Down
9 changes: 8 additions & 1 deletion library/alloc/src/collections/btree/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2289,6 +2289,10 @@ impl<K, V> FusedIterator for RangeMut<'_, K, V> {}

#[stable(feature = "rust1", since = "1.0.0")]
impl<K: Ord, V> FromIterator<(K, V)> for BTreeMap<K, V> {
/// Constructs a `BTreeMap<K, V>` from an iterator of key-value pairs.
///
/// If the iterator produces any pairs with equal keys,
/// all but one of the corresponding values will be dropped.
fn from_iter<T: IntoIterator<Item = (K, V)>>(iter: T) -> BTreeMap<K, V> {
let mut inputs: Vec<_> = iter.into_iter().collect();

Expand Down Expand Up @@ -2403,7 +2407,10 @@ where

#[stable(feature = "std_collections_from_array", since = "1.56.0")]
impl<K: Ord, V, const N: usize> From<[(K, V); N]> for BTreeMap<K, V> {
/// Converts a `[(K, V); N]` into a `BTreeMap<(K, V)>`.
/// Converts a `[(K, V); N]` into a `BTreeMap<K, V>`.
///
/// If any entries in the array have equal keys,
/// all but one of the corresponding values will be dropped.
///
/// ```
/// use std::collections::BTreeMap;
Expand Down
5 changes: 5 additions & 0 deletions library/alloc/src/collections/btree/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1491,6 +1491,11 @@ impl<T: Ord, A: Allocator + Clone> BTreeSet<T, A> {
impl<T: Ord, const N: usize> From<[T; N]> for BTreeSet<T> {
/// Converts a `[T; N]` into a `BTreeSet<T>`.
///
/// If the array contains any equal values,
/// all but one will be dropped.
///
/// # Examples
///
/// ```
/// use std::collections::BTreeSet;
///
Expand Down
20 changes: 20 additions & 0 deletions library/alloc/src/rc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1084,6 +1084,26 @@ impl<T> Rc<[T]> {
))
}
}

/// Converts the reference-counted slice into a reference-counted array.
///
/// This operation does not reallocate; the underlying array of the slice is simply reinterpreted as an array type.
///
/// If `N` is not exactly equal to the length of `self`, then this method returns `None`.
#[unstable(feature = "slice_as_array", issue = "133508")]
#[inline]
#[must_use]
pub fn into_array<const N: usize>(self) -> Option<Rc<[T; N]>> {
if self.len() == N {
let ptr = Self::into_raw(self) as *const [T; N];

// SAFETY: The underlying array of a slice has the exact same layout as an actual array `[T; N]` if `N` is equal to the slice's length.
let me = unsafe { Rc::from_raw(ptr) };
Some(me)
} else {
None
}
}
}

impl<T, A: Allocator> Rc<[T], A> {
Expand Down
20 changes: 20 additions & 0 deletions library/alloc/src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1203,6 +1203,26 @@ impl<T> Arc<[T]> {
))
}
}

/// Converts the reference-counted slice into a reference-counted array.
///
/// This operation does not reallocate; the underlying array of the slice is simply reinterpreted as an array type.
///
/// If `N` is not exactly equal to the length of `self`, then this method returns `None`.
#[unstable(feature = "slice_as_array", issue = "133508")]
#[inline]
#[must_use]
pub fn into_array<const N: usize>(self) -> Option<Arc<[T; N]>> {
if self.len() == N {
let ptr = Self::into_raw(self) as *const [T; N];

// SAFETY: The underlying array of a slice has the exact same layout as an actual array `[T; N]` if `N` is equal to the slice's length.
let me = unsafe { Arc::from_raw(ptr) };
Some(me)
} else {
None
}
}
}

impl<T, A: Allocator> Arc<[T], A> {
Expand Down
4 changes: 2 additions & 2 deletions library/core/src/ffi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
#[doc(inline)]
#[stable(feature = "core_c_str", since = "1.64.0")]
pub use self::c_str::CStr;
#[doc(no_inline)]
#[doc(inline)]
#[stable(feature = "cstr_from_bytes_until_nul", since = "1.69.0")]
pub use self::c_str::FromBytesUntilNulError;
#[doc(no_inline)]
#[doc(inline)]
#[stable(feature = "core_c_str", since = "1.64.0")]
pub use self::c_str::FromBytesWithNulError;
use crate::fmt;
Expand Down
1 change: 1 addition & 0 deletions library/core/src/iter/traits/iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3051,6 +3051,7 @@ pub trait Iterator {
///
/// // we can still use `iter`, as there are more elements.
/// assert_eq!(iter.next(), Some(&-1));
/// assert_eq!(iter.next_back(), Some(&3));
/// ```
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
Expand Down
9 changes: 9 additions & 0 deletions library/std/src/collections/hash/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1446,6 +1446,11 @@ impl<K, V, const N: usize> From<[(K, V); N]> for HashMap<K, V, RandomState>
where
K: Eq + Hash,
{
/// Converts a `[(K, V); N]` into a `HashMap<K, V>`.
///
/// If any entries in the array have equal keys,
/// all but one of the corresponding values will be dropped.
///
/// # Examples
///
/// ```
Expand Down Expand Up @@ -3219,6 +3224,10 @@ where
K: Eq + Hash,
S: BuildHasher + Default,
{
/// Constructs a `HashMap<K, V>` from an iterator of key-value pairs.
///
/// If the iterator produces any pairs with equal keys,
/// all but one of the corresponding values will be dropped.
fn from_iter<T: IntoIterator<Item = (K, V)>>(iter: T) -> HashMap<K, V, S> {
let mut map = HashMap::with_hasher(Default::default());
map.extend(iter);
Expand Down
5 changes: 5 additions & 0 deletions library/std/src/collections/hash/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1091,6 +1091,11 @@ impl<T, const N: usize> From<[T; N]> for HashSet<T, RandomState>
where
T: Eq + Hash,
{
/// Converts a `[T; N]` into a `HashSet<T>`.
///
/// If the array contains any equal values,
/// all but one will be dropped.
///
/// # Examples
///
/// ```
Expand Down
10 changes: 5 additions & 5 deletions library/std/src/ffi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,19 +179,19 @@ pub use core::ffi::{
c_ulong, c_ulonglong, c_ushort,
};

#[doc(no_inline)]
#[doc(inline)]
#[stable(feature = "cstr_from_bytes_until_nul", since = "1.69.0")]
pub use self::c_str::FromBytesUntilNulError;
#[doc(no_inline)]
#[doc(inline)]
#[stable(feature = "cstr_from_bytes", since = "1.10.0")]
pub use self::c_str::FromBytesWithNulError;
#[doc(no_inline)]
#[doc(inline)]
#[stable(feature = "cstring_from_vec_with_nul", since = "1.58.0")]
pub use self::c_str::FromVecWithNulError;
#[doc(no_inline)]
#[doc(inline)]
#[stable(feature = "cstring_into", since = "1.7.0")]
pub use self::c_str::IntoStringError;
#[doc(no_inline)]
#[doc(inline)]
#[stable(feature = "rust1", since = "1.0.0")]
pub use self::c_str::NulError;
#[doc(inline)]
Expand Down
60 changes: 26 additions & 34 deletions library/std/src/sync/barrier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,22 @@ use crate::sync::{Condvar, Mutex};
/// # Examples
///
/// ```
/// use std::sync::{Arc, Barrier};
/// use std::sync::Barrier;
/// use std::thread;
///
/// let n = 10;
/// let mut handles = Vec::with_capacity(n);
/// let barrier = Arc::new(Barrier::new(n));
/// for _ in 0..n {
/// let c = Arc::clone(&barrier);
/// // The same messages will be printed together.
/// // You will NOT see any interleaving.
/// handles.push(thread::spawn(move || {
/// println!("before wait");
/// c.wait();
/// println!("after wait");
/// }));
/// }
/// // Wait for other threads to finish.
/// for handle in handles {
/// handle.join().unwrap();
/// }
/// let barrier = Barrier::new(n);
/// thread::scope(|s| {
/// for _ in 0..n {
/// // The same messages will be printed together.
/// // You will NOT see any interleaving.
/// s.spawn(|| {
/// println!("before wait");
/// barrier.wait();
/// println!("after wait");
/// });
/// }
/// });
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub struct Barrier {
Expand Down Expand Up @@ -105,26 +101,22 @@ impl Barrier {
/// # Examples
///
/// ```
/// use std::sync::{Arc, Barrier};
/// use std::sync::Barrier;
/// use std::thread;
///
/// let n = 10;
/// let mut handles = Vec::with_capacity(n);
/// let barrier = Arc::new(Barrier::new(n));
/// for _ in 0..n {
/// let c = Arc::clone(&barrier);
/// // The same messages will be printed together.
/// // You will NOT see any interleaving.
/// handles.push(thread::spawn(move || {
/// println!("before wait");
/// c.wait();
/// println!("after wait");
/// }));
/// }
/// // Wait for other threads to finish.
/// for handle in handles {
/// handle.join().unwrap();
/// }
/// let barrier = Barrier::new(n);
/// thread::scope(|s| {
/// for _ in 0..n {
/// // The same messages will be printed together.
/// // You will NOT see any interleaving.
/// s.spawn(|| {
/// println!("before wait");
/// barrier.wait();
/// println!("after wait");
/// });
/// }
/// });
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn wait(&self) -> BarrierWaitResult {
Expand Down
6 changes: 5 additions & 1 deletion library/std/src/sys/pal/unix/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@ cfg_has_statx! {{
) -> c_int
}

if STATX_SAVED_STATE.load(Ordering::Relaxed) == STATX_STATE::Unavailable as u8 {
let statx_availability = STATX_SAVED_STATE.load(Ordering::Relaxed);
if statx_availability == STATX_STATE::Unavailable as u8 {
return None;
}

Expand Down Expand Up @@ -200,6 +201,9 @@ cfg_has_statx! {{
return None;
}
}
if statx_availability == STATX_STATE::Unknown as u8 {
STATX_SAVED_STATE.store(STATX_STATE::Present as u8, Ordering::Relaxed);
}

// We cannot fill `stat64` exhaustively because of private padding fields.
let mut stat: stat64 = mem::zeroed();
Expand Down
2 changes: 1 addition & 1 deletion library/unwind/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ cfg-if = "1.0"
libc = { version = "0.2.140", features = ['rustc-dep-of-std'], default-features = false }

[target.'cfg(target_os = "xous")'.dependencies]
unwinding = { version = "0.2.3", features = ['rustc-dep-of-std', 'unwinder', 'fde-custom'], default-features = false }
unwinding = { version = "0.2.5", features = ['rustc-dep-of-std', 'unwinder', 'fde-custom'], default-features = false }

[features]

Expand Down
13 changes: 0 additions & 13 deletions tests/crashes/128346.rs

This file was deleted.

22 changes: 20 additions & 2 deletions tests/ui/macros/macro-metavar-expr-concat/repetitions.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
//@ run-pass

#![feature(macro_metavar_expr_concat)]

macro_rules! one_rep {
Expand All @@ -10,9 +8,29 @@ macro_rules! one_rep {
};
}

macro_rules! issue_128346 {
( $($a:ident)* ) => {
A(
const ${concat($a, Z)}: i32 = 3;
//~^ ERROR invalid syntax
)*
};
}

macro_rules! issue_131393 {
($t:ident $($en:ident)?) => {
read::<${concat($t, $en)}>()
//~^ ERROR invalid syntax
//~| ERROR invalid syntax
}
}

fn main() {
one_rep!(A B C);
assert_eq!(AZ, 3);
assert_eq!(BZ, 3);
assert_eq!(CZ, 3);
issue_128346!(A B C);
issue_131393!(u8);
issue_131393!(u16 le);
}
Loading

0 comments on commit 63c3fa8

Please sign in to comment.