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

Better help message for comparison_chain lint #13762

Merged
merged 1 commit into from
Dec 10, 2024

Conversation

samueltardieu
Copy link
Contributor

changelog: [comparison_chain]: give explicit help message showing a clear suggestion

Close #13739

@rustbot
Copy link
Collaborator

rustbot commented Nov 30, 2024

r? @Alexendoo

rustbot has assigned @Alexendoo.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Nov 30, 2024
@samueltardieu
Copy link
Contributor Author

r? @y21

@rustbot rustbot assigned y21 and unassigned Alexendoo Dec 5, 2024
span_lint_and_help(
cx,
COMPARISON_CHAIN,
expr.span,
"`if` chain can be rewritten with `match`",
None,
"consider rewriting the `if` chain to use `cmp` and `match`",
format!("consider rewriting the `if` chain with: `match {lhs}.cmp({rhs}) {{...}}`"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At this point now that we're giving code snippets to the user and reference real code the user wrote (esp. with the colon) I feel like it would make sense to start giving this its own actual verbose suggestion with Applicability::HasPlaceholders. That seems like it would also help with making it easier to spot this part of the diagnostic.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean like this? (I just pushed a revised version)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant span_lint_and_then + span_suggestion_verbose, so that the suggestion gets put on its own line at the bottom, but this is fine too

Copy link
Member

@y21 y21 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, thanks!

@y21 y21 added this pull request to the merge queue Dec 10, 2024
Merged via the queue into rust-lang:master with commit 59740a8 Dec 10, 2024
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties
Projects
None yet
Development

Successfully merging this pull request may close these issues.

comparison_chain false positive when constant depends on generic parameter
4 participants