Skip to content

Commit 3bbfe78

Browse files
committed
Auto merge of #13907 - weihanglo:ipv6, r=ehuss
fix: support IPv6-only network for cargo fix
2 parents bb6e446 + ced58bf commit 3bbfe78

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

src/cargo/util/diagnostic_server.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use tracing::warn;
1616

1717
use crate::core::Edition;
1818
use crate::util::errors::CargoResult;
19+
use crate::util::network::LOCALHOST;
1920
use crate::util::GlobalContext;
2021

2122
const DIAGNOSTICS_SERVER_VAR: &str = "__CARGO_FIX_DIAGNOSTICS_SERVER";
@@ -266,7 +267,7 @@ pub struct StartedServer {
266267

267268
impl RustfixDiagnosticServer {
268269
pub fn new() -> Result<Self, Error> {
269-
let listener = TcpListener::bind("127.0.0.1:0")
270+
let listener = TcpListener::bind(&LOCALHOST[..])
270271
.with_context(|| "failed to bind TCP listener to manage locking")?;
271272
let addr = listener.local_addr()?;
272273

src/cargo/util/lockserver.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ use std::thread::{self, JoinHandle};
2020

2121
use anyhow::{Context, Error};
2222

23+
use crate::util::network::LOCALHOST;
24+
2325
pub struct LockServer {
2426
listener: TcpListener,
2527
addr: SocketAddr,
@@ -44,7 +46,7 @@ struct ServerClient {
4446

4547
impl LockServer {
4648
pub fn new() -> Result<LockServer, Error> {
47-
let listener = TcpListener::bind("127.0.0.1:0")
49+
let listener = TcpListener::bind(&LOCALHOST[..])
4850
.with_context(|| "failed to bind TCP listener to manage locking")?;
4951
let addr = listener.local_addr()?;
5052
Ok(LockServer {

src/cargo/util/network/mod.rs

+11
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,23 @@
11
//! Utilities for networking.
22
3+
use std::net::Ipv4Addr;
4+
use std::net::Ipv6Addr;
5+
use std::net::SocketAddr;
6+
use std::net::SocketAddrV4;
7+
use std::net::SocketAddrV6;
38
use std::task::Poll;
49

510
pub mod http;
611
pub mod proxy;
712
pub mod retry;
813
pub mod sleep;
914

15+
/// LOCALHOST constants for both IPv4 and IPv6.
16+
pub const LOCALHOST: [SocketAddr; 2] = [
17+
SocketAddr::V4(SocketAddrV4::new(Ipv4Addr::LOCALHOST, 0)),
18+
SocketAddr::V6(SocketAddrV6::new(Ipv6Addr::LOCALHOST, 0, 0, 0)),
19+
];
20+
1021
pub trait PollExt<T> {
1122
fn expect(self, msg: &str) -> T;
1223
}

0 commit comments

Comments
 (0)