Migrate format_args.rs to rustc_ast::FormatArgs#10484
Conversation
| } | ||
|
|
||
| false | ||
| } |
There was a problem hiding this comment.
This is a slightly simplified version of
rust-clippy/clippy_utils/src/macros.rs
Lines 932 to 992 in f19db28
| error: variables can be used directly in the `format!` string | ||
| --> $DIR/uninlined_format_args.rs:125:20 | ||
| | | ||
| LL | println!("{}", format!("{}", local_i32)); | ||
| | ^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | | ||
| help: change this to | ||
| | | ||
| LL - println!("{}", format!("{}", local_i32)); | ||
| LL + println!("{}", format!("{local_i32}")); | ||
| | | ||
|
|
There was a problem hiding this comment.
This is a bug with root_macro_call_first_node, not sure why but it doesn't pick up that format!() as a macro call
| edition = "2021" | ||
|
|
||
| [dependencies] | ||
| arrayvec = { version = "0.7", default-features = false } |
There was a problem hiding this comment.
clippy_utils depends on this already so it's not a new dependency
We should probably just move that warning to rustc, since an empty |
|
I tried to apply a similar change to explicit_write.rs , and if let ExprKind::MethodCall(unwrap_fun, write_call, [], _) = expr.kind
&& unwrap_fun.ident.name == sym::unwrap
// match call to write_fmt
&& let ExprKind::MethodCall(write_fun, write_recv, [write_arg], _) = look_in_block(cx, &write_call.kind)
&& let ExprKind::Call(_, write_arg2) = look_in_block(cx, &write_arg.kind)
&& write_fun.ident.name == sym!(write_fmt)
// match calls to std::io::stdout() / std::io::stderr ()
&& let Some(dest_name) = if match_function_call(cx, write_recv, &paths::STDOUT).is_some() {
Some("stdout")
} else if match_function_call(cx, write_recv, &paths::STDERR).is_some() {
Some("stderr")
} else {
None
}
&& let Some(format_args) = root_macro_call_first_node(cx, write_call)
&& is_format_macro(cx, format_args.def_id)
// && let Some(format_args2) = FormatArgsExpn::find_nested(cx, expr, format_args.expn) |
|
The replacement would be You wouldn't need |
7b94c41 to
066949c
Compare
No longer lints empty precisions `{:.}` as the spans aren't available
066949c to
3259b48
Compare
| } | ||
| } | ||
|
|
||
| /// Detects if the format string or an argument has its span set by a proc macro to something inside |
|
@bors r+ |
|
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
changelog: none
Part of #10233
Empty precision specifiers are no longer linted as the span for that isn't present in
FormatOptionsThat could be fixed later with some hackery or a change upstream
r? @flip1995