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

I::Item: Clone, J::Item: Clone triggers FP #8162

Closed
jendrikw opened this issue Dec 23, 2021 · 2 comments · Fixed by #8224
Closed

I::Item: Clone, J::Item: Clone triggers FP #8162

jendrikw opened this issue Dec 23, 2021 · 2 comments · Fixed by #8224
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

Comments

@jendrikw
Copy link
Contributor

jendrikw commented Dec 23, 2021

Summary

This only happens when using both J::AssociatedType and one the types is Self.

Lint Name

type_repetition_in_bounds

Reproducer

I tried this code playground:

#[warn(clippy::type_repetition_in_bounds)]

trait T: Iterator {
    fn f<J>(self, _: J)
    where
        Self: Sized,
        Self::Item: Clone,
        J: Iterator,
        J::Item: Clone,
    {
    }
}

I saw this happen:

warning: this type has already been used as a bound predicate
 --> src/lib.rs:9:9
  |
9 |         J::Item: Clone,
  |         ^^^^^^^^^^^^^^
  |
note: the lint level is defined here
 --> src/lib.rs:1:8
  |
1 | #[warn(clippy::type_repetition_in_bounds)]
  |        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  = help: consider combining the bounds: `J::Item: Clone + Clone`

I expected to see this happen:

No warning.

Version

rustc 1.57.0 (f1edd0429 2021-11-29)
binary: rustc
commit-hash: f1edd0429582dd29cccacaf50fd134b05593bd9c
commit-date: 2021-11-29
host: x86_64-unknown-linux-gnu
release: 1.57.0
LLVM version: 13.0.0

Additional Labels

No response

@jendrikw jendrikw added C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have labels Dec 23, 2021
@jendrikw
Copy link
Contributor Author

I've found another example: playground

#![warn(clippy::type_repetition_in_bounds)]

pub struct ZipAll<I: Iterator, J: Iterator>(I, J);

impl<I: Iterator, J: Iterator> ZipAll<I, J>
where
    I::Item: Clone,
    J::Item: Clone,
{}

@jendrikw jendrikw changed the title Self::Item: Clone, J::Item: Clone triggers FP I::Item: Clone, J::Item: Clone triggers FP Dec 27, 2021
@jendrikw
Copy link
Contributor Author

I think this is a duplicate (but with a smaller example) of #7360.

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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant