Skip to content

use IPV6 loopback and documentation address in documentation over V4 by default - #161879

Open
2ndDerivative wants to merge 18 commits into
rust-lang:mainfrom
2ndDerivative:ipv6_documentation_default
Open

use IPV6 loopback and documentation address in documentation over V4 by default#161879
2ndDerivative wants to merge 18 commits into
rust-lang:mainfrom
2ndDerivative:ipv6_documentation_default

Conversation

@2ndDerivative

@2ndDerivative 2ndDerivative commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

View all comments

This defaults all documentation unrelated to specific IP versions to the current IPv6.

Related to issue #161832

I didn't touch any tests, as I'm pretty new and don't know much about the test infrastructure, but maybe it should be considered to run all the tests via the v6 loopback by default too.

Feel free to discuss and / or critique!

My submission towards rust-lang#161832

I didn't touch any tests or anything that actually gets run for now, but if this is realistic Rust should probably default to using [::1] loopback for the std tests too.
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Aug 27, 2026
@rustbot

rustbot commented Aug 27, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the pull request, and welcome! The Rust Project has assigned @joboet (or someone else) to review your changes, you should hear from them (or someone else) within the next two weeks.

Please see the contribution instructions and our LLM policy for more information.

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: @ChrisDenton, libs
  • @ChrisDenton, libs expanded to 13 candidates
  • Random selection from 6 candidates

@rustbot

rustbot commented Aug 27, 2026

Copy link
Copy Markdown
Collaborator

⚠️ Warning ⚠️

  • There are issue links (such as #123) in the commit messages of the following commits.
    Please move them to the PR description, to avoid spamming the issues with references to the commit, and so this bot can automatically canonicalize them to avoid issues with subtree.

@2ndDerivative 2ndDerivative changed the title use IPV6 loopback and documentation address in over V4 by default use IPV6 loopback and documentation address in documentation over V4 by default Aug 27, 2026
@rust-log-analyzer

This comment has been minimized.

Comment thread library/std/src/net/socket_addr.rs
@joboet

joboet commented Aug 30, 2026

Copy link
Copy Markdown
Member

I really don't have an opinion here, networking isn't my domain (pun intended).

@rustbot reroll

@rustbot rustbot assigned ChrisDenton and unassigned joboet Aug 30, 2026
@ChrisDenton

Copy link
Copy Markdown
Member

I admit I'm struggling to feel strongly about this either way. This does feel like a policy decision though:

I think the Rust docs could be doing their part to normalize using [IPv6].

@rust-lang/libs does anybody have thoughts on this?

Comment thread library/alloc/src/io/buffered/bufwriter.rs
@clarfonthey

Copy link
Copy Markdown
Contributor

I can take this over since I did the previous one. r? clarfonthey

@rustbot rustbot assigned clarfonthey and unassigned ChrisDenton Aug 30, 2026
@rust-log-analyzer

This comment has been minimized.

@tgross35

Copy link
Copy Markdown
Member

I think the Rust docs could be doing their part to normalize using [IPv6].

@rust-lang/libs does anybody have thoughts on this?

Personally I'm -0.75 – users are way more likely to encounter IPv4 at the time being, and likely for the foreseeable future. I don't think I've ever seen documentation anywhere use [::1] rather than 127.0.0.1 when both are an option.

@clarfonthey

clarfonthey commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

This is definitely a spicy take, but I feel compelled to remind people that IPv6 is almost 30 years old and the fact that we still use IPv4 at all is a travesty and something the entire tech industry should be ashamed of.

(Yes, IPv6 was standardised in 1998. It's that old.)

I agree that we should still support IPv4 and make sure that our APIs can handle it, but I think that if people are confused to see IPv6 addresses on APIs that very explicitly accept them that is something they should quickly rectify. And, it's especially helpful that the two most commonly written IPv6 addresses, [::1] and [::], are shorter to type than their IPv4 counterparts, 127.0.0.1 and 0.0.0.0.

I will probably ask around the libs team to make sure I'm not being too spicy here but most of the arguments I've seen complaining about IPv6 (here and elsewhere) are mostly just people misunderstanding how IPv6 works or being resistant to change, neither of which feels particularly compelling here.

@kennytm

kennytm commented Sep 2, 2026

Copy link
Copy Markdown
Member

It's especially helpful that the two most commonly written IPv6 addresses, [::1] and [::], are shorter to type than their IPv4 counterparts, 127.0.0.1 and 0.0.0.0.

Disagreed, in a typical keyboard to enter an IPv6 address you need to reach for Shift and requires simultaneous touch. To type ::1 you need Shift+;; → (release Shift) → 1, while the IPv4 localhost you just type 127.0.0.1 directly. It is shorter to type ::1 but not easier than 127.0.0.1.

In any case typing should not be relevant to this PR at all, this PR is about example code i.e. reading, and I'd argue:

  1. People recognizes words not individual letters, the strlen of ::1 vs 127.0.0.1 don't impact readability.

  2. OTOH, some example code replaced Ipv4Addr::new(127, 0, 0, 1) with Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1), or Ipv4Addr::new(10, 10, 0, 1) with Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 1), and the IPv6 counterparts are much harder to read, because you can't take advantage of the compressed representation (::1, 2001:db8::1) in code.

  3. Mostly a fault of Rust not supporting optional arguments, the constructor of SocketAddrV6 required filling in flowinfo and scope_id, leading to uncanny changes such as

-   ///            SocketAddr::V4(SocketAddrV4::new(Ipv4Addr::new(127, 0, 0, 1), 8080)));
+   ///            SocketAddr::V6(SocketAddrV6::new(
+   ///                 Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1),
+   ///                 8080,
+   ///                 0,
+   ///                 0
+   /// )));

I will probably ask around the libs team to make sure I'm not being too spicy here but most of the arguments I've seen complaining about IPv6 (here and elsewhere) are mostly just people misunderstanding how IPv6 works or being resistant to change, neither of which feels particularly compelling here.

While I'd love to see IPv6 supported everywhere (CGNAT is awful), in the context of this PR I don't see replacing examples using 127.0.0.1 with ::1 alone produced any benefits (this is unlike 0.0.0.0:x[::]:x that the latter enabled IPv6+v4 connectivity on a dual-stack system). There is lack of compelling reason to merge this PR, unless it is part of a grand policy of T-libs as called out above #161879 (comment).

@2ndDerivative

2ndDerivative commented Sep 2, 2026

Copy link
Copy Markdown
Contributor Author

It's especially helpful that the two most commonly written IPv6 addresses, [::1] and [::], are shorter to type than their IPv4 counterparts, 127.0.0.1 and 0.0.0.0.

Disagreed, in a typical keyboard to enter an IPv6 address you need to reach for Shift and requires simultaneous touch. To type ::1 you need Shift+;; → (release Shift) → 1, while the IPv4 localhost you just type 127.0.0.1 directly. It is shorter to type ::1 but not easier than 127.0.0.1.

In any case typing should not be relevant to this PR at all, this PR is about example code i.e. reading, and I'd argue:

  1. People recognizes words not individual letters, the strlen of ::1 vs 127.0.0.1 don't impact readability.

  2. OTOH, some example code replaced Ipv4Addr::new(127, 0, 0, 1) with Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1), or Ipv4Addr::new(10, 10, 0, 1) with Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 1), and the IPv6 counterparts are much harder to read, because you can't take advantage of the compressed representation (::1, 2001:db8::1) in code.

  3. Mostly a fault of Rust not supporting optional arguments, the constructor of SocketAddrV6 required filling in flowinfo and scope_id, leading to uncanny changes such as

-   ///            SocketAddr::V4(SocketAddrV4::new(Ipv4Addr::new(127, 0, 0, 1), 8080)));
+   ///            SocketAddr::V6(SocketAddrV6::new(
+   ///                 Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1),
+   ///                 8080,
+   ///                 0,
+   ///                 0
+   /// )));

If readability is your problem, we can always replace this kind of usage with the LOCALHOST and UNSPECIFIED constants

Comment thread library/core/src/net/socket_addr.rs
@kennytm

kennytm commented Sep 2, 2026

Copy link
Copy Markdown
Member

If readability is your problem, we can always replace this kind of usage with the LOCALHOST and UNSPECIFIED constants

  1. For LOCALHOST: Sure.

    This PR does not introduce any UNSPECIFIED and you can shorten it with [0_u16; 8] anyway.

    But 2001:db8::1 can't be simplified, you gotta write Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 1) or Ipv6Addr::from_bits(0x2001_0db8_0000_0000_0000_0000_0000_0001) for unwrap-free code.

  2. Readability is a response to use IPV6 loopback and documentation address in documentation over V4 by default #161879 (comment) saying some IPv6 addresses are shorter to type. My stance is already described in Documentation examples should default to IPv6 instead of IPv4 #161832 (comment) I'm not gonna copy here.

@clarfonthey

Copy link
Copy Markdown
Contributor

unless it is part of a grand policy of T-libs as called out above #161879 (comment).

It is explicitly not a grander T-libs policy which is why I've been asking for more explicit feedback on it. While I think this is a better change, I am also someone who kind of wants to bend over backwards to get people more used to IPv6, which is far from a neutral position. And it's also especially worthwhile to call out ergonomics here, which are fixable but require broader changes.

@clarfonthey

clarfonthey commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Okay, so, a day later, dismounting my horse, I actually thought the original issue had way more support than it actually did, and also 100% agree that while for APIs like IpAddr this is fair, for other generic APIs there is less perceived benefit. I do think however that the docs are the perfect place to get people more acquainted with IPv6 addresses, since we should do that.

I think it would be reasonable to stop and say that we probably should not explicitly just replace 127.0.0.1 with ::1 here, but I think anywhere where we add both IPv4 and IPv6 examples is fine. I'll point them out as examples in review comments.

Edit: there actually aren't examples of this happening, since I failed tech 101 and that diffs include the before and after because I was excited about IPv6. But alternating between examples might be okay. Would need to generate docs after to compare, but, maybe that's reasonable to have a broader variety of addresses.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants