-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Description
What it does
Detect when one or more trait methods were not implemented, i.e. delegated to their default implementation.
Categories (optional)
- Kind:
clippy::restriction
Why
Useful for code that needs to exhaustively implement a trait for one reason or another.
For example, the serenity crate has an EventHandler trait with dozens of optional methods, and you usually implement the methods corresponding to the events you care about. However, in my project I need to listen for all events to package them into an Event enum (link). The ability to do #[warn(clippy::incomplete_trait_impl)]
(lint name up for debate) would be awesome to make sure I don't miss any events.
Possible names
- incomplete_trait_impl
- unimplemented_trait_methods
- default_implementation_used
- default_trait_impl_used
- non_exhaustive_trait_impl
Drawbacks
Seeing as it's an opt-in clippy::restriction lint, there are no drawbacks. People can activate the lint specifically for situations where it is useful.
Example
struct Foo;
impl some_trait::SomeTrait for Foo {
fn a() { /* ... */ }
fn b() { /* ... */ }
fn c() { /* ... */ }
// Oops, forgot to implement d() which was added in some_trait 0.13.4
}
Could be written as:
struct Foo;
impl some_trait::SomeTrait for Foo {
fn a() { /* ... */ }
fn b() { /* ... */ }
fn c() { /* ... */ }
fn d() { /* ... */ }
}