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
| /// | ||
| /// 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.
or perhaps as a static fn on the format args expansion helper type
|
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 |
| /// Explicit values passed after the format string, ignoring implicit captures. `[1, z + 2]` for | ||
| /// `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.
we may want to clarify this comment -- the above format!(...) doesn't look like valid code.
There was a problem hiding this comment.
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
, 1from theexpect_fun_callsuggestion: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_argsspecificclippy_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