Clippy lints / Restriction
Clippy lint · Restriction · checked with Clippy 0.1.99
clippy::multiple_inherent_impl: multiple implementations of this structure
What it meansChecks for multiple inherent implementations of a struct The config option controls the scope in which multiple inherent impl blocks for the same struct are linted, allowing values of module (only within the same module), file (within the same file), or crate (anywhere in the crate, default). It is in the restriction group and off by default.
What you see
warning: multiple implementations of this structure --> main.rs:7:1 | 7 | / impl X { 8 | | fn other() {} 9 | | } | |_^ | note: first implementation here --> main.rs:4:1 | 4 | / impl X { 5 | | fn one() {} 6 | | } | |_^ = help: for further information visit https://rust-lang.github.io/rust-clippy/stable/index.html#multiple_inherent_impl = note: requested on the command line with `-W clippy::multiple-inherent-impl`
Real output of Clippy 0.1.99 (Rust 1.99) on the example below. Names and line numbers in yours will differ.
Does it matter?
Splitting the implementation of a type makes the code harder to navigate.
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
struct X;
impl X {
fn one() {}
}
impl X {
fn other() {}
}
Write this instead
struct X;
impl X {
fn one() {}
fn other() {}
}
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]
multiple_inherent_impl = "warn"In code
#![warn(clippy::multiple_inherent_impl)]One run
cargo clippy -- -W clippy::multiple-inherent-implThe [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.
Settings in clippy.toml
inherent-impl-lint-scope: Sets the scope (“crate”, “file”, or “module”) in which duplicate inherent impl blocks for the same type are linted.
Clippy's own documentation
What it does
Checks for multiple inherent implementations of a struct
The config option controls the scope in which multiple inherent impl blocks for the same
struct are linted, allowing values of module (only within the same module), file
(within the same file), or crate (anywhere in the crate, default).
Why restrict this?
Splitting the implementation of a type makes the code harder to navigate.
Example
struct X;
impl X {
fn one() {}
}
impl X {
fn other() {}
}
Could be written:
struct X;
impl X {
fn one() {}
fn other() {}
}
Configuration
-
inherent-impl-lint-scope: Sets the scope (“crate”, “file”, or “module”) in which duplicate inherentimplblocks for the same type are linted.(default:
"crate")
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
- mod_module_filesChecks that module layout uses only self named module files; bans mod.rs files
- modulo_arithmeticyou are using modulo operator on constants with different signs: `-17 % 3`
- multiple_unsafe_ops_per_blockthis `unsafe` block contains 2 unsafe operations, expected only one
- mutex_atomicChecks for usage of Mutex<X> where an atomic will do
- mutex_integerChecks for usage of Mutex<X> where X is an integral type
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?