-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Adding helper to report_unused_parameter #108252
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @nagisa (or someone else) soon. Please see the contribution instructions for more information. |
This comment has been minimized.
This comment has been minimized.
err.span_suggestion( | ||
span, | ||
format!( | ||
"Either remove the type parameter '{}' or make use of it, for example ` for S<{}>`.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Make use of it" is a little misleading, the user might already use it in a where clause. I'm not sure what the best wording for this would be.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe just removing the "make" and leave it Either remove the type parameter or use it?
I am not sure on the words as well... =(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yea that sounds better
"Either remove the type parameter '{}' or make use of it, for example ` for S<{}>`.", | ||
name, name | ||
), | ||
"", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it's a good idea to give a suggestion to remove it. Simply removing the parameter is usually not the solution to this error in my experience.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I based myself on the "desired output" on #107295
What would be a good explanation? :)
r? @oli-obk |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we have enough information to actually report a good message here. We'll need to add more information to the report_unused_parameter
function, but first we need to figure out what the ideal output even is. It may be better to
- only add another note in this PR
- in a follow up PR: turn this into a structured error (https://rustc-dev-guide.rust-lang.org/diagnostics/diagnostic-structs.html)
- add more information (type, trait, full span for generic param) and report more targeted errors
the last step is very handwavy on purpose, as turning this diagnostic into a really good one is hard, so it'll need a lot of experimentation, ideally initially restricted to just a few cases, possibly avoiding a removal suggestion entirely
help: Either remove the type parameter 'N' or make use of it, for example ` for S<N>`. | ||
| | ||
LL - impl <const N: usize> Collatz<{Some(N)}> {} | ||
LL + impl <> Collatz<{Some(N)}> {} | ||
| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in this case the suggestion is wrong, removing it is never the right thing if it is used, but in a way that isn't legal.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since we know it in this case (we are emitting the two notes above after all), you can re-use the condition for that and not emit the suggestion in that case
help: Either remove the type parameter 'T' or make use of it, for example ` for S<T>`. | ||
| | ||
LL - impl<T,T> Qux<T,T> for Option<T> {} | ||
LL + impl<T,> Qux<T,T> for Option<T> {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
stray comma in the suggestion
help: Either remove the type parameter 'T' or make use of it, for example ` for S<T>`. | ||
| | ||
LL - impl<T: Default> Foo { | ||
LL + impl<: Default> Foo { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to remove the bounds, too
help: Either remove the type parameter 'N' or make use of it, for example ` for S<N>`. | ||
| | ||
LL - impl<const N: usize> Foo {} | ||
LL + impl<> Foo {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should remove the generic parameters entirely instead of leaving empty ones around
help: Either remove the type parameter 'I' or make use of it, for example ` for S<I>`. | ||
| | ||
LL - impl<'q, Q, I, F> A for TestB<Q, F> | ||
LL + impl<'q, Q, , F> A for TestB<Q, F> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
stray comma
err.span_suggestion( | ||
span, | ||
format!( | ||
"Either remove the type parameter '{}' or make use of it, for example ` for S<{}>`.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yea that sounds better
err.span_suggestion( | ||
span, | ||
format!( | ||
"Either remove the type parameter '{}' or make use of it, for example ` for S<{}>`.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: our messages start lowercase
err.span_suggestion( | ||
span, | ||
format!( | ||
"Either remove the type parameter '{}' or make use of it, for example ` for S<{}>`.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should not just suggest S<T>
. Either load the trait or type name and append the generics to that or write prosa explaining what's going on without naming the trait or type.
I think think can switch to waiting on author to incorporate changes and design suggestions. Feel free to request a review with @rustbot author |
@jkvargas any updates on this? |
Hi, |
☔ The latest upstream changes (presumably #114116) made this pull request unmergeable. Please resolve the merge conflicts. |
Closing this as inactive. Feel free to reöpen this pr or create a new pr if you get the time to work on this. Thanks |
Fixes issue: #107295