-
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
FormatArgsExpn: Find comma spans and ignore weird proc macro spans #9586
Conversation
r? @Manishearth (rust-highfive has picked a reviewer for you, use r? to override) |
☔ The latest upstream changes (presumably #9547) made this pull request unmergeable. Please resolve the merge conflicts. |
Overall looks good to me! One thing you may want to reuse - I trimmed down the |
|
465e297
to
9d322f6
Compare
clippy_utils/src/macros.rs
Outdated
/// | ||
/// Ensures that the format string and values aren't coming from a proc macro that sets the output | ||
/// span to that of its input | ||
fn comma_spans(cx: &LateContext<'_>, explicit_values: &[&Expr<'_>], fmt_span: Span) -> Option<Vec<Span>> { |
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.
nit: fmt_args_comma_spans
?
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.
or perhaps as a static fn on the format args expansion helper type
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.
👍
Changed
r=me, one nit |
9d322f6
to
9226066
Compare
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
1 similar comment
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
/// `format!("{x} {} {y}", 1, z + 2)`. | ||
value_args: Vec<&'tcx Expr<'tcx>>, | ||
explicit_values: Vec<&'tcx Expr<'tcx>>, |
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.
we may want to clarify this comment -- the above format!(...)
doesn't look like valid code.
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.
Ah whoops, the {y}
should be {}
. I also forgot to remove the FIXME if you fancy doing a cleanup PR, otherwise I'll get around to it
lint: fix a few comments minor cleanup per `@Alexendoo` [comment](#9586 (comment)) changelog: none
Fixes the following cases:
A missing
, 1
from theexpect_fun_call
suggestion:The suggestion removing from the comma in the comment rather than the one after the format string:
It also no longer accepts expansions where a format string or argument has a "weird" proc macro span, that is one where the literal/expression it outputs has the span of one of its inputs. Kind of like a
format_args
specificclippy_utils::is_from_proc_macro
, e.g.format!(indoc! {" ... "})
changelog: [
expect_fun_call
]: Fix suggestion forformat!
using captured variableschangelog: [
print_literal
], [write_literal
], [uninlined_format_args
]: Fix suggestion when following a comment including a comma