about summary refs log tree commit diff
path: root/library/std
diff options
context:
space:
mode:
authorChristiaan Dirkx <christiaan@dirkx.email>2020-09-02 02:05:42 +0200
committerChristiaan Dirkx <christiaan@dirkx.email>2020-11-23 01:33:46 +0100
commit3f8fdf83ff2182938b29b93cbf92aec62e1f96cd (patch)
tree68bc7ef6acd215e94c53c9354e51af9dc0f8fdf4 /library/std
parent4ec27e4b79891b0ebc2ad71a3c4ac94f67d93f93 (diff)
downloadrust-3f8fdf83ff2182938b29b93cbf92aec62e1f96cd.tar.gz
rust-3f8fdf83ff2182938b29b93cbf92aec62e1f96cd.zip
Stabilize `IpAddr::is_ipv4` and `is_ipv6` as const
Insta-stabilize the methods `is_ipv4` and `is_ipv6` of `IpAddr`.

Possible because of the recent stabilization of const control flow.

Also adds a test for these methods in a const context.
Diffstat (limited to 'library/std')
-rw-r--r--library/std/src/net/ip.rs6
1 files changed, 4 insertions, 2 deletions
diff --git a/library/std/src/net/ip.rs b/library/std/src/net/ip.rs
index bb3ece4c273..714ff78777c 100644
--- a/library/std/src/net/ip.rs
+++ b/library/std/src/net/ip.rs
@@ -263,8 +263,9 @@ impl IpAddr {
     /// assert_eq!(IpAddr::V4(Ipv4Addr::new(203, 0, 113, 6)).is_ipv4(), true);
     /// assert_eq!(IpAddr::V6(Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 0)).is_ipv4(), false);
     /// ```
+    #[rustc_const_stable(feature = "const_ip", since = "1.48.0")]
     #[stable(feature = "ipaddr_checker", since = "1.16.0")]
-    pub fn is_ipv4(&self) -> bool {
+    pub const fn is_ipv4(&self) -> bool {
         matches!(self, IpAddr::V4(_))
     }
 
@@ -281,8 +282,9 @@ impl IpAddr {
     /// assert_eq!(IpAddr::V4(Ipv4Addr::new(203, 0, 113, 6)).is_ipv6(), false);
     /// assert_eq!(IpAddr::V6(Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 0)).is_ipv6(), true);
     /// ```
+    #[rustc_const_stable(feature = "const_ip", since = "1.48.0")]
     #[stable(feature = "ipaddr_checker", since = "1.16.0")]
-    pub fn is_ipv6(&self) -> bool {
+    pub const fn is_ipv6(&self) -> bool {
         matches!(self, IpAddr::V6(_))
     }
 }