Unconstrained parameter fix#148788
Conversation
|
This PR modifies |
|
r? @davidtwco rustbot has assigned @davidtwco. Use |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
☔ The latest upstream changes (presumably #150844) made this pull request unmergeable. Please resolve the merge conflicts. |
de845c2 to
1f5e308
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
bbce6e5 to
06e17b4
Compare
This comment has been minimized.
This comment has been minimized.
|
Reminder, once the PR becomes ready for a review, use |
This comment has been minimized.
This comment has been minimized.
1747f90 to
0b83de8
Compare
This comment has been minimized.
This comment has been minimized.
|
@rustbot ready |
| return self.span.shrink_to_hi(); | ||
| } | ||
|
|
||
| let is_impl_generic = |par: &&GenericParam<'_>| match par.kind { |
There was a problem hiding this comment.
| let is_impl_generic = |par: &&GenericParam<'_>| match par.kind { | |
| let is_param_explicit = |par: &&GenericParam<'_>| match par.kind { |
| let parameter_type = if is_lifetime { "lifetime" } else { "type" }; | ||
| if is_param_used { | ||
| let msg = format!( | ||
| "make use of the {} parameter `{}` in the `self` type", |
There was a problem hiding this comment.
| "make use of the {} parameter `{}` in the `self` type", | |
| "make use of the {} parameter `{}` in the `{}` type", |
Can you get the name of the Self type from its DefId?
| Applicability::MaybeIncorrect, | ||
| ); | ||
| if suggestions.len() == 2 { | ||
| let msg = format!("or make use of it"); |
There was a problem hiding this comment.
| let msg = format!("or make use of it"); | |
| let msg = format!("or use it"); |
| let msg2 = format!( | ||
| "and add it to the struct definition of {} as well since it's used in the body of the impl", | ||
| tcx.def_path_str(struct_def_id) | ||
| ); |
There was a problem hiding this comment.
You should probably use a MultiSpan with the definition and the impl and emit a single suggestion for this instead of two distinct suggestions but that would need to be applied together
There was a problem hiding this comment.
And change the message to "use this type parameter in the type definition"
| /// - `impl<'a> Struct { ... }` where `'a` is unused -> suggests removing `'a`. | ||
| /// - `impl<T> Struct { // T used in here }` where `T` is used in the body but not in the self type -> suggests adding `T` to the self type and struct definition. | ||
| /// - `impl<T> Struct { ... }` where the struct has a generic parameter with a default -> suggests adding `T` to the self type. | ||
| pub(crate) fn suggest_to_remove_or_use_generic( |
There was a problem hiding this comment.
Can you add your own test file that tests all of these cases specifically, as well as where the type is defined in another crate, or where the type is generated from a macro.
7664723 to
3827e42
Compare
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
This comment has been minimized.
This comment has been minimized.
e2d16ae to
7e1bb3a
Compare
This comment has been minimized.
This comment has been minimized.
When an unconstrained type or lifetime parameter is detected in an `impl`, provide more specific help based on its usage: - If the parameter is entirely unused, suggest removing it. - If it is used in the `impl` body but not the `Self` type, suggest including it in the `Self` type and the struct definition. This also adds a comprehensive UI test for these cases.
7e1bb3a to
d38acdb
Compare
|
I have squashed the commits and addressed the feedback regarding MultiSpan and the new tests |
|
@rustbot ready |
View all comments
This PR is an attempt to solve the issue described in the issue #107295