IMPL_TRAIT_REDUNDANT_CAPTURES in rustc_lint::impl_trait_overcaptures - Rust
Description: The `impl_trait_redundant_captures` lint warns against cases where use of the precise capturing `use<...>` syntax is not needed.

Skip to main content

## IMPL_TRAIT_REDUNDANT_CAPTURES

# Static IMPL_TRAIT_REDUNDANT_CAPTURES

Source

    pub static IMPL_TRAIT_REDUNDANT_CAPTURES: &Lint

Expand description

The `impl_trait_redundant_captures` lint warns against cases where use of the precise capturing `use<...>` syntax is not needed.

In the 2024 edition, `impl Trait`s will capture all lifetimes in scope. If precise-capturing `use<...>` syntax is used, and the set of parameters that are captures are equal to the set of parameters in scope, then the syntax is redundant, and can be removed.

#### §Example

ⓘ

    fn test<'a>(x: &'a i32) -> impl Sized + use<'a> { x }

{{produces}}

#### §Explanation

To fix this, remove the `use<'a>`, since the lifetime is already captured since it is in scope.