-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Conversation
r? @Alexendoo rustbot has assigned @Alexendoo. Use |
3f1a571
to
975e3ed
Compare
r? @y21 |
clippy_lints/src/comparison_chain.rs
Outdated
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}) {{...}}`"), |
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.
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.
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.
You mean like this? (I just pushed a revised version)
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 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
975e3ed
to
69411e0
Compare
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.
Looks good to me, thanks!
changelog: [
comparison_chain
]: give explicit help message showing a clear suggestionClose #13739