Skip to content

Commit 207ed1b

Browse files
committed
Auto merge of rust-lang#134812 - jhpratt:rollup-a9klvez, r=jhpratt
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
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

Lines changed: 4 additions & 2 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 20 additions & 0 deletions
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

Lines changed: 8 additions & 1 deletion
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

Lines changed: 5 additions & 0 deletions
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

Lines changed: 20 additions & 0 deletions
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

Lines changed: 20 additions & 0 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 9 additions & 0 deletions
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);

0 commit comments

Comments
 (0)