-
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
WIP format literal arg inlining #10740
Conversation
r? @llogiq (rustbot has picked a reviewer for you, use r? to override) |
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. I have but one request for clarification and I'd like to see a test with macros.
clippy_lints/src/format_args.rs
Outdated
} else if !matches!(arg.kind, FormatArgumentKind::Captured(_)) | ||
&& let Some(FormatPlaceholder{span: Some(placeholder_span), ..}) = placeholder | ||
&& let rustc_ast::ExprKind::Lit(lit) = &arg.expr.kind | ||
&& lit.kind == LitKind::Str // FIXME: lit.kind must match the format string kind |
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.
This isn't clear to me. What other kinds would there be?
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 are also raw strings
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.
And possibly byte strings too? Not certain
@@ -262,3 +262,17 @@ fn tester2() { | |||
local_i32, | |||
}; | |||
} | |||
|
|||
fn literals() { |
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 worry about cases where the format string and literal value come from different macro expansions. We should have a test where that is the case.
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.
Yeah, i will need tons more of tests for this - some already exist in
- https://github.com/rust-lang/rust-clippy/blob/master/tests/ui/write_literal.rs
- https://github.com/rust-lang/rust-clippy/blob/master/tests/ui/write_literal_2.rs
- https://github.com/rust-lang/rust-clippy/blob/master/tests/ui/write_with_newline.rs
Could you give an example of what specific macro expansion where you thinking about?
I'd say this should be under a new lint name, although it's similar what it's doing is different enough to the existing The existing implementation can also be used, it handles the various raw/non-raw permutations of the literal and format string as well as some other literals. You'd have to change the part where it checks the macro names before it's called + do a lint rename for both |
@Alexendoo after some more thinking, it seems separating it into a new lint would create more problems than solve:
So in short, we would not really gain anything besides problems from multiple lints... Not worth it IMO :) |
I don't see what problem that would cause here, overlapping suggestions would cause rustfix ui tests to fail ( The main thing is so that you can set the lint levels independently, e.g. It would also make the lint documentation more confusing to have to explain the two different kinds of inlining in one lint, and how
|
@Alexendoo you do raise important config point. I think we can actually achieve both goals if we track the type of inlining needed -- e.g. if both are enabled, and both are needed (the |
To me that sounds too complicated/novel considering the problem is relatively minor |
Agreed, let's not complicate the solution. As long as both lints don't step on each other's toes by issuing incompatible suggestions, having two lints that don't care about each other is fine. |
☔ The latest upstream changes (presumably #10358) made this pull request unmergeable. Please resolve the merge conflicts. |
86cfa0b
to
de80373
Compare
A rough draft of rust-lang#10739 implementation. The goal is to allow any kind of literal string arguments to be inlined automatically. ```rust format!("hello {}", "world") // is replaced with format!("hello world") ```
de80373
to
e50f944
Compare
☔ The latest upstream changes (presumably #12306) made this pull request unmergeable. Please resolve the merge conflicts. |
Hey @nyurik, this is a ping from triage. Do you still plan to continue this PR? If you need help, you're always welcome to ask questions here or on Zulip :) |
Hey this is triage, I'm closing this due to inactivity. If you want to continue this implementation, you're welcome to create a new PR. Thank you for the time, you already put into this! Interested parties are welcome to pick this implementation up as well :) @rustbot label +S-inactive-closed -S-waiting-on-author -S-waiting-on-review |
A rough draft of #10739 implementation. The goal is to allow any kind of literal string arguments to be inlined automatically.