Skip to content

Commit d125574

Browse files
committed
Auto merge of #96906 - tbu-:pr_stabilize_to_ipv4_mapped, r=dtolnay
Stabilize `Ipv6Addr::to_ipv4_mapped` CC #27709 (tracking issue for the `ip` feature which contains more functions) The function `Ipv6Addr::to_ipv4` is bad because it also returns an IPv4 address for the IPv6 loopback address `::1`. Stabilize `Ipv6Addr::to_ipv4_mapped` so we can recommend that function instead.
2 parents 07e7b43 + 813c5b0 commit d125574

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

library/std/src/net/ip.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,8 @@ pub struct Ipv4Addr {
138138
///
139139
/// To convert from an IPv4 address to an IPv4-mapped IPv6 address, use [`Ipv4Addr::to_ipv6_mapped`].
140140
/// Use [`Ipv6Addr::to_ipv4`] to convert an IPv4-mapped IPv6 address to the canonical IPv4 address.
141-
/// Note that this will also convert the IPv6 loopback address `::1` to `0.0.0.1`.
141+
/// Note that this will also convert the IPv6 loopback address `::1` to `0.0.0.1`. Use
142+
/// [`Ipv6Addr::to_ipv4_mapped`] to avoid this.
142143
///
143144
/// [IETF RFC 4291 Section 2.5.5.2]: https://datatracker.ietf.org/doc/html/rfc4291#section-2.5.5.2
144145
///
@@ -1646,8 +1647,6 @@ impl Ipv6Addr {
16461647
/// # Examples
16471648
///
16481649
/// ```
1649-
/// #![feature(ip)]
1650-
///
16511650
/// use std::net::{Ipv4Addr, Ipv6Addr};
16521651
///
16531652
/// assert_eq!(Ipv6Addr::new(0xff00, 0, 0, 0, 0, 0, 0, 0).to_ipv4_mapped(), None);
@@ -1656,7 +1655,7 @@ impl Ipv6Addr {
16561655
/// assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1).to_ipv4_mapped(), None);
16571656
/// ```
16581657
#[rustc_const_unstable(feature = "const_ipv6", issue = "76205")]
1659-
#[unstable(feature = "ip", issue = "27709")]
1658+
#[stable(feature = "ipv6_to_ipv4_mapped", since = "1.62.0")]
16601659
#[must_use = "this returns the result of the operation, \
16611660
without modifying the original"]
16621661
#[inline]
@@ -1674,7 +1673,8 @@ impl Ipv6Addr {
16741673
/// or an [IPv4-mapped] address as defined in [IETF RFC 4291 section 2.5.5.2],
16751674
/// otherwise returns [`None`].
16761675
///
1677-
/// Note that this will return an [`IPv4` address] for the IPv6 loopback address `::1`.
1676+
/// Note that this will return an [`IPv4` address] for the IPv6 loopback address `::1`. Use
1677+
/// [`Ipv6Addr::to_ipv4_mapped`] to avoid this.
16781678
///
16791679
/// `::a.b.c.d` and `::ffff:a.b.c.d` become `a.b.c.d`. `::1` becomes `0.0.0.1`.
16801680
/// All addresses *not* starting with either all zeroes or `::ffff` will return `None`.

0 commit comments

Comments
 (0)