Skip to content

Commit 989b6e2

Browse files
committed
Auto merge of rust-lang#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](rust-lang#76198). Possible because of the recent stabilization of const control flow. Part of rust-lang#76225 and rust-lang#76205.
2 parents 78c9416 + d6a9806 commit 989b6e2

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

std/src/net/ip.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,8 +263,9 @@ impl IpAddr {
263263
/// assert_eq!(IpAddr::V4(Ipv4Addr::new(203, 0, 113, 6)).is_ipv4(), true);
264264
/// assert_eq!(IpAddr::V6(Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 0)).is_ipv4(), false);
265265
/// ```
266+
#[rustc_const_stable(feature = "const_ip", since = "1.50.0")]
266267
#[stable(feature = "ipaddr_checker", since = "1.16.0")]
267-
pub fn is_ipv4(&self) -> bool {
268+
pub const fn is_ipv4(&self) -> bool {
268269
matches!(self, IpAddr::V4(_))
269270
}
270271

@@ -281,8 +282,9 @@ impl IpAddr {
281282
/// assert_eq!(IpAddr::V4(Ipv4Addr::new(203, 0, 113, 6)).is_ipv6(), false);
282283
/// assert_eq!(IpAddr::V6(Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 0)).is_ipv6(), true);
283284
/// ```
285+
#[rustc_const_stable(feature = "const_ip", since = "1.50.0")]
284286
#[stable(feature = "ipaddr_checker", since = "1.16.0")]
285-
pub fn is_ipv6(&self) -> bool {
287+
pub const fn is_ipv6(&self) -> bool {
286288
matches!(self, IpAddr::V6(_))
287289
}
288290
}

0 commit comments

Comments
 (0)