You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
transmute_ptr_to_ptr is too noisy for instance of between references even it is pedantic currently IMO.
This issue suggests avoid triggering if following conditions are met, because those do not trigger UBs:
the call does not extends lifetime, nor change it to unrelated one.
at least one of following conditions are met
the Src is an enum and it has #[repr(C)] or #[repr($integer)] or #[repr(transparent)], and Dst is corresponding type.
the Src is an struct and it has #[repr(transparent)], and Dst is reference to the inner type.
the Src is an struct which has single field and #[repr(C)], and Dst is reference to the field type.
Purpose
The lint should not be warn on &'a E ~> &'a E::Repr (where E is any field-less enum), &'a Transparent ~> &'a Transparent::Inner (where Transparent is struct with #[repr(transparent)]). The former can be achieved by primitive cast, but latter is not:
#[repr(C)]// also applicable if layout is i*, u*, or transparentenumExpReprC{Zero = 0,}#[repr(transparent)]// also applicable if layout is CstructTransparent(u8);fnmain(){let m:ExpReprC = ExpReprC::Zero;let x:&u8 = unsafe{ std::mem::transmute(&m)};let m:Transparent = Transparent(42);let x:&u8 = unsafe{ std::mem::transmute(&m)};}
All of these cases would be better served by &x.field or &x as REPR_TYPE, which does the same operation, but restricts the lifetime and ensures that the types are correct.
the call does not extends lifetime, nor change it to unrelated one. transmute returns an "unbound lifetime" so whether a lifetime change happens is very liable to change with small inference changes in the program.
It's perfectly fine that a pedantic lint lints on possible sound but fragile code.
cc #6372
Description
transmute_ptr_to_ptr
is too noisy for instance of between references even it is pedantic currently IMO.This issue suggests avoid triggering if following conditions are met, because those do not trigger UBs:
Src
is anenum
and it has#[repr(C)]
or#[repr($integer)]
or#[repr(transparent)]
, andDst
is corresponding type.Src
is anstruct
and it has#[repr(transparent)]
, andDst
is reference to the inner type.Src
is anstruct
which has single field and#[repr(C)]
, andDst
is reference to the field type.Purpose
The lint should not be warn on
&'a E ~> &'a E::Repr
(whereE
is any field-less enum),&'a Transparent ~> &'a Transparent::Inner
(whereTransparent
isstruct
with#[repr(transparent)]
). The former can be achieved by primitive cast, but latter is not:Version
Additional Labels
@rustbot label C-question
The text was updated successfully, but these errors were encountered: