about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2022-05-05 09:45:53 +0000
committerbors <bors@rust-lang.org>2022-05-05 09:45:53 +0000
commit322a14919d6cc67af45477b623857b30fae63f9d (patch)
tree31a637c35fa5949f65c67efdcc28281a5f4d9075
parent3d18f945cab17c98a2d4bedd174c47a24ecfe8f4 (diff)
parented95d502c66b26e3d991dd32f849819c6252385e (diff)
downloadrust-322a14919d6cc67af45477b623857b30fae63f9d.tar.gz
rust-322a14919d6cc67af45477b623857b30fae63f9d.zip
Auto merge of #96649 - tbu-:pr_to_ipv4_loopback_doc, r=m-ou-se
Make it clear that `to_ipv4` returns an IPv4 address for the IPv6 loopback
-rw-r--r--library/std/src/net/ip.rs5
1 files changed, 4 insertions, 1 deletions
diff --git a/library/std/src/net/ip.rs b/library/std/src/net/ip.rs
index 036f2919976..f629a1a0f99 100644
--- a/library/std/src/net/ip.rs
+++ b/library/std/src/net/ip.rs
@@ -138,6 +138,7 @@ pub struct Ipv4Addr {
 ///
 /// To convert from an IPv4 address to an IPv4-mapped IPv6 address, use [`Ipv4Addr::to_ipv6_mapped`].
 /// Use [`Ipv6Addr::to_ipv4`] to convert an IPv4-mapped IPv6 address to the canonical IPv4 address.
+/// Note that this will also convert the IPv6 loopback address `::1` to `0.0.0.1`.
 ///
 /// [IETF RFC 4291 Section 2.5.5.2]: https://datatracker.ietf.org/doc/html/rfc4291#section-2.5.5.2
 ///
@@ -1673,7 +1674,9 @@ impl Ipv6Addr {
     /// or an [IPv4-mapped] address as defined in [IETF RFC 4291 section 2.5.5.2],
     /// otherwise returns [`None`].
     ///
-    /// `::a.b.c.d` and `::ffff:a.b.c.d` become `a.b.c.d`
+    /// Note that this will return an [`IPv4` address] for the IPv6 loopback address `::1`.
+    ///
+    /// `::a.b.c.d` and `::ffff:a.b.c.d` become `a.b.c.d`. `::1` becomes `0.0.0.1`.
     /// All addresses *not* starting with either all zeroes or `::ffff` will return `None`.
     ///
     /// [`IPv4` address]: Ipv4Addr