RS.CLIPPY.IMPLIED_BOUNDS_IN_IMPLS
Specifying bounds that are implied by other bounds in `impl Trait` type
This checker is a Clippy lint created by The Rust Project Contributors. The documentation shown here is a copy of the original documentation for: implied_bounds_in_impls. Copyright ©2025 The Rust Team. All rights reserved.
What it does
Looks for bounds in impl Trait in return position that are implied by other bounds.
This can happen when a trait is specified that another trait already has as a supertrait
(e.g. fn() -> impl Deref + DerefMut<Target = i32> has an unnecessary Deref bound,
because Deref is a supertrait of DerefMut)
Why is this bad?
Specifying more bounds than necessary adds needless complexity for the reader.
Limitations
This lint does not check for implied bounds transitively. Meaning that
it doesn't check for implied bounds from supertraits of supertraits
(e.g. trait A {} trait B: A {} trait C: B {}, then having an fn() -> impl A + C)
Example
fn f() -> impl Deref<Target = i32> + DerefMut<Target = i32> {
// ^^^^^^^^^^^^^^^^^^^ unnecessary bound, already implied by the `DerefMut` trait bound
Box::new(123)
}
Use instead:
fn f() -> impl DerefMut<Target = i32> {
Box::new(123)
}