Add a NOOP_METHOD_CALL
lint for methods which should never be directly called
#66
Labels
NOOP_METHOD_CALL
lint for methods which should never be directly called
#66
Based on rust-lang/compiler-team#375
Summary
Add a new lint
NOOP_METHOD_CALL
, which fires on calls to methods which are known to do nothing. To start with, we would lint calls to the following methods:<&T as Clone>::clone
<&T as Borrow>::borrow
<&T as Deref>::deref
<&T as ToOwned>::to_owned
These trait impls are useful in generic code (e.g. you pass an
&T
to a function expecting aClone
argument), but are pointless when called directly (e.g.&bool::clone(&true)
).Note that we will intentionally not perform any kind of post-monomorphization checks. This lint will only fire on calls that are known to have the proper receiver (
&T
) at the call site (where the user could just remove the call).For example
The precise mechanism used to indicate that these methods should be linted is not specified.
To start with, we could add an internal attribute
#[noop]
, or hard-code a list of method paths in a lint visitor.In the future, this could be made available to user code by stabilizing some mechanism to mark a function as being linted by
NOOP_METHOD_CALL
.However, any such mechanism will need to have a way of dealing with blanekt impls (e.g.
<&T as ToOwned>::to_owned
goes throughimpl<T: Clone> ToOwned for T
), which will require additional design work.About this issue
This issue corresponds to a lang-team design meeting proposal. It corresponds
to a possible topic of discussion that may be scheduled for deeper discussion
during one of our design meetings.
The text was updated successfully, but these errors were encountered: