rust-lang / rust-lang/rust-clippy
Fp with nonsense suggestion from type_repetition_in_bounds when using #[derivative]
Open
Nobody has claimed this yet.
C-bug
I-false-positive
I-suggestion-causes-error
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
Summary
When using derivative to generate a Clone impl, clippy produces a FP. Also, the suggestion is nonsense:
"I: Clone, I::Item: Clone": Iterator + "I: Clone, I::Item: Clone"
Lint Name
type_repetition_in_bounds
Reproducer
I tried this code:
#![warn(clippy::type_repetition_in_bounds)]
use derivative::Derivative; // 2.2.0
// generates
// impl<I: Iterator> Clone for S<I> where I: Clone, I::Item: Clone { ... }
#[derive(Clone)]
pub struct S<I: Iterator> {
pub i: I,
pub item: I::Item,
}
#[derive(Derivative)]
#[derivative(
Clone(bound = "I: Clone, I::Item: Clone"),
)]
pub struct Foo<I: Iterator> {
inner: S<I>,
}
I saw this happen:
warning: this type has already been used as a bound predicate
--> src/lib.rs:15:19
|
15 | Clone(bound = "I: Clone, I::Item: Clone"),
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: the lint level is defined here
--> src/lib.rs:1:9
|
1 | #![warn(clippy::type_repetition_in_bounds)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= help: consider combining the bounds: `"I: Clone, I::Item: Clone": Iterator + "I: Clone, I::Item: Clone"`
I expected to see this happen:
No warning.
Version
rustc 1.62.0 (a8314ef7d 2022-06-27)
binary: rustc
commit-hash: a8314ef7d0ec7b75c336af2c9857bfaf43002bfc
commit-date: 2022-06-27
host: x86_64-unknown-linux-gnu
release: 1.62.0
LLVM version: 14.0.5
Additional Labels
@rustbot label +I-suggestion-causes-error
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the implementation and tests for the type_repetition_in_bounds lint, then reproduce the supplied example using derivative 2.2.0. Done means the false positive is absent and no malformed suggestion is emitted for the shown Clone bound.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100