From fe71c7431a0a1ae93436bf646df3676dc215ed86 Mon Sep 17 00:00:00 2001 From: Nikolai Vazquez Date: Tue, 25 Jan 2022 04:29:40 -0500 Subject: [PATCH 1/7] Implement `MIN`/`MAX` constants for non-zero integers --- library/core/src/num/nonzero.rs | 101 ++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) diff --git a/library/core/src/num/nonzero.rs b/library/core/src/num/nonzero.rs index e21ae48917953..a32631a06a5b6 100644 --- a/library/core/src/num/nonzero.rs +++ b/library/core/src/num/nonzero.rs @@ -988,3 +988,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. + /// + /// 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(), 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`].")] + /// + /// 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(); + } + )+ + } +} + +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`].")] + /// + /// # 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`].")] + /// + /// # 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); +} From 7f44b3a118a93497b3d60cb161dc71c1d2cb7e72 Mon Sep 17 00:00:00 2001 From: Thomas de Zeeuw Date: Fri, 25 Feb 2022 13:03:41 +0100 Subject: [PATCH 2/7] Rename unix::net::SocketAddr::from_path to from_pathname Matching SocketAddr::as_pathname. --- library/std/src/os/unix/net/addr.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/library/std/src/os/unix/net/addr.rs b/library/std/src/os/unix/net/addr.rs index 034fa301ba1ea..62bf4b6e862c6 100644 --- a/library/std/src/os/unix/net/addr.rs +++ b/library/std/src/os/unix/net/addr.rs @@ -145,7 +145,7 @@ impl 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(()) /// # } @@ -157,10 +157,10 @@ impl SocketAddr { /// #![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

(path: P) -> io::Result + pub fn from_pathname

(path: P) -> io::Result where P: AsRef, { From a84e77bebff4b3a0ab30108d720b47ddb6d027df Mon Sep 17 00:00:00 2001 From: Thomas de Zeeuw Date: Fri, 25 Feb 2022 13:04:40 +0100 Subject: [PATCH 3/7] Stabilize unix_socket_creation --- library/std/src/os/unix/net/addr.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/library/std/src/os/unix/net/addr.rs b/library/std/src/os/unix/net/addr.rs index 62bf4b6e862c6..03d59d773115e 100644 --- a/library/std/src/os/unix/net/addr.rs +++ b/library/std/src/os/unix/net/addr.rs @@ -140,7 +140,6 @@ impl SocketAddr { /// # Examples /// /// ``` - /// #![feature(unix_socket_creation)] /// use std::os::unix::net::SocketAddr; /// use std::path::Path; /// @@ -154,12 +153,11 @@ 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_pathname("/path/with/\0/bytes").is_err()); /// ``` - #[unstable(feature = "unix_socket_creation", issue = "93423")] + #[stable(feature = "unix_socket_creation", since = "1.61.0")] pub fn from_pathname

(path: P) -> io::Result where P: AsRef, From 7c7411fb5d6860d4687acd150e3e606c7f424686 Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Wed, 9 Mar 2022 11:20:36 +0100 Subject: [PATCH 4/7] Rename is_{some,ok,err}_with to is_{some,ok,err}_and. --- library/core/src/option.rs | 10 +++++----- library/core/src/result.rs | 20 ++++++++++---------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/library/core/src/option.rs b/library/core/src/option.rs index 508837f63c3be..9df56b3bfd51b 100644 --- a/library/core/src/option.rs +++ b/library/core/src/option.rs @@ -551,7 +551,7 @@ impl Option { 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 Option { /// #![feature(is_some_with)] /// /// let x: Option = 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 = 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 = 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)) } diff --git a/library/core/src/result.rs b/library/core/src/result.rs index 1827860a39045..e5a4dc06c6421 100644 --- a/library/core/src/result.rs +++ b/library/core/src/result.rs @@ -542,7 +542,7 @@ impl Result { 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 Result { /// #![feature(is_some_with)] /// /// let x: Result = 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 = 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 = 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 Result { !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 Result { /// use std::io::{Error, ErrorKind}; /// /// let x: Result = 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 = 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 = 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)) } From 7c20a29af8bffdd393e9e8a716de8266fcdae8bc Mon Sep 17 00:00:00 2001 From: Jon Gjengset Date: Thu, 10 Mar 2022 12:39:29 -0800 Subject: [PATCH 5/7] configure: don't serialize empty array elements Before this change: $ ./configure --codegen-backends= [..] $ grep -P '^codegen-backends' config.toml codegen-backends = [''] After this change: $ ./configure --codegen-backends= [..] $ grep -P '^codegen-backends' config.toml codegen-backends = [] --- src/bootstrap/configure.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/bootstrap/configure.py b/src/bootstrap/configure.py index 94424cb4548fa..87a130a09827d 100755 --- a/src/bootstrap/configure.py +++ b/src/bootstrap/configure.py @@ -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) From ecb792705077c6e6c116146cc797727a2cba4c47 Mon Sep 17 00:00:00 2001 From: Nikolai Vazquez Date: Thu, 10 Mar 2022 17:52:48 -0500 Subject: [PATCH 6/7] Move note about 0 gap to signed integers Was accidentally placed on unsigned integers, where it is not relevant. --- library/core/src/num/nonzero.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/library/core/src/num/nonzero.rs b/library/core/src/num/nonzero.rs index a32631a06a5b6..584e8a881df69 100644 --- a/library/core/src/num/nonzero.rs +++ b/library/core/src/num/nonzero.rs @@ -996,10 +996,6 @@ macro_rules! nonzero_min_max_unsigned { /// The smallest value that can be represented by this non-zero /// integer type, 1. /// - /// 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 /// /// ``` @@ -1015,10 +1011,6 @@ macro_rules! nonzero_min_max_unsigned { /// 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 /// /// ``` @@ -1042,6 +1034,10 @@ macro_rules! nonzero_min_max_signed { /// 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 /// /// ``` @@ -1057,6 +1053,10 @@ macro_rules! nonzero_min_max_signed { /// 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 /// /// ``` From 229e01d11fc5e6e34488beb5da05702de5eac632 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maik=20Allg=C3=B6wer?= Date: Fri, 11 Mar 2022 00:16:45 +0100 Subject: [PATCH 7/7] Improve doc wording for retain on some collections --- library/alloc/src/collections/binary_heap.rs | 2 +- library/alloc/src/collections/btree/map.rs | 2 +- library/alloc/src/collections/btree/set.rs | 2 +- library/alloc/src/collections/vec_deque/mod.rs | 4 ++-- library/alloc/src/vec/mod.rs | 2 +- library/std/src/collections/hash/map.rs | 2 +- library/std/src/collections/hash/set.rs | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/library/alloc/src/collections/binary_heap.rs b/library/alloc/src/collections/binary_heap.rs index e18cd8cd46427..eff21e5c11e7c 100644 --- a/library/alloc/src/collections/binary_heap.rs +++ b/library/alloc/src/collections/binary_heap.rs @@ -779,7 +779,7 @@ impl BinaryHeap { /// 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 diff --git a/library/alloc/src/collections/btree/map.rs b/library/alloc/src/collections/btree/map.rs index 7890c1040f0a1..12c9952558005 100644 --- a/library/alloc/src/collections/btree/map.rs +++ b/library/alloc/src/collections/btree/map.rs @@ -963,7 +963,7 @@ impl BTreeMap { /// 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 diff --git a/library/alloc/src/collections/btree/set.rs b/library/alloc/src/collections/btree/set.rs index bab6af8269864..c6a15953e8710 100644 --- a/library/alloc/src/collections/btree/set.rs +++ b/library/alloc/src/collections/btree/set.rs @@ -873,7 +873,7 @@ impl BTreeSet { /// 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 diff --git a/library/alloc/src/collections/vec_deque/mod.rs b/library/alloc/src/collections/vec_deque/mod.rs index 7139a0fb94d76..c3cabc754e6a8 100644 --- a/library/alloc/src/collections/vec_deque/mod.rs +++ b/library/alloc/src/collections/vec_deque/mod.rs @@ -2119,7 +2119,7 @@ impl VecDeque { /// 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 VecDeque { /// 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. /// diff --git a/library/alloc/src/vec/mod.rs b/library/alloc/src/vec/mod.rs index c4c393f55eee9..b898bd8743f63 100644 --- a/library/alloc/src/vec/mod.rs +++ b/library/alloc/src/vec/mod.rs @@ -1424,7 +1424,7 @@ impl Vec { /// 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. /// diff --git a/library/std/src/collections/hash/map.rs b/library/std/src/collections/hash/map.rs index c0524352193f9..59dc13246aa3a 100644 --- a/library/std/src/collections/hash/map.rs +++ b/library/std/src/collections/hash/map.rs @@ -621,7 +621,7 @@ impl HashMap { /// 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 diff --git a/library/std/src/collections/hash/set.rs b/library/std/src/collections/hash/set.rs index 2eb4cacabb831..4fd6996269e50 100644 --- a/library/std/src/collections/hash/set.rs +++ b/library/std/src/collections/hash/set.rs @@ -300,7 +300,7 @@ impl HashSet { /// 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