Skip to content

useless-transmute doesn't take lifetimes into account #5668

Closed
@ndmitchell

Description

@ndmitchell

Given:

use std::cell::Cell;
pub struct V<'v>(Cell<&'v ()>);

pub unsafe fn downcast_v<'v>(x: V<'static>) -> V<'v> {
    std::mem::transmute(x)
}

If you enable -D clippy::useless-transmute then Clippy warns:

error: transmute from a type (`foo:V`) to itself

But it's actually V<'static> to V<'v>, so a transmute is required.

$ cargo clippy -V
clippy 0.0.212 (891e1a85 2020-04-18)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions