Skip to content

Provide better doc code example for UnixDatagram::bind_addr and UnixListener::bind_addr - #163580

Merged
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
asder8215:unix_sockets_bind_addr_docs
Oct 2, 2026
Merged

rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
asder8215:unix_sockets_bind_addr_docs

Conversation

@asder8215

Copy link
Copy Markdown
Contributor

The current doc code example for both UnixDatagram::bind_addr and UnixListener::bind_addr attempts binding to an already binded socket address. It's clear that this would always result in a AddrInUse error. I'm pretty certain the original purpose for this function was so that Linux/Android/Cygwin can create an abstract datagram/stream socket through this function as it is impossible to create an abstract socket via the regular *::bind functions (since it will return an error if we pass in a Path with interior nul bytes).

I thought it would be better to provide an example of how to use this UnixDatagram::bind_addr and UnixListener::bind_addr via SocketAddr::from_pathname since that's general purpose to all platforms within the Unix family.

You can verify in this rust playground how the current example (if you switch the "path/to/socket" argument to a tmp directory path) always result in an AddrInUse error.

@rustbot rustbot added O-unix Operating system: Unix-like 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 Oct 1, 2026
@rustbot

rustbot commented Oct 1, 2026

Copy link
Copy Markdown
Collaborator

r? @Darksonn

rustbot has assigned @Darksonn.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

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 ChrisDenton, Darksonn, JohnTitor, Mark-Simulacrum, clarfonthey

@asder8215
asder8215 force-pushed the unix_sockets_bind_addr_docs branch from fb4cdc8 to 82366d5 Compare October 1, 2026 04:00

@Darksonn Darksonn left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rust-bors

rust-bors Bot commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 82366d5 has been approved by Darksonn

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 1, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Oct 1, 2026
…ocs, r=Darksonn

Provide better doc code example for `UnixDatagram::bind_addr` and `UnixListener::bind_addr`

The current doc code example for both [`UnixDatagram::bind_addr`](https://doc.rust-lang.org/std/os/unix/net/struct.UnixDatagram.html#method.bind_addr) and [`UnixListener::bind_addr`](https://doc.rust-lang.org/std/os/unix/net/struct.UnixListener.html#method.bind_addr) attempts binding to an already binded socket address. It's clear that this would always result in a `AddrInUse` error. I'm pretty certain the original purpose for this function was so that Linux/Android/Cygwin can create an abstract datagram/stream socket through this function as it is impossible to create an abstract socket via the regular `*::bind` functions (since it will return an error if we pass in a `Path` with interior nul bytes).

I thought it would be better to provide an example of how to use this `UnixDatagram::bind_addr` and `UnixListener::bind_addr` via `SocketAddr::from_pathname` since that's general purpose to all platforms within the Unix family.

You can verify in this rust playground how the current example (if you switch the `"path/to/socket"` argument to a tmp directory path) always result in an `AddrInUse` error.
* [`UnixListener::bind_addr` code example](https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=153c9e3131275e9c859dfa47f1d528b6)
* [`UnixDatagram::bind_addr` code example](https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=a6fdd5cc9c9b08b8c4a58f4c2d6b83cb)
rust-bors Bot pushed a commit that referenced this pull request Oct 1, 2026
…uwer

Rollup of 9 pull requests

Successful merges:

 - #163483 (Bump bootstrap compiler to 1.100.0 beta)
 - #161380 (only rerun const eval in next-solver if the const actually references opaques)
 - #162900 (Some refactorings around metadata encoding)
 - #163580 (Provide better doc code example for `UnixDatagram::bind_addr` and `UnixListener::bind_addr`)
 - #163584 ([triagebot] Ping me for debugger visualizer changes)
 - #162782 (Fix rustdoc ICE caused by mishandling of ambiguity errors)
 - #163314 (move `#[macro_export]` on declarative macro check to `rustc_attr_parsing`)
 - #163405 (Remove some #[linkage] options)
 - #163581 (do not suggest precise capturing when the opaque span is in a macro expansion)
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Oct 1, 2026
…ocs, r=Darksonn

Provide better doc code example for `UnixDatagram::bind_addr` and `UnixListener::bind_addr`

The current doc code example for both [`UnixDatagram::bind_addr`](https://doc.rust-lang.org/std/os/unix/net/struct.UnixDatagram.html#method.bind_addr) and [`UnixListener::bind_addr`](https://doc.rust-lang.org/std/os/unix/net/struct.UnixListener.html#method.bind_addr) attempts binding to an already binded socket address. It's clear that this would always result in a `AddrInUse` error. I'm pretty certain the original purpose for this function was so that Linux/Android/Cygwin can create an abstract datagram/stream socket through this function as it is impossible to create an abstract socket via the regular `*::bind` functions (since it will return an error if we pass in a `Path` with interior nul bytes).

I thought it would be better to provide an example of how to use this `UnixDatagram::bind_addr` and `UnixListener::bind_addr` via `SocketAddr::from_pathname` since that's general purpose to all platforms within the Unix family.

You can verify in this rust playground how the current example (if you switch the `"path/to/socket"` argument to a tmp directory path) always result in an `AddrInUse` error.
* [`UnixListener::bind_addr` code example](https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=153c9e3131275e9c859dfa47f1d528b6)
* [`UnixDatagram::bind_addr` code example](https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=a6fdd5cc9c9b08b8c4a58f4c2d6b83cb)
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Oct 1, 2026
…ocs, r=Darksonn

Provide better doc code example for `UnixDatagram::bind_addr` and `UnixListener::bind_addr`

The current doc code example for both [`UnixDatagram::bind_addr`](https://doc.rust-lang.org/std/os/unix/net/struct.UnixDatagram.html#method.bind_addr) and [`UnixListener::bind_addr`](https://doc.rust-lang.org/std/os/unix/net/struct.UnixListener.html#method.bind_addr) attempts binding to an already binded socket address. It's clear that this would always result in a `AddrInUse` error. I'm pretty certain the original purpose for this function was so that Linux/Android/Cygwin can create an abstract datagram/stream socket through this function as it is impossible to create an abstract socket via the regular `*::bind` functions (since it will return an error if we pass in a `Path` with interior nul bytes).

I thought it would be better to provide an example of how to use this `UnixDatagram::bind_addr` and `UnixListener::bind_addr` via `SocketAddr::from_pathname` since that's general purpose to all platforms within the Unix family.

You can verify in this rust playground how the current example (if you switch the `"path/to/socket"` argument to a tmp directory path) always result in an `AddrInUse` error.
* [`UnixListener::bind_addr` code example](https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=153c9e3131275e9c859dfa47f1d528b6)
* [`UnixDatagram::bind_addr` code example](https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=a6fdd5cc9c9b08b8c4a58f4c2d6b83cb)
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Oct 1, 2026
…ocs, r=Darksonn

Provide better doc code example for `UnixDatagram::bind_addr` and `UnixListener::bind_addr`

The current doc code example for both [`UnixDatagram::bind_addr`](https://doc.rust-lang.org/std/os/unix/net/struct.UnixDatagram.html#method.bind_addr) and [`UnixListener::bind_addr`](https://doc.rust-lang.org/std/os/unix/net/struct.UnixListener.html#method.bind_addr) attempts binding to an already binded socket address. It's clear that this would always result in a `AddrInUse` error. I'm pretty certain the original purpose for this function was so that Linux/Android/Cygwin can create an abstract datagram/stream socket through this function as it is impossible to create an abstract socket via the regular `*::bind` functions (since it will return an error if we pass in a `Path` with interior nul bytes).

I thought it would be better to provide an example of how to use this `UnixDatagram::bind_addr` and `UnixListener::bind_addr` via `SocketAddr::from_pathname` since that's general purpose to all platforms within the Unix family.

You can verify in this rust playground how the current example (if you switch the `"path/to/socket"` argument to a tmp directory path) always result in an `AddrInUse` error.
* [`UnixListener::bind_addr` code example](https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=153c9e3131275e9c859dfa47f1d528b6)
* [`UnixDatagram::bind_addr` code example](https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=a6fdd5cc9c9b08b8c4a58f4c2d6b83cb)
rust-bors Bot pushed a commit that referenced this pull request Oct 1, 2026
Rollup of 11 pull requests

Successful merges:

 - #163483 (Bump bootstrap compiler to 1.100.0 beta)
 - #161380 (only rerun const eval in next-solver if the const actually references opaques)
 - #162900 (Some refactorings around metadata encoding)
 - #163580 (Provide better doc code example for `UnixDatagram::bind_addr` and `UnixListener::bind_addr`)
 - #163584 ([triagebot] Ping me for debugger visualizer changes)
 - #162904 (Fix ICE for ambiguous candidates on method probing)
 - #163281 (Add `f16` inline ASM support to `spirv.rs`)
 - #163314 (move `#[macro_export]` on declarative macro check to `rustc_attr_parsing`)
 - #163405 (Remove some #[linkage] options)
 - #163530 (`const impl PartialEq` for `f16b`)
 - #163581 (do not suggest precise capturing when the opaque span is in a macro expansion)
rust-bors Bot pushed a commit that referenced this pull request Oct 1, 2026
…uwer

Rollup of 20 pull requests

Successful merges:

 - #163483 (Bump bootstrap compiler to 1.100.0 beta)
 - #161380 (only rerun const eval in next-solver if the const actually references opaques)
 - #162900 (Some refactorings around metadata encoding)
 - #163461 (Improve diagnostic deduplication)
 - #163580 (Provide better doc code example for `UnixDatagram::bind_addr` and `UnixListener::bind_addr`)
 - #163584 ([triagebot] Ping me for debugger visualizer changes)
 - #159021 (windows-gnu: enable native TLS)
 - #161467 (wfcheck: name the item that discards an unused type parameter)
 - #162618 (trait_selection: Preserve eager normalization failures)
 - #162904 (Fix ICE for ambiguous candidates on method probing)
 - #163064 (Avoid computing overflowed goal chains for crate dependencies)
 - #163281 (Add `f16` inline ASM support to `spirv.rs`)
 - #163314 (move `#[macro_export]` on declarative macro check to `rustc_attr_parsing`)
 - #163360 ([rustdoc] Correctly handle rustc_allow_incoherent_impl on primitive methods)
 - #163385 (GVN transmutes of Immediate::Uninit to Immediate::Uninit)
 - #163405 (Remove some #[linkage] options)
 - #163530 (`const impl PartialEq` for `f16b`)
 - #163581 (do not suggest precise capturing when the opaque span is in a macro expansion)
 - #163590 (Make `AllocatorNightly` less clever)
 - #163599 (Add union pattern reference change to relnotes)
rust-bors Bot pushed a commit that referenced this pull request Oct 1, 2026
…uwer

Rollup of 20 pull requests

Successful merges:

 - #163483 (Bump bootstrap compiler to 1.100.0 beta)
 - #161380 (only rerun const eval in next-solver if the const actually references opaques)
 - #162900 (Some refactorings around metadata encoding)
 - #163461 (Improve diagnostic deduplication)
 - #163580 (Provide better doc code example for `UnixDatagram::bind_addr` and `UnixListener::bind_addr`)
 - #163584 ([triagebot] Ping me for debugger visualizer changes)
 - #159021 (windows-gnu: enable native TLS)
 - #161467 (wfcheck: name the item that discards an unused type parameter)
 - #162618 (trait_selection: Preserve eager normalization failures)
 - #162904 (Fix ICE for ambiguous candidates on method probing)
 - #163064 (Avoid computing overflowed goal chains for crate dependencies)
 - #163281 (Add `f16` inline ASM support to `spirv.rs`)
 - #163314 (move `#[macro_export]` on declarative macro check to `rustc_attr_parsing`)
 - #163360 ([rustdoc] Correctly handle rustc_allow_incoherent_impl on primitive methods)
 - #163385 (GVN transmutes of Immediate::Uninit to Immediate::Uninit)
 - #163405 (Remove some #[linkage] options)
 - #163530 (`const impl PartialEq` for `f16b`)
 - #163581 (do not suggest precise capturing when the opaque span is in a macro expansion)
 - #163590 (Make `AllocatorNightly` less clever)
 - #163599 (Add union pattern reference change to relnotes)
rust-bors Bot pushed a commit that referenced this pull request Oct 2, 2026
…uwer

Rollup of 20 pull requests

Successful merges:

 - #163483 (Bump bootstrap compiler to 1.100.0 beta)
 - #161380 (only rerun const eval in next-solver if the const actually references opaques)
 - #162900 (Some refactorings around metadata encoding)
 - #163461 (Improve diagnostic deduplication)
 - #163580 (Provide better doc code example for `UnixDatagram::bind_addr` and `UnixListener::bind_addr`)
 - #163584 ([triagebot] Ping me for debugger visualizer changes)
 - #159021 (windows-gnu: enable native TLS)
 - #161467 (wfcheck: name the item that discards an unused type parameter)
 - #162618 (trait_selection: Preserve eager normalization failures)
 - #162904 (Fix ICE for ambiguous candidates on method probing)
 - #163064 (Avoid computing overflowed goal chains for crate dependencies)
 - #163281 (Add `f16` inline ASM support to `spirv.rs`)
 - #163314 (move `#[macro_export]` on declarative macro check to `rustc_attr_parsing`)
 - #163360 ([rustdoc] Correctly handle rustc_allow_incoherent_impl on primitive methods)
 - #163385 (GVN transmutes of Immediate::Uninit to Immediate::Uninit)
 - #163405 (Remove some #[linkage] options)
 - #163530 (`const impl PartialEq` for `f16b`)
 - #163581 (do not suggest precise capturing when the opaque span is in a macro expansion)
 - #163590 (Make `AllocatorNightly` less clever)
 - #163599 (Add union pattern reference change to relnotes)
@rust-bors
rust-bors Bot merged commit dcc0179 into rust-lang:main Oct 2, 2026
13 checks passed
@rustbot rustbot added this to the 1.101.0 milestone Oct 2, 2026
rust-bors Bot pushed a commit that referenced this pull request Oct 2, 2026
Rollup merge of #163580 - asder8215:unix_sockets_bind_addr_docs, r=Darksonn

Provide better doc code example for `UnixDatagram::bind_addr` and `UnixListener::bind_addr`

The current doc code example for both [`UnixDatagram::bind_addr`](https://doc.rust-lang.org/std/os/unix/net/struct.UnixDatagram.html#method.bind_addr) and [`UnixListener::bind_addr`](https://doc.rust-lang.org/std/os/unix/net/struct.UnixListener.html#method.bind_addr) attempts binding to an already binded socket address. It's clear that this would always result in a `AddrInUse` error. I'm pretty certain the original purpose for this function was so that Linux/Android/Cygwin can create an abstract datagram/stream socket through this function as it is impossible to create an abstract socket via the regular `*::bind` functions (since it will return an error if we pass in a `Path` with interior nul bytes).

I thought it would be better to provide an example of how to use this `UnixDatagram::bind_addr` and `UnixListener::bind_addr` via `SocketAddr::from_pathname` since that's general purpose to all platforms within the Unix family.

You can verify in this rust playground how the current example (if you switch the `"path/to/socket"` argument to a tmp directory path) always result in an `AddrInUse` error.
* [`UnixListener::bind_addr` code example](https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=153c9e3131275e9c859dfa47f1d528b6)
* [`UnixDatagram::bind_addr` code example](https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=a6fdd5cc9c9b08b8c4a58f4c2d6b83cb)
flip1995 pushed a commit to flip1995/rust-clippy that referenced this pull request Oct 3, 2026
…uwer

Rollup of 20 pull requests

Successful merges:

 - rust-lang/rust#163483 (Bump bootstrap compiler to 1.100.0 beta)
 - rust-lang/rust#161380 (only rerun const eval in next-solver if the const actually references opaques)
 - rust-lang/rust#162900 (Some refactorings around metadata encoding)
 - rust-lang/rust#163461 (Improve diagnostic deduplication)
 - rust-lang/rust#163580 (Provide better doc code example for `UnixDatagram::bind_addr` and `UnixListener::bind_addr`)
 - rust-lang/rust#163584 ([triagebot] Ping me for debugger visualizer changes)
 - rust-lang/rust#159021 (windows-gnu: enable native TLS)
 - rust-lang/rust#161467 (wfcheck: name the item that discards an unused type parameter)
 - rust-lang/rust#162618 (trait_selection: Preserve eager normalization failures)
 - rust-lang/rust#162904 (Fix ICE for ambiguous candidates on method probing)
 - rust-lang/rust#163064 (Avoid computing overflowed goal chains for crate dependencies)
 - rust-lang/rust#163281 (Add `f16` inline ASM support to `spirv.rs`)
 - rust-lang/rust#163314 (move `#[macro_export]` on declarative macro check to `rustc_attr_parsing`)
 - rust-lang/rust#163360 ([rustdoc] Correctly handle rustc_allow_incoherent_impl on primitive methods)
 - rust-lang/rust#163385 (GVN transmutes of Immediate::Uninit to Immediate::Uninit)
 - rust-lang/rust#163405 (Remove some #[linkage] options)
 - rust-lang/rust#163530 (`const impl PartialEq` for `f16b`)
 - rust-lang/rust#163581 (do not suggest precise capturing when the opaque span is in a macro expansion)
 - rust-lang/rust#163590 (Make `AllocatorNightly` less clever)
 - rust-lang/rust#163599 (Add union pattern reference change to relnotes)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

O-unix Operating system: Unix-like S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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.

3 participants