Skip to content

transmute_ptr_to_ref false positive for types containing differing lifetimes #8924

Closed
@Alexendoo

Description

@Alexendoo

Summary

There's one last FP in #2906 that wasn't fixed

Lint Name

transmute_ptr_to_ref

Reproducer

I tried this code:

#![allow(clippy::missing_safety_doc)]

use std::mem::transmute;

pub unsafe fn ptr_to_ref<'a, 'b>(ptr: *const &'a ()) -> &&'b () {
    transmute(ptr)
}

I saw this happen:

warning: transmute from a pointer type (`*const &()`) to a reference type (`&&()`)
 --> t.rs:5:5
  |
5 |     std::mem::transmute(ptr)
  |     ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*ptr`
  |

I expected to see this happen:

It shouldn't lint, as &*ptr would fail to compile

Version

No response

Additional Labels

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when applied

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions