fix: no generate unused generic params in trait sign#22519
Conversation
Example
---
```rust
struct Foo<T, const N: usize>([T; N]);
impl<T, const N: usize> F$0oo<T, N> {
fn spec_len(&self) -> usize {
N
}
}
```
**Before this PR**
```rust
struct Foo<T, const N: usize>([T; N]);
trait SpecLen<T, const N: usize> {
fn spec_len(&self) -> usize;
}
impl<T, const N: usize> SpecLen<T, N> for Foo<T, N> {
fn spec_len(&self) -> usize {
N
}
}
```
**After this PR**
```rust
struct Foo<T, const N: usize>([T; N]);
trait SpecLen {
fn spec_len(&self) -> usize;
}
impl<T, const N: usize> SpecLen for Foo<T, N> {
fn spec_len(&self) -> usize {
N
}
}
```
| .all() | ||
| .file_ranges() | ||
| .any(|it| trait_ranges.iter().any(|range| range.contains_range(it.range))) |
There was a problem hiding this comment.
| .all() | |
| .file_ranges() | |
| .any(|it| trait_ranges.iter().any(|range| range.contains_range(it.range))) | |
| .at_least_one() |
We don't actually need to check whether they're in the range, since they're declared in it.
There was a problem hiding this comment.
We don't actually need to check whether they're in the range, since they're declared in it.
This is necessary because the references in self-type and fn-body need to be ignored
There was a problem hiding this comment.
Right, then references in the body of consts/type aliases should also be ignored.
There was a problem hiding this comment.
Because const and type exist in both trait and impl after generation, they are retained
It should be up to the user to decide which one to adopt
There was a problem hiding this comment.
I don't think they should be retained, but, fair enough.
| .assoc_item_list() | ||
| .into_iter() | ||
| .flat_map(|list| list.assoc_items()) | ||
| .map(item_in_trait_range) |
There was a problem hiding this comment.
Shouldn't we need to check for where clause as well?
Consider something like this:
impl<T> Foo<T> where T: Copy { fn foo() {} } There was a problem hiding this comment.
True. I think it's better to have a negative list, i.e. a list of excluded ranges.
Example
Before this PR
After this PR