about summary refs log tree commit diff
path: root/library/std/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2020-11-23 04:47:25 +0000
committerbors <bors@rust-lang.org>2020-11-23 04:47:25 +0000
commit1823a87986c6acf0765c0101d75bca5328416a60 (patch)
treeb44fb72ecd0d71180f089f3a8637be72f0f98e0b /library/std/src
parentf32459c7ba767e7f26e3c4c4bd6be326d83bcb78 (diff)
parent4613bc96a4dd8b492623aac79d91314041d17af0 (diff)
downloadrust-1823a87986c6acf0765c0101d75bca5328416a60.tar.gz
rust-1823a87986c6acf0765c0101d75bca5328416a60.zip
Auto merge of #76226 - CDirkx:const-ipaddr, r=dtolnay
Stabilize `IpAddr::is_ipv4` and `is_ipv6` as const

Insta-stabilize the methods `is_ipv4` and `is_ipv6` of `std::net::IpAddr` as const, in the same way as [PR#76198](https://github.com/rust-lang/rust/pull/76198).

Possible because of the recent stabilization of const control flow.

Part of #76225 and #76205.
Diffstat (limited to 'library/std/src')
-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 04b6f0a5b91..87bbd33bc01 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.50.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.50.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(_))
     }
 }