Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FP trait_duplication_in_bounds #11067

Open
matthiaskrgr opened this issue Jul 2, 2023 · 0 comments
Open

FP trait_duplication_in_bounds #11067

matthiaskrgr opened this issue Jul 2, 2023 · 0 comments
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied

Comments

@matthiaskrgr
Copy link
Member

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

@matthiaskrgr matthiaskrgr added C-bug Category: Clippy is not doing the correct thing I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied I-false-positive Issue: The lint was triggered on code it shouldn't have labels Jul 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied
Projects
None yet
Development

No branches or pull requests

1 participant