Skip to content

Commit 37370b0

Browse files
author
The Miri Cronjob Bot
committed
Merge from rustc
2 parents 6544b00 + ff9e88a commit 37370b0

File tree

29 files changed

+209
-103
lines changed

29 files changed

+209
-103
lines changed

alloc/src/collections/vec_deque/mod.rs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1735,6 +1735,52 @@ impl<T, A: Allocator> VecDeque<T, A> {
17351735
}
17361736
}
17371737

1738+
/// Removes and returns the first element from the deque if the predicate
1739+
/// returns `true`, or [`None`] if the predicate returns false or the deque
1740+
/// is empty (the predicate will not be called in that case).
1741+
///
1742+
/// # Examples
1743+
///
1744+
/// ```
1745+
/// #![feature(vec_deque_pop_if)]
1746+
/// use std::collections::VecDeque;
1747+
///
1748+
/// let mut deque: VecDeque<i32> = vec![0, 1, 2, 3, 4].into();
1749+
/// let pred = |x: &mut i32| *x % 2 == 0;
1750+
///
1751+
/// assert_eq!(deque.pop_front_if(pred), Some(0));
1752+
/// assert_eq!(deque, [1, 2, 3, 4]);
1753+
/// assert_eq!(deque.pop_front_if(pred), None);
1754+
/// ```
1755+
#[unstable(feature = "vec_deque_pop_if", issue = "135889")]
1756+
pub fn pop_front_if(&mut self, predicate: impl FnOnce(&mut T) -> bool) -> Option<T> {
1757+
let first = self.front_mut()?;
1758+
if predicate(first) { self.pop_front() } else { None }
1759+
}
1760+
1761+
/// Removes and returns the last element from the deque if the predicate
1762+
/// returns `true`, or [`None`] if the predicate returns false or the deque
1763+
/// is empty (the predicate will not be called in that case).
1764+
///
1765+
/// # Examples
1766+
///
1767+
/// ```
1768+
/// #![feature(vec_deque_pop_if)]
1769+
/// use std::collections::VecDeque;
1770+
///
1771+
/// let mut deque: VecDeque<i32> = vec![0, 1, 2, 3, 4].into();
1772+
/// let pred = |x: &mut i32| *x % 2 == 0;
1773+
///
1774+
/// assert_eq!(deque.pop_back_if(pred), Some(4));
1775+
/// assert_eq!(deque, [0, 1, 2, 3]);
1776+
/// assert_eq!(deque.pop_back_if(pred), None);
1777+
/// ```
1778+
#[unstable(feature = "vec_deque_pop_if", issue = "135889")]
1779+
pub fn pop_back_if(&mut self, predicate: impl FnOnce(&mut T) -> bool) -> Option<T> {
1780+
let first = self.back_mut()?;
1781+
if predicate(first) { self.pop_back() } else { None }
1782+
}
1783+
17381784
/// Prepends an element to the deque.
17391785
///
17401786
/// # Examples

alloc/src/vec/mod.rs

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2511,9 +2511,9 @@ impl<T, A: Allocator> Vec<T, A> {
25112511
}
25122512
}
25132513

2514-
/// Removes and returns the last element in a vector if the predicate
2514+
/// Removes and returns the last element from a vector if the predicate
25152515
/// returns `true`, or [`None`] if the predicate returns false or the vector
2516-
/// is empty.
2516+
/// is empty (the predicate will not be called in that case).
25172517
///
25182518
/// # Examples
25192519
///
@@ -2528,12 +2528,9 @@ impl<T, A: Allocator> Vec<T, A> {
25282528
/// assert_eq!(vec.pop_if(pred), None);
25292529
/// ```
25302530
#[unstable(feature = "vec_pop_if", issue = "122741")]
2531-
pub fn pop_if<F>(&mut self, f: F) -> Option<T>
2532-
where
2533-
F: FnOnce(&mut T) -> bool,
2534-
{
2531+
pub fn pop_if(&mut self, predicate: impl FnOnce(&mut T) -> bool) -> Option<T> {
25352532
let last = self.last_mut()?;
2536-
if f(last) { self.pop() } else { None }
2533+
if predicate(last) { self.pop() } else { None }
25372534
}
25382535

25392536
/// Moves all the elements of `other` into `self`, leaving `other` empty.
@@ -2574,9 +2571,11 @@ impl<T, A: Allocator> Vec<T, A> {
25742571
self.len += count;
25752572
}
25762573

2577-
/// Removes the specified range from the vector in bulk, returning all
2578-
/// removed elements as an iterator. If the iterator is dropped before
2579-
/// being fully consumed, it drops the remaining removed elements.
2574+
/// Removes the subslice indicated by the given range from the vector,
2575+
/// returning a double-ended iterator over the removed subslice.
2576+
///
2577+
/// If the iterator is dropped before being fully consumed,
2578+
/// it drops the remaining removed elements.
25802579
///
25812580
/// The returned iterator keeps a mutable borrow on the vector to optimize
25822581
/// its implementation.
@@ -3016,10 +3015,9 @@ impl<T: Clone, A: Allocator> Vec<T, A> {
30163015
/// Iterates over the slice `other`, clones each element, and then appends
30173016
/// it to this `Vec`. The `other` slice is traversed in-order.
30183017
///
3019-
/// Note that this function is same as [`extend`] except that it is
3020-
/// specialized to work with slices instead. If and when Rust gets
3021-
/// specialization this function will likely be deprecated (but still
3022-
/// available).
3018+
/// Note that this function is the same as [`extend`],
3019+
/// except that it also works with slice elements that are Clone but not Copy.
3020+
/// If Rust gets specialization this function may be deprecated.
30233021
///
30243022
/// # Examples
30253023
///

alloc/tests/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#![feature(str_as_str)]
3939
#![feature(strict_provenance_lints)]
4040
#![feature(vec_pop_if)]
41+
#![feature(vec_deque_pop_if)]
4142
#![feature(unique_rc_arc)]
4243
#![feature(macro_metavar_expr_concat)]
4344
#![allow(internal_features)]

alloc/tests/vec_deque.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,45 @@ fn test_parameterized<T: Clone + PartialEq + Debug>(a: T, b: T, c: T, d: T) {
8080
assert_eq!(deq[3].clone(), d.clone());
8181
}
8282

83+
#[test]
84+
fn test_pop_if() {
85+
let mut deq: VecDeque<_> = vec![0, 1, 2, 3, 4].into();
86+
let pred = |x: &mut i32| *x % 2 == 0;
87+
88+
assert_eq!(deq.pop_front_if(pred), Some(0));
89+
assert_eq!(deq, [1, 2, 3, 4]);
90+
91+
assert_eq!(deq.pop_front_if(pred), None);
92+
assert_eq!(deq, [1, 2, 3, 4]);
93+
94+
assert_eq!(deq.pop_back_if(pred), Some(4));
95+
assert_eq!(deq, [1, 2, 3]);
96+
97+
assert_eq!(deq.pop_back_if(pred), None);
98+
assert_eq!(deq, [1, 2, 3]);
99+
}
100+
101+
#[test]
102+
fn test_pop_if_empty() {
103+
let mut deq = VecDeque::<i32>::new();
104+
assert_eq!(deq.pop_front_if(|_| true), None);
105+
assert_eq!(deq.pop_back_if(|_| true), None);
106+
assert!(deq.is_empty());
107+
}
108+
109+
#[test]
110+
fn test_pop_if_mutates() {
111+
let mut v: VecDeque<_> = vec![-1, 1].into();
112+
let pred = |x: &mut i32| {
113+
*x *= 2;
114+
false
115+
};
116+
assert_eq!(v.pop_front_if(pred), None);
117+
assert_eq!(v, [-2, 1]);
118+
assert_eq!(v.pop_back_if(pred), None);
119+
assert_eq!(v, [-2, 2]);
120+
}
121+
83122
#[test]
84123
fn test_push_front_grow() {
85124
let mut deq = VecDeque::new();

core/src/array/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,6 @@ pub const fn from_mut<T>(s: &mut T) -> &mut [T; 1] {
156156

157157
/// The error type returned when a conversion from a slice to an array fails.
158158
#[stable(feature = "try_from", since = "1.34.0")]
159-
#[rustc_allowed_through_unstable_modules]
160159
#[derive(Debug, Copy, Clone)]
161160
pub struct TryFromSliceError(());
162161

core/src/num/nonzero.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,26 @@ impl_zeroable_primitive!(
9090
///
9191
/// assert_eq!(size_of::<Option<NonZero<u32>>>(), size_of::<u32>());
9292
/// ```
93+
///
94+
/// # Layout
95+
///
96+
/// `NonZero<T>` is guaranteed to have the same layout and bit validity as `T`
97+
/// with the exception that the all-zero bit pattern is invalid.
98+
/// `Option<NonZero<T>>` is guaranteed to be compatible with `T`, including in
99+
/// FFI.
100+
///
101+
/// Thanks to the [null pointer optimization], `NonZero<T>` and
102+
/// `Option<NonZero<T>>` are guaranteed to have the same size and alignment:
103+
///
104+
/// ```
105+
/// # use std::mem::{size_of, align_of};
106+
/// use std::num::NonZero;
107+
///
108+
/// assert_eq!(size_of::<NonZero<u32>>(), size_of::<Option<NonZero<u32>>>());
109+
/// assert_eq!(align_of::<NonZero<u32>>(), align_of::<Option<NonZero<u32>>>());
110+
/// ```
111+
///
112+
/// [null pointer optimization]: crate::option#representation
93113
#[stable(feature = "generic_nonzero", since = "1.79.0")]
94114
#[repr(transparent)]
95115
#[rustc_nonnull_optimization_guaranteed]

core/src/pin.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,8 @@
156156
//!
157157
//! In order to implement the second option, we must in some way enforce its key invariant,
158158
//! *i.e.* prevent the value from being *moved* or otherwise invalidated (you may notice this
159-
//! sounds an awful lot like the definition of *pinning* a value). There a few ways one might be
160-
//! able to enforce this invariant in Rust:
159+
//! sounds an awful lot like the definition of *pinning* a value). There are a few ways one might
160+
//! be able to enforce this invariant in Rust:
161161
//!
162162
//! 1. Offer a wholly `unsafe` API to interact with the object, thus requiring every caller to
163163
//! uphold the invariant themselves

proc_macro/src/bridge/closure.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use std::marker::PhantomData;
44

55
#[repr(C)]
6-
pub struct Closure<'a, A, R> {
6+
pub(super) struct Closure<'a, A, R> {
77
call: unsafe extern "C" fn(*mut Env, A) -> R,
88
env: *mut Env,
99
// Prevent Send and Sync impls. `!Send`/`!Sync` is the usual way of doing
@@ -26,7 +26,7 @@ impl<'a, A, R, F: FnMut(A) -> R> From<&'a mut F> for Closure<'a, A, R> {
2626
}
2727

2828
impl<'a, A, R> Closure<'a, A, R> {
29-
pub fn call(&mut self, arg: A) -> R {
29+
pub(super) fn call(&mut self, arg: A) -> R {
3030
unsafe { (self.call)(self.env, arg) }
3131
}
3232
}

proc_macro/src/bridge/fxhash.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use std::hash::{BuildHasherDefault, Hasher};
99
use std::ops::BitXor;
1010

1111
/// Type alias for a hashmap using the `fx` hash algorithm.
12-
pub type FxHashMap<K, V> = HashMap<K, V, BuildHasherDefault<FxHasher>>;
12+
pub(super) type FxHashMap<K, V> = HashMap<K, V, BuildHasherDefault<FxHasher>>;
1313

1414
/// A speedy hash algorithm for use within rustc. The hashmap in alloc by
1515
/// default uses SipHash which isn't quite as speedy as we want. In the compiler
@@ -23,7 +23,7 @@ pub type FxHashMap<K, V> = HashMap<K, V, BuildHasherDefault<FxHasher>>;
2323
/// similar or slightly worse than FNV, but the speed of the hash function
2424
/// itself is much higher because it works on up to 8 bytes at a time.
2525
#[derive(Default)]
26-
pub struct FxHasher {
26+
pub(super) struct FxHasher {
2727
hash: usize,
2828
}
2929

proc_macro/src/bridge/rpc.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ macro_rules! rpc_encode_decode {
6767
mod tag {
6868
#[repr(u8)] enum Tag { $($variant),* }
6969

70-
$(pub const $variant: u8 = Tag::$variant as u8;)*
70+
$(pub(crate) const $variant: u8 = Tag::$variant as u8;)*
7171
}
7272

7373
match self {
@@ -89,7 +89,7 @@ macro_rules! rpc_encode_decode {
8989
mod tag {
9090
#[repr(u8)] enum Tag { $($variant),* }
9191

92-
$(pub const $variant: u8 = Tag::$variant as u8;)*
92+
$(pub(crate) const $variant: u8 = Tag::$variant as u8;)*
9393
}
9494

9595
match u8::decode(r, s) {

0 commit comments

Comments
 (0)