-
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
Lint push_str
with a single-character string literal
#5881
Conversation
r? @phansch (rust_highfive has picked a reviewer for you, use r? to override) |
5dccf12
to
260e9ed
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.
Left some thoughts.
As a nit, in the changelog line the lint should be inside backticks so that the link to the description works from the changelog.
cc @flip1995
/// string.push('R'); | ||
/// ``` | ||
pub SINGLE_CHAR_PUSH_STR, | ||
style, |
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.
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.
It looks like rustc is optimizing the push_str("R")
to a push('R')
so it's not a performance difference.
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.
Sorry if I was not precise enough, I meant that Clippy's suggestion would not improve the performance.
if let Some(fn_def_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id); | ||
if match_def_path(cx, fn_def_id, &paths::PUSH_STR); | ||
if let ExprKind::Lit(ref lit) = extension_string.kind; | ||
if let LitKind::Str(symbol,_) = lit.node; |
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 think we should ignore raw strings as the intention of the user is probably to avoid escaping the character.
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.
The single_char_pattern
does replace raw strings, should i remove that feature
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.
Honestly I was not aware of that lint. I think we should not change the behavior at this point.
What I just realized: Wouldn't it be easier/better to enhance the |
10fa7b3
to
783108d
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.
LGTM, just some really minor nits
783108d
to
b381ade
Compare
LGTM, cc @flip1995 Thanks! |
📌 Commit b381ade has been approved by |
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
Fixes #5875
changelog:
* [single_char_push_str]