Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unnecessary static assertion #2047

Closed
wants to merge 1 commit into from
Closed

Remove unnecessary static assertion #2047

wants to merge 1 commit into from

Conversation

WhyNotHugo
Copy link

This assertion is not required. The docs for std::mem::transmute read:

Both types must have the same size. Compilation will fail if this is
not guaranteed.

I have confirmed this to be the case by trying to transmute two different variables of different length:

error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
  --> src/sys/socket/addr.rs:44:14
   |
44 |     unsafe { mem::transmute("asdfasd") }
   |              ^^^^^^^^^^^^^^
   |
   = note: source type: `&str` (128 bits)
   = note: target type: `in_addr` (32 bits)

Given that this is the only usage of the static_assertions crates, this allows dropping an unnecessary dependency.

This assertion is not required. The docs for std::mem::transmute read:

    Both types must have the same size. Compilation will fail if this is
    not guaranteed.

I have confirmed this to be the case by trying to transmute two
different variables of different length:

    error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
      --> src/sys/socket/addr.rs:44:14
       |
    44 |     unsafe { mem::transmute("asdfasd") }
       |              ^^^^^^^^^^^^^^
       |
       = note: source type: `&str` (128 bits)
       = note: target type: `in_addr` (32 bits)

Given that this is the only usage of the `static_assertions` crates,
this allows dropping an unnecessary dependency.
@stevenengler
Copy link
Contributor

I'm pretty sure this transmute is actually unsafe. I've opened #2053.

@asomers
Copy link
Member

asomers commented Jun 27, 2023

Superseded by #2061

@asomers asomers closed this Jun 27, 2023
@WhyNotHugo WhyNotHugo deleted the needless-check branch July 1, 2023 13:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants