Is it a bug? a ipv4 IpAddr to SocketAddr

using crate local-ip-address to get local ipv4 address , when convert it to SocketAddr, the method new will treat it as ipv6 address. see the video bellow

video about IpAddr to SocketAddr

sample code is

fn test_ip() {
    match local_ip() {
        Ok(local_ip_address) => {
            let x = SocketAddr::new(local_ip_address, 53);
        }
        Err(_) => {}
    }
}

the problem code is SocketAddr::new

    pub const fn new(ip: IpAddr, port: u16) -> SocketAddr {
        match ip {
            IpAddr::V4(a) => SocketAddr::V4(SocketAddrV4::new(a, port)),
            IpAddr::V6(a) => SocketAddr::V6(SocketAddrV6::new(a, port, 0, 0)),
        }
    }

the match item is IpAddr::V6, but not IpAddr::V4

rust: 1.96
os: mac os 12.7.6
ide: rustover 2026.1.3

if you look at the code of SocketAddr::new that you have shared , you can see that it behaves exactly as anyone would excpect and cannot convert ipv4 to ipv6.

you share some sample code, but local_ip is not an std function. you need to share what it is or where you got it from in order for us to be able to help you.

edit : i originally made a disparaing comment against the use of LLMs but it has become clear the one used here was only for translation

the code is my test code. not copy from any web page. my question is :
after call local_ip() by crate local-ip-address, got a IpAddr type variable local_ip_address, it's ipv4, but when use SocketAddr::new() , the inner code
match ip {
}
it will match IpAddr::V6, but not V4.
you can see the video.

i have seen the video, and it certainly looks like a serious bug. but the code of SocketAddr::new remains airtight.
it does not modify the input, so it can't change what variant this is.

i would advise you try to debug-print ip just before calling SocketAddr::new, and debug-print the SocketAddr right after, as i would find this more reliable than the debugger.

SocketAddr is an enum, so you could also rewrite SocketAddr::new by hand and add more debugging there

I'd take what the debugger says with a grain of salt in general. Debug information generation is one of the most under-tested and difficult areas in a compiler. In your video it says scope_id = 32759, which is impossible in the given context, suggesting the debugger is most likely showing incorrect information.

that is most likely what is happening here, which is why i would recommend doing some print-debugging

i have tried print, before and after SocketAddr::new, both IpV4.

so it seems your debugger is the one with bugs. that is very unfortnate, and i have no clue what could cause it.

i would advise that you try to rely on debug printing whenever there is doubt from now on