Open madsmtm opened 11 months ago
Some (sometimes unjustifiably) use Deref
for newtypes, even large projects like bevy. This would afaik lint if it's generic, as an example, struct Meters<T: num::Float>(pub T)
In the case fully generic means no trait bounds, yeah this would work. Even if it's a newtype/marker type that would still be prone to issues
What it does
Generic smart pointers like
Box<T>
,Rc<T>
and so on are recommended to use associated functions instead of inherent methods to avoid compatibility hazards withDeref
. As an example, seeBox::leak
. This is also documented in the Rust API Guidelines.This lint warns on every inherent method on types that implement
Deref
in a fully generic fashion.(In particular, it should activate when
type Target = T
, but not whentype Target = u8
ortype Target = [T]
).Advantage
Drawbacks
Example
Could be written as:
Or, in the case where the user has read and understood the drawbacks, be explicitly allowed: