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

Replace transmute with pointer cast #4

Closed
wants to merge 4 commits into from
Closed

Replace transmute with pointer cast #4

wants to merge 4 commits into from

Conversation

dtolnay
Copy link
Owner

@dtolnay dtolnay commented Aug 17, 2024

This requires Rust 1.75+ which contains rust-lang/rust#113262.

    warning: casting raw pointers to the same type and constness is unnecessary (`*const dyn of::NonStaticAny` -> `*const dyn of::NonStaticAny`)
       --> src/lib.rs:219:11
        |
    219 |         &*(&phantom_data as *const dyn NonStaticAny as *const (dyn NonStaticAny + 'static))
        |           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&phantom_data as *const dyn NonStaticAny`
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_cast
        = note: `#[warn(clippy::unnecessary_cast)]` on by default
@dtolnay dtolnay changed the title Replace transmtue with pointer cast Replace transmute with pointer cast Aug 17, 2024
On older compilers, the pointer cast does not compile due to a rustc bug.

    error[E0310]: the parameter type `T` may not live long enough
       --> src/lib.rs:223:12
        |
    223 |         &*(&phantom_data as *const dyn NonStaticAny as *const (dyn NonStaticAny + 'static))
        |            ^^^^^^^^^^^^^ ...so that the type `T` will meet its required lifetime bounds
        |
    help: consider adding an explicit lifetime bound...
        |
    203 |     T: ?Sized + 'static,
        |               +++++++++
    warning: borrow as raw pointer
       --> src/lib.rs:223:12
        |
    223 |         &*(&phantom_data as *const dyn NonStaticAny as *const (dyn NonStaticAny + 'static))
        |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `core::ptr::addr_of!(phantom_data)`
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#borrow_as_ptr
        = note: `-W clippy::borrow-as-ptr` implied by `-W clippy::pedantic`
        = help: to override `-W clippy::pedantic` add `#[allow(clippy::borrow_as_ptr)]`
Copy link
Owner Author

@dtolnay dtolnay left a comment

Choose a reason for hiding this comment

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

I opened #5 to follow up once we're no longer supporting such old compilers.

@dtolnay dtolnay closed this Aug 17, 2024
@dtolnay dtolnay deleted the cast branch August 17, 2024 05:37
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.

1 participant