Skip to content

FP trait_duplication_in_bounds #11067

@matthiaskrgr

Description

@matthiaskrgr

Summary

.

Lint Name

trait_duplication_in_bounds

Reproducer

I tried this code:

fn main() {
    multiple_constraints(&[[""]]); 
}

fn multiple_constraints<T, U, V, X, Y>(_: T)
where
    T: IntoIterator<Item = U> + IntoIterator<Item = X>,
    U: IntoIterator<Item = V>,
    V: AsRef<str>,
    X: IntoIterator<Item = Y>,
    Y: AsRef<std::ffi::OsStr>,
{
}

I saw this happen:

warning: these where clauses contain repeated elements
 --> ./src/tools/clippy/tests/ui/needless_borrow.rs:7:8
  |
7 |     T: IntoIterator<Item = U> + IntoIterator<Item = X>,
  |        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `IntoIterator<Item = U>`
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#trait_duplication_in_bounds
  = note: requested on the command line with `-W clippy::trait-duplication-in-bounds`

warning: 1 warning emitted

I expected to see this happen:

Suggetsion does not compile:

fn main() {
    multiple_constraints(&[[""]]); 
}

fn multiple_constraints<T, U, V, X, Y>(_: T)
where
    T: IntoIterator<Item = U>,
    U: IntoIterator<Item = V>,
    V: AsRef<str>,
    X: IntoIterator<Item = Y>,
    Y: AsRef<std::ffi::OsStr>,
{
}
error[E0282]: type annotations needed
 --> ./src/tools/clippy/tests/ui/needless_borrow.rs:2:5
  |
2 |     multiple_constraints(&[[""]]);
  |     ^^^^^^^^^^^^^^^^^^^^ cannot infer type of the type parameter `X` declared on the function `multiple_constraints`
  |
help: consider specifying the generic arguments
  |
2 |     multiple_constraints::<&[[&str; 1]; 1], &[&str; 1], &&str, X, Y>(&[[""]]);
  |                         ++++++++++++++++++++++++++++++++++++++++++++

error: aborting due to previous error

For more information about this error, try `rustc --explain E0282`.

Version

rustc 1.72.0-nightly (32d81eccd 2023-07-02)
binary: rustc
commit-hash: 32d81eccd64513bacef9dfa1574543ada6b45d85
commit-date: 2023-07-02
host: x86_64-unknown-linux-gnu
release: 1.72.0-nightly
LLVM version: 16.0.5

Additional Labels

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when applied

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions