Help, can't compile project from Feb 2022

I have a little project that compiled and ran in Feb 2022 but now fails to build with error:

error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
   --> /Users/zicog/.cargo/registry/src/index.crates.io-6f17d22bba15001f/socket2-0.3.12/src/sockaddr.rs:176:9
    |
176 |         mem::transmute::<SocketAddrV4, sockaddr_in>(v4);
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = note: source type: `SocketAddrV4` (48 bits)
    = note: target type: `sockaddr_in` (128 bits)

I'm building on a Mac M1 and Ubuntu 18.04 on ARMv8 with rustc 1.70.0 .

I gave no memory of what compiler version was used last time it did compile and run.

My experience of this kind of breakage usually leads me to all manner of experimenting, updating versions in Cargo.toml, removing Cargo.lock, etc and finally starting over with a new project and copying my code into it.

Before I start down that rabbit hole again what is a good way to track this kind of dependency/legacy/update failure?

Rust 1.64 changed the memory layout of SocketAddrV4.
Relying on the memory layout was always wrong, but it "worked" in old versions.
Pick any Rust before 1.64 and the project might still compile or see if you can update socket2 (at least to 0.3.16): cargo update -p socket2

2 Likes

Thanks. Good to know why it broke.

In the meantime I updated my dependencies in Cargo.toml and blew away Cargo.lock and all is fine again with the latest stable compiler.

-ring = "0.16.19"
-ssh2 = "0.8.2"
-nats = "0.7.1"
+ring = "0.16.20"
+ssh2 = "0.9.4"
+nats = "0.24.0"

I had tried a cargo update but after that the build failed with an error about an unfound "something-dalek-something" crate.

For some reason this kind of failure happens to me a lot!

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.