rust-lang / rust-lang/rust-clippy
new lint rule - dublicate generics in `where`
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
What it does
I don't really understand which one this rule should apply to - rustfmt or clippy.
I would like duplicate generics to be highlighted with a warning or automatically formatted with deletion. It's hard for me to say what should be correct.
Advantage
There will be no duplicate generics in where.
I get a copy error when there is a duplicate generics in the function arguments, but I don't get a copy error when there are duplicates in the where keyword
error[E0403]: the name `T` is already used for a generic parameter in this item's generic parameters
--> src/main.rs:17:20
|
17 | fn new<T: Default, T: Default /*linted*/>() -> T {
| - ^ already used
| |
| first use of `T`
For more information about this error, try `rustc --explain E0403`.
error: could not compile `kek` (bin "kek") due to 1 previous error
Drawbacks
There is not
Example
show error only func new()
fn main() {
assert_eq!(0.0, new());
assert_eq!(0.0, new_where());
assert_eq!(0, new());
assert_eq!(0, new_where());
}
fn new<T: Default, T: Default /*linted*/>() -> T {
T::default()
}
fn new_where<T>() -> T
where
T: Default,
T: Default, // Duplicate condition, not linted
{
T::default()
}
Could be written as:
Maybe...
Diagnostics:
1. the name `T` is already used in WHERE for a generic parameter in this item's generic parameters
already used [E0number]
2. first use of `T` [E0number]
Must be show errors in funcs new and new_where.
fn main() {
assert_eq!(0.0, new());
assert_eq!(0.0, new_where());
assert_eq!(0, new());
assert_eq!(0, new_where());
}
fn new<T: Default>() -> T {
T::default()
}
fn new_where<T>() -> T
where
T: Default,
{
T::default()
}
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
The issue names no files, tests, or entry points. First determine whether duplicate where generics belong in rustfmt or Clippy, then clarify the intended diagnostic and behavior using the new and new_where examples; done means an agreed scope and corresponding coverage for both cases.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100