mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-30 18:53:39 +00:00
Auto merge of #94834 - Dylan-DPC:rollup-sza4qc2, r=Dylan-DPC
Rollup of 5 pull requests Successful merges: - #93293 (Implement `MIN`/`MAX` constants for non-zero integers) - #94356 (Rename unix::net::SocketAddr::from_path to from_pathname and stabilize it) - #94765 (Rename is_{some,ok,err}_with to is_{some,ok,err}_and.) - #94819 (configure: don't serialize empty array elements) - #94826 (Improve doc wording for retain on some collections) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
This commit is contained in:
commit
8756ed20b2
@ -779,7 +779,7 @@ impl<T: Ord> BinaryHeap<T> {
|
||||
|
||||
/// Retains only the elements specified by the predicate.
|
||||
///
|
||||
/// In other words, remove all elements `e` such that `f(&e)` returns
|
||||
/// In other words, remove all elements `e` for which `f(&e)` returns
|
||||
/// `false`. The elements are visited in unsorted (and unspecified) order.
|
||||
///
|
||||
/// # Examples
|
||||
|
@ -963,7 +963,7 @@ impl<K, V> BTreeMap<K, V> {
|
||||
|
||||
/// Retains only the elements specified by the predicate.
|
||||
///
|
||||
/// In other words, remove all pairs `(k, v)` such that `f(&k, &mut v)` returns `false`.
|
||||
/// In other words, remove all pairs `(k, v)` for which `f(&k, &mut v)` returns `false`.
|
||||
/// The elements are visited in ascending key order.
|
||||
///
|
||||
/// # Examples
|
||||
|
@ -873,7 +873,7 @@ impl<T> BTreeSet<T> {
|
||||
|
||||
/// Retains only the elements specified by the predicate.
|
||||
///
|
||||
/// In other words, remove all elements `e` such that `f(&e)` returns `false`.
|
||||
/// In other words, remove all elements `e` for which `f(&e)` returns `false`.
|
||||
/// The elements are visited in ascending order.
|
||||
///
|
||||
/// # Examples
|
||||
|
@ -2119,7 +2119,7 @@ impl<T, A: Allocator> VecDeque<T, A> {
|
||||
|
||||
/// Retains only the elements specified by the predicate.
|
||||
///
|
||||
/// In other words, remove all elements `e` such that `f(&e)` returns false.
|
||||
/// In other words, remove all elements `e` for which `f(&e)` returns false.
|
||||
/// This method operates in place, visiting each element exactly once in the
|
||||
/// original order, and preserves the order of the retained elements.
|
||||
///
|
||||
@ -2158,7 +2158,7 @@ impl<T, A: Allocator> VecDeque<T, A> {
|
||||
|
||||
/// Retains only the elements specified by the predicate.
|
||||
///
|
||||
/// In other words, remove all elements `e` such that `f(&e)` returns false.
|
||||
/// In other words, remove all elements `e` for which `f(&e)` returns false.
|
||||
/// This method operates in place, visiting each element exactly once in the
|
||||
/// original order, and preserves the order of the retained elements.
|
||||
///
|
||||
|
@ -1424,7 +1424,7 @@ impl<T, A: Allocator> Vec<T, A> {
|
||||
|
||||
/// Retains only the elements specified by the predicate.
|
||||
///
|
||||
/// In other words, remove all elements `e` such that `f(&e)` returns `false`.
|
||||
/// In other words, remove all elements `e` for which `f(&e)` returns `false`.
|
||||
/// This method operates in place, visiting each element exactly once in the
|
||||
/// original order, and preserves the order of the retained elements.
|
||||
///
|
||||
|
@ -989,3 +989,104 @@ macro_rules! nonzero_unsigned_is_power_of_two {
|
||||
}
|
||||
|
||||
nonzero_unsigned_is_power_of_two! { NonZeroU8 NonZeroU16 NonZeroU32 NonZeroU64 NonZeroU128 NonZeroUsize }
|
||||
|
||||
macro_rules! nonzero_min_max_unsigned {
|
||||
( $( $Ty: ident($Int: ident); )+ ) => {
|
||||
$(
|
||||
impl $Ty {
|
||||
/// The smallest value that can be represented by this non-zero
|
||||
/// integer type, 1.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(nonzero_min_max)]
|
||||
#[doc = concat!("# use std::num::", stringify!($Ty), ";")]
|
||||
///
|
||||
#[doc = concat!("assert_eq!(", stringify!($Ty), "::MIN.get(), 1", stringify!($Int), ");")]
|
||||
/// ```
|
||||
#[unstable(feature = "nonzero_min_max", issue = "89065")]
|
||||
pub const MIN: Self = Self::new(1).unwrap();
|
||||
|
||||
/// The largest value that can be represented by this non-zero
|
||||
/// integer type,
|
||||
#[doc = concat!("equal to [`", stringify!($Int), "::MAX`].")]
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(nonzero_min_max)]
|
||||
#[doc = concat!("# use std::num::", stringify!($Ty), ";")]
|
||||
///
|
||||
#[doc = concat!("assert_eq!(", stringify!($Ty), "::MAX.get(), ", stringify!($Int), "::MAX);")]
|
||||
/// ```
|
||||
#[unstable(feature = "nonzero_min_max", issue = "89065")]
|
||||
pub const MAX: Self = Self::new(<$Int>::MAX).unwrap();
|
||||
}
|
||||
)+
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! nonzero_min_max_signed {
|
||||
( $( $Ty: ident($Int: ident); )+ ) => {
|
||||
$(
|
||||
impl $Ty {
|
||||
/// The smallest value that can be represented by this non-zero
|
||||
/// integer type,
|
||||
#[doc = concat!("equal to [`", stringify!($Int), "::MIN`].")]
|
||||
///
|
||||
/// Note: While most integer types are defined for every whole
|
||||
/// number between `MIN` and `MAX`, signed non-zero integers are
|
||||
/// a special case. They have a "gap" at 0.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(nonzero_min_max)]
|
||||
#[doc = concat!("# use std::num::", stringify!($Ty), ";")]
|
||||
///
|
||||
#[doc = concat!("assert_eq!(", stringify!($Ty), "::MIN.get(), ", stringify!($Int), "::MIN);")]
|
||||
/// ```
|
||||
#[unstable(feature = "nonzero_min_max", issue = "89065")]
|
||||
pub const MIN: Self = Self::new(<$Int>::MIN).unwrap();
|
||||
|
||||
/// The largest value that can be represented by this non-zero
|
||||
/// integer type,
|
||||
#[doc = concat!("equal to [`", stringify!($Int), "::MAX`].")]
|
||||
///
|
||||
/// Note: While most integer types are defined for every whole
|
||||
/// number between `MIN` and `MAX`, signed non-zero integers are
|
||||
/// a special case. They have a "gap" at 0.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(nonzero_min_max)]
|
||||
#[doc = concat!("# use std::num::", stringify!($Ty), ";")]
|
||||
///
|
||||
#[doc = concat!("assert_eq!(", stringify!($Ty), "::MAX.get(), ", stringify!($Int), "::MAX);")]
|
||||
/// ```
|
||||
#[unstable(feature = "nonzero_min_max", issue = "89065")]
|
||||
pub const MAX: Self = Self::new(<$Int>::MAX).unwrap();
|
||||
}
|
||||
)+
|
||||
}
|
||||
}
|
||||
|
||||
nonzero_min_max_unsigned! {
|
||||
NonZeroU8(u8);
|
||||
NonZeroU16(u16);
|
||||
NonZeroU32(u32);
|
||||
NonZeroU64(u64);
|
||||
NonZeroU128(u128);
|
||||
NonZeroUsize(usize);
|
||||
}
|
||||
|
||||
nonzero_min_max_signed! {
|
||||
NonZeroI8(i8);
|
||||
NonZeroI16(i16);
|
||||
NonZeroI32(i32);
|
||||
NonZeroI64(i64);
|
||||
NonZeroI128(i128);
|
||||
NonZeroIsize(isize);
|
||||
}
|
||||
|
@ -551,7 +551,7 @@ impl<T> Option<T> {
|
||||
matches!(*self, Some(_))
|
||||
}
|
||||
|
||||
/// Returns `true` if the option is a [`Some`] wrapping a value matching the predicate.
|
||||
/// Returns `true` if the option is a [`Some`] and the value inside of it matches a predicate.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
@ -559,18 +559,18 @@ impl<T> Option<T> {
|
||||
/// #![feature(is_some_with)]
|
||||
///
|
||||
/// let x: Option<u32> = Some(2);
|
||||
/// assert_eq!(x.is_some_with(|&x| x > 1), true);
|
||||
/// assert_eq!(x.is_some_and(|&x| x > 1), true);
|
||||
///
|
||||
/// let x: Option<u32> = Some(0);
|
||||
/// assert_eq!(x.is_some_with(|&x| x > 1), false);
|
||||
/// assert_eq!(x.is_some_and(|&x| x > 1), false);
|
||||
///
|
||||
/// let x: Option<u32> = None;
|
||||
/// assert_eq!(x.is_some_with(|&x| x > 1), false);
|
||||
/// assert_eq!(x.is_some_and(|&x| x > 1), false);
|
||||
/// ```
|
||||
#[must_use]
|
||||
#[inline]
|
||||
#[unstable(feature = "is_some_with", issue = "93050")]
|
||||
pub fn is_some_with(&self, f: impl FnOnce(&T) -> bool) -> bool {
|
||||
pub fn is_some_and(&self, f: impl FnOnce(&T) -> bool) -> bool {
|
||||
matches!(self, Some(x) if f(x))
|
||||
}
|
||||
|
||||
|
@ -542,7 +542,7 @@ impl<T, E> Result<T, E> {
|
||||
matches!(*self, Ok(_))
|
||||
}
|
||||
|
||||
/// Returns `true` if the result is [`Ok`] wrapping a value matching the predicate.
|
||||
/// Returns `true` if the result is [`Ok`] and the value inside of it matches a predicate.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
@ -550,18 +550,18 @@ impl<T, E> Result<T, E> {
|
||||
/// #![feature(is_some_with)]
|
||||
///
|
||||
/// let x: Result<u32, &str> = Ok(2);
|
||||
/// assert_eq!(x.is_ok_with(|&x| x > 1), true);
|
||||
/// assert_eq!(x.is_ok_and(|&x| x > 1), true);
|
||||
///
|
||||
/// let x: Result<u32, &str> = Ok(0);
|
||||
/// assert_eq!(x.is_ok_with(|&x| x > 1), false);
|
||||
/// assert_eq!(x.is_ok_and(|&x| x > 1), false);
|
||||
///
|
||||
/// let x: Result<u32, &str> = Err("hey");
|
||||
/// assert_eq!(x.is_ok_with(|&x| x > 1), false);
|
||||
/// assert_eq!(x.is_ok_and(|&x| x > 1), false);
|
||||
/// ```
|
||||
#[must_use]
|
||||
#[inline]
|
||||
#[unstable(feature = "is_some_with", issue = "93050")]
|
||||
pub fn is_ok_with(&self, f: impl FnOnce(&T) -> bool) -> bool {
|
||||
pub fn is_ok_and(&self, f: impl FnOnce(&T) -> bool) -> bool {
|
||||
matches!(self, Ok(x) if f(x))
|
||||
}
|
||||
|
||||
@ -586,7 +586,7 @@ impl<T, E> Result<T, E> {
|
||||
!self.is_ok()
|
||||
}
|
||||
|
||||
/// Returns `true` if the result is [`Err`] wrapping a value matching the predicate.
|
||||
/// Returns `true` if the result is [`Err`] and the value inside of it matches a predicate.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
@ -595,18 +595,18 @@ impl<T, E> Result<T, E> {
|
||||
/// use std::io::{Error, ErrorKind};
|
||||
///
|
||||
/// let x: Result<u32, Error> = Err(Error::new(ErrorKind::NotFound, "!"));
|
||||
/// assert_eq!(x.is_err_with(|x| x.kind() == ErrorKind::NotFound), true);
|
||||
/// assert_eq!(x.is_err_and(|x| x.kind() == ErrorKind::NotFound), true);
|
||||
///
|
||||
/// let x: Result<u32, Error> = Err(Error::new(ErrorKind::PermissionDenied, "!"));
|
||||
/// assert_eq!(x.is_err_with(|x| x.kind() == ErrorKind::NotFound), false);
|
||||
/// assert_eq!(x.is_err_and(|x| x.kind() == ErrorKind::NotFound), false);
|
||||
///
|
||||
/// let x: Result<u32, Error> = Ok(123);
|
||||
/// assert_eq!(x.is_err_with(|x| x.kind() == ErrorKind::NotFound), false);
|
||||
/// assert_eq!(x.is_err_and(|x| x.kind() == ErrorKind::NotFound), false);
|
||||
/// ```
|
||||
#[must_use]
|
||||
#[inline]
|
||||
#[unstable(feature = "is_some_with", issue = "93050")]
|
||||
pub fn is_err_with(&self, f: impl FnOnce(&E) -> bool) -> bool {
|
||||
pub fn is_err_and(&self, f: impl FnOnce(&E) -> bool) -> bool {
|
||||
matches!(self, Err(x) if f(x))
|
||||
}
|
||||
|
||||
|
@ -621,7 +621,7 @@ impl<K, V, S> HashMap<K, V, S> {
|
||||
|
||||
/// Retains only the elements specified by the predicate.
|
||||
///
|
||||
/// In other words, remove all pairs `(k, v)` such that `f(&k, &mut v)` returns `false`.
|
||||
/// In other words, remove all pairs `(k, v)` for which `f(&k, &mut v)` returns `false`.
|
||||
/// The elements are visited in unsorted (and unspecified) order.
|
||||
///
|
||||
/// # Examples
|
||||
|
@ -300,7 +300,7 @@ impl<T, S> HashSet<T, S> {
|
||||
|
||||
/// Retains only the elements specified by the predicate.
|
||||
///
|
||||
/// In other words, remove all elements `e` such that `f(&e)` returns `false`.
|
||||
/// In other words, remove all elements `e` for which `f(&e)` returns `false`.
|
||||
/// The elements are visited in unsorted (and unspecified) order.
|
||||
///
|
||||
/// # Examples
|
||||
|
@ -140,12 +140,11 @@ impl SocketAddr {
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(unix_socket_creation)]
|
||||
/// use std::os::unix::net::SocketAddr;
|
||||
/// use std::path::Path;
|
||||
///
|
||||
/// # fn main() -> std::io::Result<()> {
|
||||
/// let address = SocketAddr::from_path("/path/to/socket")?;
|
||||
/// let address = SocketAddr::from_pathname("/path/to/socket")?;
|
||||
/// assert_eq!(address.as_pathname(), Some(Path::new("/path/to/socket")));
|
||||
/// # Ok(())
|
||||
/// # }
|
||||
@ -154,13 +153,12 @@ impl SocketAddr {
|
||||
/// Creating a `SocketAddr` with a NULL byte results in an error.
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(unix_socket_creation)]
|
||||
/// use std::os::unix::net::SocketAddr;
|
||||
///
|
||||
/// assert!(SocketAddr::from_path("/path/with/\0/bytes").is_err());
|
||||
/// assert!(SocketAddr::from_pathname("/path/with/\0/bytes").is_err());
|
||||
/// ```
|
||||
#[unstable(feature = "unix_socket_creation", issue = "93423")]
|
||||
pub fn from_path<P>(path: P) -> io::Result<SocketAddr>
|
||||
#[stable(feature = "unix_socket_creation", since = "1.61.0")]
|
||||
pub fn from_pathname<P>(path: P) -> io::Result<SocketAddr>
|
||||
where
|
||||
P: AsRef<Path>,
|
||||
{
|
||||
|
@ -279,6 +279,10 @@ def build():
|
||||
|
||||
|
||||
def set(key, value):
|
||||
if isinstance(value, list):
|
||||
# Remove empty values, which value.split(',') tends to generate.
|
||||
value = [v for v in value if v]
|
||||
|
||||
s = "{:20} := {}".format(key, value)
|
||||
if len(s) < 70:
|
||||
p(s)
|
||||
|
Loading…
Reference in New Issue
Block a user