Skip to content
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

Closed
wants to merge 3 commits into from

Conversation

jkvargas
Copy link

Fixes issue: #107295

@rustbot
Copy link
Collaborator

rustbot commented Feb 20, 2023

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.

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Feb 20, 2023
@rust-log-analyzer

This comment has been minimized.

err.span_suggestion(
span,
format!(
"Either remove the type parameter '{}' or make use of it, for example ` for S<{}>`.",
Copy link
Member

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.

Copy link
Author

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... =(

Copy link
Contributor

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
),
"",
Copy link
Member

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.

Copy link
Author

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? :)

@jkvargas jkvargas requested a review from Noratrieb February 20, 2023 08:06
@oli-obk
Copy link
Contributor

oli-obk commented Feb 22, 2023

r? @oli-obk

@rustbot rustbot assigned oli-obk and unassigned nagisa Feb 22, 2023
Copy link
Contributor

@oli-obk oli-obk left a 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

  1. only add another note in this PR
  2. in a follow up PR: turn this into a structured error (https://rustc-dev-guide.rust-lang.org/diagnostics/diagnostic-structs.html)
  3. 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

Comment on lines +9 to +13
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)}> {}
|
Copy link
Contributor

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.

Copy link
Contributor

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> {}
Copy link
Contributor

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 {
Copy link
Contributor

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 {}
Copy link
Contributor

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>
Copy link
Contributor

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<{}>`.",
Copy link
Contributor

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<{}>`.",
Copy link
Contributor

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<{}>`.",
Copy link
Contributor

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.

@apiraino
Copy link
Contributor

I think think can switch to waiting on author to incorporate changes and design suggestions. Feel free to request a review with @rustbot ready, thanks!

@rustbot author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 29, 2023
@Dylan-DPC
Copy link
Member

@jkvargas any updates on this?

@jkvargas
Copy link
Author

@jkvargas any updates on this?

Hi,
I have been passing through some personal issues and I couldn't sit down yet to solve this yet.

@bors
Copy link
Contributor

bors commented Jul 27, 2023

☔ The latest upstream changes (presumably #114116) made this pull request unmergeable. Please resolve the merge conflicts.

@Dylan-DPC
Copy link
Member

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

@Dylan-DPC Dylan-DPC closed this Aug 6, 2023
@Dylan-DPC Dylan-DPC added S-inactive Status: Inactive and waiting on the author. This is often applied to closed PRs. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Aug 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-inactive Status: Inactive and waiting on the author. This is often applied to closed PRs. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants