FP: unused_self
triggers if only the lifetime of self
is used
#4928
Labels
C-bug
Category: Clippy is not doing the correct thing
E-medium
Call for participation: Medium difficulty level problem and requires some initial experience.
I-false-positive
Issue: The lint was triggered on code it shouldn't have
Tested on clippy shipping with Rust 1.40.0:
Here's a contrived example that triggers the
unused_self
lint and fails to build:This is actually a valid pattern. In FFI code for instance,
A
might be responsible for initialising and freeing some part of a library, and the functionb
is used to create objects that belong to the library, and therefore can't outlive it. SoA
can just be a ZST whileB
usesPhantomData<&'a A>
to convey ownership semantics.If we rewrite the example so it directly uses
self
it works:But we don't want to hold pointers to
A
, we just want to express that instances ofB
belong to an instance ofA
.tl;dr
unused_self
doesn't catch edge cases whereself
is used without actually being used.The text was updated successfully, but these errors were encountered: