Skip to content

Commit

Permalink
Auto merge of rust-lang#94834 - Dylan-DPC:rollup-sza4qc2, r=Dylan-DPC
Browse files Browse the repository at this point in the history
Rollup of 5 pull requests

Successful merges:

 - rust-lang#93293 (Implement `MIN`/`MAX` constants for non-zero integers)
 - rust-lang#94356 (Rename unix::net::SocketAddr::from_path to from_pathname and stabilize it)
 - rust-lang#94765 (Rename is_{some,ok,err}_with to is_{some,ok,err}_and.)
 - rust-lang#94819 (configure: don't serialize empty array elements)
 - rust-lang#94826 (Improve doc wording for retain on some collections)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Mar 11, 2022
2 parents c5a43b8 + f97a1c6 commit 8756ed2
Show file tree
Hide file tree
Showing 12 changed files with 132 additions and 29 deletions.
2 changes: 1 addition & 1 deletion library/alloc/src/collections/binary_heap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion library/alloc/src/collections/btree/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion library/alloc/src/collections/btree/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions library/alloc/src/collections/vec_deque/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand Down Expand Up @@ -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.
///
Expand Down
2 changes: 1 addition & 1 deletion library/alloc/src/vec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand Down
101 changes: 101 additions & 0 deletions library/core/src/num/nonzero.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
10 changes: 5 additions & 5 deletions library/core/src/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -551,26 +551,26 @@ 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
///
/// ```
/// #![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))
}

Expand Down
20 changes: 10 additions & 10 deletions library/core/src/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -542,26 +542,26 @@ 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
///
/// ```
/// #![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))
}

Expand All @@ -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
///
Expand All @@ -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))
}

Expand Down
2 changes: 1 addition & 1 deletion library/std/src/collections/hash/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion library/std/src/collections/hash/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 4 additions & 6 deletions library/std/src/os/unix/net/addr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
/// # }
Expand All @@ -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>,
{
Expand Down
4 changes: 4 additions & 0 deletions src/bootstrap/configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 8756ed2

Please sign in to comment.