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
Crate compilation often happens to be slow because of bunch of unnecessary trait implementations, especially via derives, that are not actually used in the public interface.
You can see here that trait is not used anywhere in private code, not exposed to the public interface and is generally just a dead code, but, unlike regular unused methods, this currently compiles with no warning.
Example 2 (public trait on private type):
pubtraitCustomTrait{fnsome_method(&self);}structS;implS{fndo_something_private(&self){}}implCustomTraitforS{fnsome_method(&self){}}pubfnf(){let s = S;
s.do_something_private();}
This time a type private to the library has a trait implementation that is, again, not used internally nor can be used outside because the type itself is not exposed.
I could put some more examples with #[derive(...)] but after macro expansion they would be analogous to the ones above, so probably not too interesting on their own (although do take time while proc macro does its job).
While this issue could potentially belong to Rust compiler itself, it seems worth trying to add this at least as a clippy warning first and see if it gains traction.
Also, apologies if that has been already discussed somewhere, the only related issue I found is Warn on unused/unnecessary trait bounds which is somewhat orthogonal to this one.
The text was updated successfully, but these errors were encountered:
RReverser
changed the title
Feature request: warn on unused traits
Feature request: warn on unused trait impls
Sep 23, 2018
Crate compilation often happens to be slow because of bunch of unnecessary trait implementations, especially via derives, that are not actually used in the public interface.
Example 1 (private trait on public type):
You can see here that trait is not used anywhere in private code, not exposed to the public interface and is generally just a dead code, but, unlike regular unused methods, this currently compiles with no warning.
Example 2 (public trait on private type):
This time a type private to the library has a trait implementation that is, again, not used internally nor can be used outside because the type itself is not exposed.
I could put some more examples with
#[derive(...)]
but after macro expansion they would be analogous to the ones above, so probably not too interesting on their own (although do take time while proc macro does its job).While this issue could potentially belong to Rust compiler itself, it seems worth trying to add this at least as a clippy warning first and see if it gains traction.
Also, apologies if that has been already discussed somewhere, the only related issue I found is Warn on unused/unnecessary trait bounds which is somewhat orthogonal to this one.
The text was updated successfully, but these errors were encountered: