Clippy lints / Restriction
Clippy lint · Restriction · checked with Clippy 0.1.99
clippy::missing_trait_methods: Checks if a provided method is used implicitly by a trait implementation
What it meansChecks if a provided method is used implicitly by a trait implementation. It is in the restriction group and off by default.
Does it matter?
To ensure that a certain implementation implements every method; for example, a wrapper type where every method should delegate to the corresponding method of the inner type’s implementation. This lint should typically be enabled on a specific trait impl item rather than globally.
Lints that forbid language features for specific codebases (no unwrap, no indexing...). Off by default; pick them one by one, never the whole group.
How to fix it
Clippy does not fix this one automatically. Change the code by hand:
Flagged
trait Trait {
fn required();
fn provided() {}
}
#[warn(clippy::missing_trait_methods)]
impl Trait for Type {
fn required() { /* ... */ }
}
Write this instead
trait Trait {
fn required();
fn provided() {}
}
#[warn(clippy::missing_trait_methods)]
impl Trait for Type {
fn required() { /* ... */ }
fn provided() { /* ... */ }
}
Turn it off, or on
It is off by default. To use it, set it to warn or deny:
Whole crate (Cargo.toml)
[lints.clippy]
missing_trait_methods = "warn"In code
#![warn(clippy::missing_trait_methods)]One run
cargo clippy -- -W clippy::missing-trait-methodsThe [lints] table needs Rust 1.74 or newer. In a workspace, put it under [workspace.lints.clippy] and add [lints] workspace = true to each member.
Clippy's own documentation
What it does
Checks if a provided method is used implicitly by a trait implementation.
Why restrict this?
To ensure that a certain implementation implements every method; for example, a wrapper type where every method should delegate to the corresponding method of the inner type’s implementation.
This lint should typically be enabled on a specific trait impl item
rather than globally.
Example
trait Trait {
fn required();
fn provided() {}
}
#[warn(clippy::missing_trait_methods)]
impl Trait for Type {
fn required() { /* ... */ }
}
Use instead:
trait Trait {
fn required();
fn provided() {}
}
#[warn(clippy::missing_trait_methods)]
impl Trait for Type {
fn required() { /* ... */ }
fn provided() { /* ... */ }
}
From the Clippy lint list (0.1.99), part of the Rust project, MIT or Apache-2.0. Official entry.
Related lints
- unwrap_usedChecks for .unwrap() or .unwrap_err() calls on Results and .unwrap() call on Options
- module_name_repetitionsDetects public item names that are prefixed or suffixed by the containing public module’s name
- expect_usedChecks for .expect() or .expect_err() calls on Results and .expect() call on Options
- missing_asserts_for_indexingindexing into a slice multiple times without an `assert`
- missing_docs_in_private_itemsWarns if there is missing documentation for any private documentable item
- missing_inline_in_public_itemsmissing `#[inline]` on a publicly callable function
- mixed_read_write_in_expressionunsequenced read of `x`
- mod_module_filesChecks that module layout uses only self named module files; bans mod.rs files
All 847 Clippy lints · Rust compiler errors · Cargo.toml checker
Up next
Related lintclippy::unwrap_usedChecks for .unwrap() or .unwrap_err() calls on Results and .unwrap() call on OptionsRead it next →Did this answer your question?