Closed
Description
With clippy 0.0.212, I'm getting what appears to be false positives when using transmute()
to cast either to or from a raw trait object pointer where the input and output types have invariant lifetimes, or if the output type has a longer lifetime such as 'static
(casting using as
isn't allowed in such cases). No warnings are triggered if the source and target types are both references.
use std::mem::transmute;
pub trait DummyTrait {}
pub unsafe fn ref_to_ref<'a, 'b>(obj: &'a (DummyTrait + 'a)) -> &'b (DummyTrait + 'b) {
// No warnings.
transmute(obj)
}
pub unsafe fn ptr_to_ptr<'a, 'b>(obj: *const (DummyTrait + 'a)) -> *const (DummyTrait + 'b) {
// Triggers `transmute_ptr_to_ptr` warning.
transmute(obj)
}
pub unsafe fn ptr_to_ref<'a, 'b>(obj: *const (DummyTrait + 'a)) -> &'b (DummyTrait + 'b) {
// Triggers `transmute_ptr_to_ref` warning.
transmute(obj)
}
pub unsafe fn ref_to_ptr<'a, 'b>(obj: &'a (DummyTrait + 'a)) -> *const (DummyTrait + 'b) {
// Triggers `useless_transmute` warning.
transmute(obj)
}