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

Diff for: alloc/src/collections/vec_deque/mod.rs

+46
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

Diff for: alloc/src/vec/mod.rs

+12-14
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
///

Diff for: alloc/tests/lib.rs

+1
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)]

Diff for: alloc/tests/vec_deque.rs

+39
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();

Diff for: core/src/array/mod.rs

-1
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

Diff for: core/src/num/nonzero.rs

+20
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]

Diff for: core/src/pin.rs

+2-2
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

Diff for: proc_macro/src/bridge/closure.rs

+2-2
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
}

Diff for: proc_macro/src/bridge/fxhash.rs

+2-2
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

Diff for: proc_macro/src/bridge/rpc.rs

+2-2
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) {

Diff for: proc_macro/src/bridge/selfless_reify.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ macro_rules! define_reify_functions {
4444
fn $name:ident $(<$($param:ident),*>)?
4545
for $(extern $abi:tt)? fn($($arg:ident: $arg_ty:ty),*) -> $ret_ty:ty;
4646
)+) => {
47-
$(pub const fn $name<
47+
$(pub(super) const fn $name<
4848
$($($param,)*)?
4949
F: Fn($($arg_ty),*) -> $ret_ty + Copy
5050
>(f: F) -> $(extern $abi)? fn($($arg_ty),*) -> $ret_ty {

Diff for: proc_macro/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#![allow(internal_features)]
3333
#![deny(ffi_unwind_calls)]
3434
#![warn(rustdoc::unescaped_backticks)]
35+
#![warn(unreachable_pub)]
3536

3637
#[unstable(feature = "proc_macro_internals", issue = "27812")]
3738
#[doc(hidden)]

Diff for: std/src/fs.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2529,6 +2529,7 @@ pub fn copy<P: AsRef<Path>, Q: AsRef<Path>>(from: P, to: Q) -> io::Result<u64> {
25292529
/// limited to just these cases:
25302530
///
25312531
/// * The `original` path is not a file or doesn't exist.
2532+
/// * The 'link' path already exists.
25322533
///
25332534
/// # Examples
25342535
///

Diff for: test/src/cli.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ impl TestOpts {
4444
}
4545

4646
/// Result of parsing the options.
47-
pub type OptRes = Result<TestOpts, String>;
47+
pub(crate) type OptRes = Result<TestOpts, String>;
4848
/// Result of parsing the option part.
4949
type OptPartRes<T> = Result<T, String>;
5050

Diff for: test/src/console.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use super::types::{NamePadding, TestDesc, TestDescAndFn};
2020
use super::{filter_tests, run_tests, term};
2121

2222
/// Generic wrapper over stdout.
23-
pub enum OutputLocation<T> {
23+
pub(crate) enum OutputLocation<T> {
2424
Pretty(Box<term::StdoutTerminal>),
2525
Raw(T),
2626
}
@@ -41,15 +41,15 @@ impl<T: Write> Write for OutputLocation<T> {
4141
}
4242
}
4343

44-
pub struct ConsoleTestDiscoveryState {
44+
pub(crate) struct ConsoleTestDiscoveryState {
4545
pub log_out: Option<File>,
4646
pub tests: usize,
4747
pub benchmarks: usize,
4848
pub ignored: usize,
4949
}
5050

5151
impl ConsoleTestDiscoveryState {
52-
pub fn new(opts: &TestOpts) -> io::Result<ConsoleTestDiscoveryState> {
52+
pub(crate) fn new(opts: &TestOpts) -> io::Result<ConsoleTestDiscoveryState> {
5353
let log_out = match opts.logfile {
5454
Some(ref path) => Some(File::create(path)?),
5555
None => None,
@@ -58,7 +58,7 @@ impl ConsoleTestDiscoveryState {
5858
Ok(ConsoleTestDiscoveryState { log_out, tests: 0, benchmarks: 0, ignored: 0 })
5959
}
6060

61-
pub fn write_log<F, S>(&mut self, msg: F) -> io::Result<()>
61+
pub(crate) fn write_log<F, S>(&mut self, msg: F) -> io::Result<()>
6262
where
6363
S: AsRef<str>,
6464
F: FnOnce() -> S,
@@ -74,7 +74,7 @@ impl ConsoleTestDiscoveryState {
7474
}
7575
}
7676

77-
pub struct ConsoleTestState {
77+
pub(crate) struct ConsoleTestState {
7878
pub log_out: Option<File>,
7979
pub total: usize,
8080
pub passed: usize,
@@ -92,7 +92,7 @@ pub struct ConsoleTestState {
9292
}
9393

9494
impl ConsoleTestState {
95-
pub fn new(opts: &TestOpts) -> io::Result<ConsoleTestState> {
95+
pub(crate) fn new(opts: &TestOpts) -> io::Result<ConsoleTestState> {
9696
let log_out = match opts.logfile {
9797
Some(ref path) => Some(File::create(path)?),
9898
None => None,
@@ -116,7 +116,7 @@ impl ConsoleTestState {
116116
})
117117
}
118118

119-
pub fn write_log<F, S>(&mut self, msg: F) -> io::Result<()>
119+
pub(crate) fn write_log<F, S>(&mut self, msg: F) -> io::Result<()>
120120
where
121121
S: AsRef<str>,
122122
F: FnOnce() -> S,
@@ -131,7 +131,7 @@ impl ConsoleTestState {
131131
}
132132
}
133133

134-
pub fn write_log_result(
134+
pub(crate) fn write_log_result(
135135
&mut self,
136136
test: &TestDesc,
137137
result: &TestResult,
@@ -170,7 +170,7 @@ impl ConsoleTestState {
170170
}
171171

172172
// List the tests to console, and optionally to logfile. Filters are honored.
173-
pub fn list_tests_console(opts: &TestOpts, tests: Vec<TestDescAndFn>) -> io::Result<()> {
173+
pub(crate) fn list_tests_console(opts: &TestOpts, tests: Vec<TestDescAndFn>) -> io::Result<()> {
174174
let output = match term::stdout() {
175175
None => OutputLocation::Raw(io::stdout().lock()),
176176
Some(t) => OutputLocation::Pretty(t),

Diff for: test/src/formatters/json.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pub(crate) struct JsonFormatter<T> {
1313
}
1414

1515
impl<T: Write> JsonFormatter<T> {
16-
pub fn new(out: OutputLocation<T>) -> Self {
16+
pub(crate) fn new(out: OutputLocation<T>) -> Self {
1717
Self { out }
1818
}
1919

0 commit comments

Comments
 (0)