Skip to content

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.

2 participants