Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 207ed1b

Browse files
committedDec 27, 2024
Auto merge of #134812 - jhpratt:rollup-a9klvez, r=jhpratt
Rollup of 8 pull requests Successful merges: - #131522 ([macro_metavar_expr_concat] Fix #128346) - #134379 (Add `into_array` conversion destructors for `Box`, `Rc`, and `Arc`.) - #134644 (Document collection `From` and `FromIterator` impls that drop duplicate keys.) - #134649 (Fix forgetting to save statx availability on success) - #134728 (Use scoped threads in `std::sync::Barrier` examples) - #134782 (Update Code Example for `Iterator::rposition`) - #134789 (unwinding: bump version to fix naked_asm on Xous) - #134791 (docs: inline `std::ffi::c_str` types to `std::ffi`) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 917bfa7 + c1447e3 commit 207ed1b

File tree

18 files changed

+175
-63
lines changed

18 files changed

+175
-63
lines changed
 

‎compiler/rustc_expand/src/mbe/transcribe.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -697,8 +697,10 @@ fn transcribe_metavar_expr<'a>(
697697
MetaVarExprConcatElem::Var(ident) => {
698698
match matched_from_ident(dcx, *ident, interp)? {
699699
NamedMatch::MatchedSeq(named_matches) => {
700-
let curr_idx = repeats.last().unwrap().0;
701-
match &named_matches[curr_idx] {
700+
let Some((curr_idx, _)) = repeats.last() else {
701+
return Err(dcx.struct_span_err(sp.entire(), "invalid syntax"));
702+
};
703+
match &named_matches[*curr_idx] {
702704
// FIXME(c410-f3r) Nested repetitions are unimplemented
703705
MatchedSeq(_) => unimplemented!(),
704706
MatchedSingle(pnr) => {

‎library/Cargo.lock

+2-2
Original file line numberDiff line numberDiff line change
@@ -403,9 +403,9 @@ dependencies = [
403403

404404
[[package]]
405405
name = "unwinding"
406-
version = "0.2.4"
406+
version = "0.2.5"
407407
source = "registry+https://github.com/rust-lang/crates.io-index"
408-
checksum = "e2c6cb20f236dae10c69b0b45d82ef50af8b7e45c10e429e7901d26b49b4dbf3"
408+
checksum = "51f06a05848f650946acef3bf525fe96612226b61f74ae23ffa4e98bfbb8ab3c"
409409
dependencies = [
410410
"compiler_builtins",
411411
"gimli 0.31.1",

‎library/alloc/src/boxed.rs

+20
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,26 @@ impl<T> Box<[T]> {
761761
};
762762
unsafe { Ok(RawVec::from_raw_parts_in(ptr.as_ptr(), len, Global).into_box(len)) }
763763
}
764+
765+
/// Converts the boxed slice into a boxed array.
766+
///
767+
/// This operation does not reallocate; the underlying array of the slice is simply reinterpreted as an array type.
768+
///
769+
/// If `N` is not exactly equal to the length of `self`, then this method returns `None`.
770+
#[unstable(feature = "slice_as_array", issue = "133508")]
771+
#[inline]
772+
#[must_use]
773+
pub fn into_array<const N: usize>(self) -> Option<Box<[T; N]>> {
774+
if self.len() == N {
775+
let ptr = Self::into_raw(self) as *mut [T; N];
776+
777+
// 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.
778+
let me = unsafe { Box::from_raw(ptr) };
779+
Some(me)
780+
} else {
781+
None
782+
}
783+
}
764784
}
765785

766786
impl<T, A: Allocator> Box<[T], A> {

‎library/alloc/src/collections/btree/map.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -2289,6 +2289,10 @@ impl<K, V> FusedIterator for RangeMut<'_, K, V> {}
22892289

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

@@ -2403,7 +2407,10 @@ where
24032407

24042408
#[stable(feature = "std_collections_from_array", since = "1.56.0")]
24052409
impl<K: Ord, V, const N: usize> From<[(K, V); N]> for BTreeMap<K, V> {
2406-
/// Converts a `[(K, V); N]` into a `BTreeMap<(K, V)>`.
2410+
/// Converts a `[(K, V); N]` into a `BTreeMap<K, V>`.
2411+
///
2412+
/// If any entries in the array have equal keys,
2413+
/// all but one of the corresponding values will be dropped.
24072414
///
24082415
/// ```
24092416
/// use std::collections::BTreeMap;

‎library/alloc/src/collections/btree/set.rs

+5
Original file line numberDiff line numberDiff line change
@@ -1491,6 +1491,11 @@ impl<T: Ord, A: Allocator + Clone> BTreeSet<T, A> {
14911491
impl<T: Ord, const N: usize> From<[T; N]> for BTreeSet<T> {
14921492
/// Converts a `[T; N]` into a `BTreeSet<T>`.
14931493
///
1494+
/// If the array contains any equal values,
1495+
/// all but one will be dropped.
1496+
///
1497+
/// # Examples
1498+
///
14941499
/// ```
14951500
/// use std::collections::BTreeSet;
14961501
///

‎library/alloc/src/rc.rs

+20
Original file line numberDiff line numberDiff line change
@@ -1084,6 +1084,26 @@ impl<T> Rc<[T]> {
10841084
))
10851085
}
10861086
}
1087+
1088+
/// Converts the reference-counted slice into a reference-counted array.
1089+
///
1090+
/// This operation does not reallocate; the underlying array of the slice is simply reinterpreted as an array type.
1091+
///
1092+
/// If `N` is not exactly equal to the length of `self`, then this method returns `None`.
1093+
#[unstable(feature = "slice_as_array", issue = "133508")]
1094+
#[inline]
1095+
#[must_use]
1096+
pub fn into_array<const N: usize>(self) -> Option<Rc<[T; N]>> {
1097+
if self.len() == N {
1098+
let ptr = Self::into_raw(self) as *const [T; N];
1099+
1100+
// 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.
1101+
let me = unsafe { Rc::from_raw(ptr) };
1102+
Some(me)
1103+
} else {
1104+
None
1105+
}
1106+
}
10871107
}
10881108

10891109
impl<T, A: Allocator> Rc<[T], A> {

‎library/alloc/src/sync.rs

+20
Original file line numberDiff line numberDiff line change
@@ -1203,6 +1203,26 @@ impl<T> Arc<[T]> {
12031203
))
12041204
}
12051205
}
1206+
1207+
/// Converts the reference-counted slice into a reference-counted array.
1208+
///
1209+
/// This operation does not reallocate; the underlying array of the slice is simply reinterpreted as an array type.
1210+
///
1211+
/// If `N` is not exactly equal to the length of `self`, then this method returns `None`.
1212+
#[unstable(feature = "slice_as_array", issue = "133508")]
1213+
#[inline]
1214+
#[must_use]
1215+
pub fn into_array<const N: usize>(self) -> Option<Arc<[T; N]>> {
1216+
if self.len() == N {
1217+
let ptr = Self::into_raw(self) as *const [T; N];
1218+
1219+
// 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.
1220+
let me = unsafe { Arc::from_raw(ptr) };
1221+
Some(me)
1222+
} else {
1223+
None
1224+
}
1225+
}
12061226
}
12071227

12081228
impl<T, A: Allocator> Arc<[T], A> {

‎library/core/src/ffi/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
#[doc(inline)]
1313
#[stable(feature = "core_c_str", since = "1.64.0")]
1414
pub use self::c_str::CStr;
15-
#[doc(no_inline)]
15+
#[doc(inline)]
1616
#[stable(feature = "cstr_from_bytes_until_nul", since = "1.69.0")]
1717
pub use self::c_str::FromBytesUntilNulError;
18-
#[doc(no_inline)]
18+
#[doc(inline)]
1919
#[stable(feature = "core_c_str", since = "1.64.0")]
2020
pub use self::c_str::FromBytesWithNulError;
2121
use crate::fmt;

‎library/core/src/iter/traits/iterator.rs

+1
Original file line numberDiff line numberDiff line change
@@ -3051,6 +3051,7 @@ pub trait Iterator {
30513051
///
30523052
/// // we can still use `iter`, as there are more elements.
30533053
/// assert_eq!(iter.next(), Some(&-1));
3054+
/// assert_eq!(iter.next_back(), Some(&3));
30543055
/// ```
30553056
#[inline]
30563057
#[stable(feature = "rust1", since = "1.0.0")]

‎library/std/src/collections/hash/map.rs

+9
Original file line numberDiff line numberDiff line change
@@ -1446,6 +1446,11 @@ impl<K, V, const N: usize> From<[(K, V); N]> for HashMap<K, V, RandomState>
14461446
where
14471447
K: Eq + Hash,
14481448
{
1449+
/// Converts a `[(K, V); N]` into a `HashMap<K, V>`.
1450+
///
1451+
/// If any entries in the array have equal keys,
1452+
/// all but one of the corresponding values will be dropped.
1453+
///
14491454
/// # Examples
14501455
///
14511456
/// ```
@@ -3219,6 +3224,10 @@ where
32193224
K: Eq + Hash,
32203225
S: BuildHasher + Default,
32213226
{
3227+
/// Constructs a `HashMap<K, V>` from an iterator of key-value pairs.
3228+
///
3229+
/// If the iterator produces any pairs with equal keys,
3230+
/// all but one of the corresponding values will be dropped.
32223231
fn from_iter<T: IntoIterator<Item = (K, V)>>(iter: T) -> HashMap<K, V, S> {
32233232
let mut map = HashMap::with_hasher(Default::default());
32243233
map.extend(iter);

‎library/std/src/collections/hash/set.rs

+5
Original file line numberDiff line numberDiff line change
@@ -1091,6 +1091,11 @@ impl<T, const N: usize> From<[T; N]> for HashSet<T, RandomState>
10911091
where
10921092
T: Eq + Hash,
10931093
{
1094+
/// Converts a `[T; N]` into a `HashSet<T>`.
1095+
///
1096+
/// If the array contains any equal values,
1097+
/// all but one will be dropped.
1098+
///
10941099
/// # Examples
10951100
///
10961101
/// ```

‎library/std/src/ffi/mod.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -179,19 +179,19 @@ pub use core::ffi::{
179179
c_ulong, c_ulonglong, c_ushort,
180180
};
181181

182-
#[doc(no_inline)]
182+
#[doc(inline)]
183183
#[stable(feature = "cstr_from_bytes_until_nul", since = "1.69.0")]
184184
pub use self::c_str::FromBytesUntilNulError;
185-
#[doc(no_inline)]
185+
#[doc(inline)]
186186
#[stable(feature = "cstr_from_bytes", since = "1.10.0")]
187187
pub use self::c_str::FromBytesWithNulError;
188-
#[doc(no_inline)]
188+
#[doc(inline)]
189189
#[stable(feature = "cstring_from_vec_with_nul", since = "1.58.0")]
190190
pub use self::c_str::FromVecWithNulError;
191-
#[doc(no_inline)]
191+
#[doc(inline)]
192192
#[stable(feature = "cstring_into", since = "1.7.0")]
193193
pub use self::c_str::IntoStringError;
194-
#[doc(no_inline)]
194+
#[doc(inline)]
195195
#[stable(feature = "rust1", since = "1.0.0")]
196196
pub use self::c_str::NulError;
197197
#[doc(inline)]

‎library/std/src/sync/barrier.rs

+26-34
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,22 @@ use crate::sync::{Condvar, Mutex};
1010
/// # Examples
1111
///
1212
/// ```
13-
/// use std::sync::{Arc, Barrier};
13+
/// use std::sync::Barrier;
1414
/// use std::thread;
1515
///
1616
/// let n = 10;
17-
/// let mut handles = Vec::with_capacity(n);
18-
/// let barrier = Arc::new(Barrier::new(n));
19-
/// for _ in 0..n {
20-
/// let c = Arc::clone(&barrier);
21-
/// // The same messages will be printed together.
22-
/// // You will NOT see any interleaving.
23-
/// handles.push(thread::spawn(move || {
24-
/// println!("before wait");
25-
/// c.wait();
26-
/// println!("after wait");
27-
/// }));
28-
/// }
29-
/// // Wait for other threads to finish.
30-
/// for handle in handles {
31-
/// handle.join().unwrap();
32-
/// }
17+
/// let barrier = Barrier::new(n);
18+
/// thread::scope(|s| {
19+
/// for _ in 0..n {
20+
/// // The same messages will be printed together.
21+
/// // You will NOT see any interleaving.
22+
/// s.spawn(|| {
23+
/// println!("before wait");
24+
/// barrier.wait();
25+
/// println!("after wait");
26+
/// });
27+
/// }
28+
/// });
3329
/// ```
3430
#[stable(feature = "rust1", since = "1.0.0")]
3531
pub struct Barrier {
@@ -105,26 +101,22 @@ impl Barrier {
105101
/// # Examples
106102
///
107103
/// ```
108-
/// use std::sync::{Arc, Barrier};
104+
/// use std::sync::Barrier;
109105
/// use std::thread;
110106
///
111107
/// let n = 10;
112-
/// let mut handles = Vec::with_capacity(n);
113-
/// let barrier = Arc::new(Barrier::new(n));
114-
/// for _ in 0..n {
115-
/// let c = Arc::clone(&barrier);
116-
/// // The same messages will be printed together.
117-
/// // You will NOT see any interleaving.
118-
/// handles.push(thread::spawn(move || {
119-
/// println!("before wait");
120-
/// c.wait();
121-
/// println!("after wait");
122-
/// }));
123-
/// }
124-
/// // Wait for other threads to finish.
125-
/// for handle in handles {
126-
/// handle.join().unwrap();
127-
/// }
108+
/// let barrier = Barrier::new(n);
109+
/// thread::scope(|s| {
110+
/// for _ in 0..n {
111+
/// // The same messages will be printed together.
112+
/// // You will NOT see any interleaving.
113+
/// s.spawn(|| {
114+
/// println!("before wait");
115+
/// barrier.wait();
116+
/// println!("after wait");
117+
/// });
118+
/// }
119+
/// });
128120
/// ```
129121
#[stable(feature = "rust1", since = "1.0.0")]
130122
pub fn wait(&self) -> BarrierWaitResult {

‎library/std/src/sys/pal/unix/fs.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,8 @@ cfg_has_statx! {{
168168
) -> c_int
169169
}
170170

171-
if STATX_SAVED_STATE.load(Ordering::Relaxed) == STATX_STATE::Unavailable as u8 {
171+
let statx_availability = STATX_SAVED_STATE.load(Ordering::Relaxed);
172+
if statx_availability == STATX_STATE::Unavailable as u8 {
172173
return None;
173174
}
174175

@@ -200,6 +201,9 @@ cfg_has_statx! {{
200201
return None;
201202
}
202203
}
204+
if statx_availability == STATX_STATE::Unknown as u8 {
205+
STATX_SAVED_STATE.store(STATX_STATE::Present as u8, Ordering::Relaxed);
206+
}
203207

204208
// We cannot fill `stat64` exhaustively because of private padding fields.
205209
let mut stat: stat64 = mem::zeroed();

‎library/unwind/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ cfg-if = "1.0"
2222
libc = { version = "0.2.140", features = ['rustc-dep-of-std'], default-features = false }
2323

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

2727
[features]
2828

‎tests/crashes/128346.rs

-13
This file was deleted.

‎tests/ui/macros/macro-metavar-expr-concat/repetitions.rs

+20-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
//@ run-pass
2-
31
#![feature(macro_metavar_expr_concat)]
42

53
macro_rules! one_rep {
@@ -10,9 +8,29 @@ macro_rules! one_rep {
108
};
119
}
1210

11+
macro_rules! issue_128346 {
12+
( $($a:ident)* ) => {
13+
A(
14+
const ${concat($a, Z)}: i32 = 3;
15+
//~^ ERROR invalid syntax
16+
)*
17+
};
18+
}
19+
20+
macro_rules! issue_131393 {
21+
($t:ident $($en:ident)?) => {
22+
read::<${concat($t, $en)}>()
23+
//~^ ERROR invalid syntax
24+
//~| ERROR invalid syntax
25+
}
26+
}
27+
1328
fn main() {
1429
one_rep!(A B C);
1530
assert_eq!(AZ, 3);
1631
assert_eq!(BZ, 3);
1732
assert_eq!(CZ, 3);
33+
issue_128346!(A B C);
34+
issue_131393!(u8);
35+
issue_131393!(u16 le);
1836
}
There was a problem loading the remainder of the diff.

0 commit comments

Comments
 (0)
Failed to load comments.