-
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
Warn on push_str
with a single-character string literal
#5875
Comments
@rustbot modify labels to +A-style +A-performance |
Hmm, rustbot's not responding... |
@rustbot modify labels: -A-style Okay, seems to work, just had to add rustbot with write permissions to this repo. |
…lip1995 Lint `push_str` with a single-character string literal Fixes #5875 changelog: `* [single_char_push_str]`
Correct me if I'm wrong, but this lint does not seem to working on the latest nightly. With this code: // src/main.rs
fn main() {
let mut string = String::new();
string.push_str("R");
} When I run nightly clippy, I don't get any warnings: $ cargo +nightly clippy
Checking clippy-issue-5875 v0.1.0 (~/clippy-issue-5875)
Finished dev [unoptimized + debuginfo] target(s) in 0.11s Output of
|
@camelid if I'm not mistaken, the clippy component is built now from the cc @flip1995 for any imprecision with the component release process, I don't want to lie to anyone :) |
What it does
Warns when using
push_str
with a single-character string literal, andpush
with achar
would work fine.Categories (optional)
clippy::style
andclippy::perf
(maybeclippy::pedantic
?)What is the advantage of the recommended code over the original code?
char
, since it's just a number and will be inlined, than to push a&'static str
, which must be stored in the binary and accessed via a pointerDrawbacks
None.
Example
Could be written as:
The text was updated successfully, but these errors were encountered: