addressed review feedback

This commit is contained in:
Yuri Astrakhan 2022-11-27 10:34:13 -05:00
parent 7a2d92e1f2
commit ab576afc18
8 changed files with 18 additions and 1270 deletions

View file

@ -321,13 +321,6 @@ fn check_uninlined_args(
Applicability::MachineApplicable,
if multiline_fix { CompletelyHidden } else { ShowCode },
);
if ignore_mixed {
// Improve lint config discoverability
diag.note_once(
"this lint can also fix mixed format arg inlining if \
`allow-mixed-uninlined-format-args = false` is set in the `clippy.toml` file",
);
}
},
);
}

View file

@ -1,32 +0,0 @@
// compile-flags: --emit=link
// no-prefer-dynamic
#![crate_type = "proc-macro"]
extern crate proc_macro;
use proc_macro::{token_stream::IntoIter, Group, Span, TokenStream, TokenTree};
#[proc_macro]
pub fn with_span(input: TokenStream) -> TokenStream {
let mut iter = input.into_iter();
let span = iter.next().unwrap().span();
let mut res = TokenStream::new();
write_with_span(span, iter, &mut res);
res
}
fn write_with_span(s: Span, input: IntoIter, out: &mut TokenStream) {
for mut tt in input {
if let TokenTree::Group(g) = tt {
let mut stream = TokenStream::new();
write_with_span(s, g.stream().into_iter(), &mut stream);
let mut group = Group::new(g.delimiter(), stream);
group.set_span(s);
out.extend([TokenTree::Group(group)]);
} else {
tt.set_span(s);
out.extend([tt]);
}
}
}

View file

@ -1,177 +1,14 @@
// aux-build:proc_macro_with_span.rs
// run-rustfix
#![feature(custom_inner_attributes)]
#![warn(clippy::uninlined_format_args)]
#![allow(named_arguments_used_positionally, unused_imports, unused_macros, unused_variables)]
#![allow(clippy::eq_op, clippy::format_in_format_args, clippy::print_literal)]
extern crate proc_macro_with_span;
use proc_macro_with_span::with_span;
macro_rules! no_param_str {
() => {
"{}"
};
}
macro_rules! my_println {
($($args:tt),*) => {{
println!($($args),*)
}};
}
macro_rules! my_println_args {
($($args:tt),*) => {{
println!("foo: {}", format_args!($($args),*))
}};
}
fn tester(fn_arg: i32) {
fn main() {
let local_i32 = 1;
let local_f64 = 2.0;
let local_opt: Option<i32> = Some(3);
let width = 4;
let prec = 5;
let val = 6;
// make sure this file hasn't been corrupted with tabs converted to spaces
// let _ = ' '; // <- this is a single tab character
let _: &[u8; 3] = b" "; // <- <tab><space><tab>
println!("val='{local_i32}'");
println!("val='{local_i32}'"); // 3 spaces
println!("val='{local_i32}'"); // tab
println!("val='{local_i32}'"); // space+tab
println!("val='{local_i32}'"); // tab+space
println!(
"val='{local_i32}'"
);
println!("{local_i32}");
println!("{fn_arg}");
println!("{local_i32:?}");
println!("{local_i32:#?}");
println!("{local_i32:4}");
println!("{local_i32:04}");
println!("{local_i32:<3}");
println!("{local_i32:#010x}");
println!("{local_f64:.1}");
println!("Hello {} is {local_f64:.local_i32$}", "x");
println!("Hello x is {local_f64:.local_i32$}");
println!("Hello {local_i32} is {local_f64:.*}", 5);
println!("Hello {local_i32} is {local_f64:.*}", 5);
println!("{local_i32} {local_f64}");
println!("{local_i32}, {}", local_opt.unwrap());
println!("{val}");
println!("{val}");
println!("{} {1}", local_i32, 42);
println!("val='{local_i32}'");
println!("val='{local_i32}'");
println!("val='{local_i32}'");
println!("val='{fn_arg}'");
println!("{local_i32}");
println!("{local_i32:?}");
println!("{local_i32:#?}");
println!("{local_i32:04}");
println!("{local_i32:<3}");
println!("{local_i32:#010x}");
println!("{local_f64:.1}");
println!("{local_i32} {local_i32}");
println!("{local_f64} {local_i32} {local_i32} {local_f64}");
println!("{local_i32} {local_f64}");
println!("{local_f64} {local_i32}");
println!("{local_f64} {local_i32} {local_f64} {local_i32}");
println!("{1} {0}", "str", local_i32);
println!("{local_i32}");
println!("{local_i32:width$}");
println!("{local_i32:width$}");
println!("{local_i32:.prec$}");
println!("{local_i32:.prec$}");
println!("{val:val$}");
println!("{val:val$}");
println!("{val:val$.val$}");
println!("{val:val$.val$}");
println!("{val:val$.val$}");
println!("{val:val$.val$}");
println!("{val:val$.val$}");
println!("{val:val$.val$}");
println!("{val:val$.val$}");
println!("{val:val$.val$}");
println!("{width:width$}");
println!("{local_i32:width$}");
println!("{width:width$}");
println!("{local_i32:width$}");
println!("{prec:.prec$}");
println!("{local_i32:.prec$}");
println!("{prec:.prec$}");
println!("{local_i32:.prec$}");
println!("{width:width$.prec$}");
println!("{width:width$.prec$}");
println!("{local_f64:width$.prec$}");
println!("{local_f64:width$.prec$} {local_f64} {width} {prec}");
println!(
"{local_i32:width$.prec$} {local_i32:prec$.width$} {width:local_i32$.prec$} {width:prec$.local_i32$} {prec:local_i32$.width$} {prec:width$.local_i32$}",
);
println!(
"{0:1$.2$} {0:2$.1$} {1:0$.2$} {1:2$.0$} {2:0$.1$} {2:1$.0$} {3}",
local_i32,
width,
prec,
1 + 2
);
println!("Width = {local_i32}, value with width = {local_f64:local_i32$}");
println!("{local_i32:width$.prec$}");
println!("{width:width$.prec$}");
println!("{}", format!("{local_i32}"));
my_println!("{}", local_i32);
my_println_args!("{}", local_i32);
// these should NOT be modified by the lint
println!(concat!("nope ", "{}"), local_i32);
println!("val='{local_i32}'");
println!("val='{local_i32 }'");
println!("val='{local_i32 }'"); // with tab
println!("val='{local_i32\n}'");
println!("{}", usize::MAX);
println!("{}", local_opt.unwrap());
println!(
"val='{local_i32
}'"
);
println!(no_param_str!(), local_i32);
println!(
"{val}",
);
println!("{val}");
println!(with_span!("{0} {1}" "{1} {0}"), local_i32, local_f64);
println!("{}", with_span!(span val));
if local_i32 > 0 {
panic!("p1 {local_i32}");
}
if local_i32 > 0 {
panic!("p2 {local_i32}");
}
if local_i32 > 0 {
panic!("p3 {local_i32}");
}
if local_i32 > 0 {
panic!("p4 {local_i32}");
}
}
fn main() {
tester(42);
}
fn _under_msrv() {
#![clippy::msrv = "1.57"]
let local_i32 = 1;
println!("don't expand='{}'", local_i32);
}
fn _meets_msrv() {
#![clippy::msrv = "1.58"]
let local_i32 = 1;
println!("expand='{local_i32}'");
}

View file

@ -1,182 +1,14 @@
// aux-build:proc_macro_with_span.rs
// run-rustfix
#![feature(custom_inner_attributes)]
#![warn(clippy::uninlined_format_args)]
#![allow(named_arguments_used_positionally, unused_imports, unused_macros, unused_variables)]
#![allow(clippy::eq_op, clippy::format_in_format_args, clippy::print_literal)]
extern crate proc_macro_with_span;
use proc_macro_with_span::with_span;
macro_rules! no_param_str {
() => {
"{}"
};
}
macro_rules! my_println {
($($args:tt),*) => {{
println!($($args),*)
}};
}
macro_rules! my_println_args {
($($args:tt),*) => {{
println!("foo: {}", format_args!($($args),*))
}};
}
fn tester(fn_arg: i32) {
fn main() {
let local_i32 = 1;
let local_f64 = 2.0;
let local_opt: Option<i32> = Some(3);
let width = 4;
let prec = 5;
let val = 6;
// make sure this file hasn't been corrupted with tabs converted to spaces
// let _ = ' '; // <- this is a single tab character
let _: &[u8; 3] = b" "; // <- <tab><space><tab>
println!("val='{}'", local_i32);
println!("val='{ }'", local_i32); // 3 spaces
println!("val='{ }'", local_i32); // tab
println!("val='{ }'", local_i32); // space+tab
println!("val='{ }'", local_i32); // tab+space
println!(
"val='{
}'",
local_i32
);
println!("{}", local_i32);
println!("{}", fn_arg);
println!("{:?}", local_i32);
println!("{:#?}", local_i32);
println!("{:4}", local_i32);
println!("{:04}", local_i32);
println!("{:<3}", local_i32);
println!("{:#010x}", local_i32);
println!("{:.1}", local_f64);
println!("Hello {} is {:.*}", "x", local_i32, local_f64);
println!("Hello {} is {:.*}", local_i32, 5, local_f64);
println!("Hello {} is {2:.*}", local_i32, 5, local_f64);
println!("{} {}", local_i32, local_f64);
println!("{}, {}", local_i32, local_opt.unwrap());
println!("{}", val);
println!("{}", v = val);
println!("{} {1}", local_i32, 42);
println!("val='{\t }'", local_i32);
println!("val='{\n }'", local_i32);
println!("val='{local_i32}'", local_i32 = local_i32);
println!("val='{local_i32}'", local_i32 = fn_arg);
println!("{0}", local_i32);
println!("{0:?}", local_i32);
println!("{0:#?}", local_i32);
println!("{0:04}", local_i32);
println!("{0:<3}", local_i32);
println!("{0:#010x}", local_i32);
println!("{0:.1}", local_f64);
println!("{0} {0}", local_i32);
println!("{1} {} {0} {}", local_i32, local_f64);
println!("{0} {1}", local_i32, local_f64);
println!("{1} {0}", local_i32, local_f64);
println!("{1} {0} {1} {0}", local_i32, local_f64);
println!("{1} {0}", "str", local_i32);
println!("{v}", v = local_i32);
println!("{local_i32:0$}", width);
println!("{local_i32:w$}", w = width);
println!("{local_i32:.0$}", prec);
println!("{local_i32:.p$}", p = prec);
println!("{:0$}", v = val);
println!("{0:0$}", v = val);
println!("{:0$.0$}", v = val);
println!("{0:0$.0$}", v = val);
println!("{0:0$.v$}", v = val);
println!("{0:v$.0$}", v = val);
println!("{v:0$.0$}", v = val);
println!("{v:v$.0$}", v = val);
println!("{v:0$.v$}", v = val);
println!("{v:v$.v$}", v = val);
println!("{:0$}", width);
println!("{:1$}", local_i32, width);
println!("{:w$}", w = width);
println!("{:w$}", local_i32, w = width);
println!("{:.0$}", prec);
println!("{:.1$}", local_i32, prec);
println!("{:.p$}", p = prec);
println!("{:.p$}", local_i32, p = prec);
println!("{:0$.1$}", width, prec);
println!("{:0$.w$}", width, w = prec);
println!("{:1$.2$}", local_f64, width, prec);
println!("{:1$.2$} {0} {1} {2}", local_f64, width, prec);
println!(
"{0:1$.2$} {0:2$.1$} {1:0$.2$} {1:2$.0$} {2:0$.1$} {2:1$.0$}",
local_i32, width, prec,
);
println!(
"{0:1$.2$} {0:2$.1$} {1:0$.2$} {1:2$.0$} {2:0$.1$} {2:1$.0$} {3}",
local_i32,
width,
prec,
1 + 2
);
println!("Width = {}, value with width = {:0$}", local_i32, local_f64);
println!("{:w$.p$}", local_i32, w = width, p = prec);
println!("{:w$.p$}", w = width, p = prec);
println!("{}", format!("{}", local_i32));
my_println!("{}", local_i32);
my_println_args!("{}", local_i32);
// these should NOT be modified by the lint
println!(concat!("nope ", "{}"), local_i32);
println!("val='{local_i32}'");
println!("val='{local_i32 }'");
println!("val='{local_i32 }'"); // with tab
println!("val='{local_i32\n}'");
println!("{}", usize::MAX);
println!("{}", local_opt.unwrap());
println!(
"val='{local_i32
}'"
);
println!(no_param_str!(), local_i32);
println!(
"{}",
// comment with a comma , in it
val,
);
println!("{}", /* comment with a comma , in it */ val);
println!(with_span!("{0} {1}" "{1} {0}"), local_i32, local_f64);
println!("{}", with_span!(span val));
if local_i32 > 0 {
panic!("p1 {}", local_i32);
}
if local_i32 > 0 {
panic!("p2 {0}", local_i32);
}
if local_i32 > 0 {
panic!("p3 {local_i32}", local_i32 = local_i32);
}
if local_i32 > 0 {
panic!("p4 {local_i32}");
}
}
fn main() {
tester(42);
}
fn _under_msrv() {
#![clippy::msrv = "1.57"]
let local_i32 = 1;
println!("don't expand='{}'", local_i32);
}
fn _meets_msrv() {
#![clippy::msrv = "1.58"]
let local_i32 = 1;
println!("expand='{}'", local_i32);
}

View file

@ -1,5 +1,5 @@
error: variables can be used directly in the `format!` string
--> $DIR/uninlined_format_args.rs:41:5
--> $DIR/uninlined_format_args.rs:9:5
|
LL | println!("val='{}'", local_i32);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -11,174 +11,21 @@ LL - println!("val='{}'", local_i32);
LL + println!("val='{local_i32}'");
|
error: variables can be used directly in the `format!` string
--> $DIR/uninlined_format_args.rs:42:5
error: literal with an empty format string
--> $DIR/uninlined_format_args.rs:10:35
|
LL | println!("val='{ }'", local_i32); // 3 spaces
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | println!("Hello {} is {:.*}", "x", local_i32, local_f64);
| ^^^
|
help: change this to
= note: `-D clippy::print-literal` implied by `-D warnings`
help: try this
|
LL - println!("val='{ }'", local_i32); // 3 spaces
LL + println!("val='{local_i32}'"); // 3 spaces
LL - println!("Hello {} is {:.*}", "x", local_i32, local_f64);
LL + println!("Hello x is {:.*}", local_i32, local_f64);
|
error: variables can be used directly in the `format!` string
--> $DIR/uninlined_format_args.rs:43:5
|
LL | println!("val='{ }'", local_i32); // tab
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: change this to
|
LL - println!("val='{ }'", local_i32); // tab
LL + println!("val='{local_i32}'"); // tab
|
error: variables can be used directly in the `format!` string
--> $DIR/uninlined_format_args.rs:44:5
|
LL | println!("val='{ }'", local_i32); // space+tab
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: change this to
|
LL - println!("val='{ }'", local_i32); // space+tab
LL + println!("val='{local_i32}'"); // space+tab
|
error: variables can be used directly in the `format!` string
--> $DIR/uninlined_format_args.rs:45:5
|
LL | println!("val='{ }'", local_i32); // tab+space
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: change this to
|
LL - println!("val='{ }'", local_i32); // tab+space
LL + println!("val='{local_i32}'"); // tab+space
|
error: variables can be used directly in the `format!` string
--> $DIR/uninlined_format_args.rs:46:5
|
LL | / println!(
LL | | "val='{
LL | | }'",
LL | | local_i32
LL | | );
| |_____^
error: variables can be used directly in the `format!` string
--> $DIR/uninlined_format_args.rs:51:5
|
LL | println!("{}", local_i32);
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: change this to
|
LL - println!("{}", local_i32);
LL + println!("{local_i32}");
|
error: variables can be used directly in the `format!` string
--> $DIR/uninlined_format_args.rs:52:5
|
LL | println!("{}", fn_arg);
| ^^^^^^^^^^^^^^^^^^^^^^
|
help: change this to
|
LL - println!("{}", fn_arg);
LL + println!("{fn_arg}");
|
error: variables can be used directly in the `format!` string
--> $DIR/uninlined_format_args.rs:53:5
|
LL | println!("{:?}", local_i32);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: change this to
|
LL - println!("{:?}", local_i32);
LL + println!("{local_i32:?}");
|
error: variables can be used directly in the `format!` string
--> $DIR/uninlined_format_args.rs:54:5
|
LL | println!("{:#?}", local_i32);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: change this to
|
LL - println!("{:#?}", local_i32);
LL + println!("{local_i32:#?}");
|
error: variables can be used directly in the `format!` string
--> $DIR/uninlined_format_args.rs:55:5
|
LL | println!("{:4}", local_i32);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: change this to
|
LL - println!("{:4}", local_i32);
LL + println!("{local_i32:4}");
|
error: variables can be used directly in the `format!` string
--> $DIR/uninlined_format_args.rs:56:5
|
LL | println!("{:04}", local_i32);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: change this to
|
LL - println!("{:04}", local_i32);
LL + println!("{local_i32:04}");
|
error: variables can be used directly in the `format!` string
--> $DIR/uninlined_format_args.rs:57:5
|
LL | println!("{:<3}", local_i32);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: change this to
|
LL - println!("{:<3}", local_i32);
LL + println!("{local_i32:<3}");
|
error: variables can be used directly in the `format!` string
--> $DIR/uninlined_format_args.rs:58:5
|
LL | println!("{:#010x}", local_i32);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: change this to
|
LL - println!("{:#010x}", local_i32);
LL + println!("{local_i32:#010x}");
|
error: variables can be used directly in the `format!` string
--> $DIR/uninlined_format_args.rs:59:5
|
LL | println!("{:.1}", local_f64);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: change this to
|
LL - println!("{:.1}", local_f64);
LL + println!("{local_f64:.1}");
|
error: variables can be used directly in the `format!` string
--> $DIR/uninlined_format_args.rs:60:5
--> $DIR/uninlined_format_args.rs:10:5
|
LL | println!("Hello {} is {:.*}", "x", local_i32, local_f64);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -190,7 +37,7 @@ LL + println!("Hello {} is {local_f64:.local_i32$}", "x");
|
error: variables can be used directly in the `format!` string
--> $DIR/uninlined_format_args.rs:61:5
--> $DIR/uninlined_format_args.rs:11:5
|
LL | println!("Hello {} is {:.*}", local_i32, 5, local_f64);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -202,7 +49,7 @@ LL + println!("Hello {local_i32} is {local_f64:.*}", 5);
|
error: variables can be used directly in the `format!` string
--> $DIR/uninlined_format_args.rs:62:5
--> $DIR/uninlined_format_args.rs:12:5
|
LL | println!("Hello {} is {2:.*}", local_i32, 5, local_f64);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -214,19 +61,7 @@ LL + println!("Hello {local_i32} is {local_f64:.*}", 5);
|
error: variables can be used directly in the `format!` string
--> $DIR/uninlined_format_args.rs:63:5
|
LL | println!("{} {}", local_i32, local_f64);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: change this to
|
LL - println!("{} {}", local_i32, local_f64);
LL + println!("{local_i32} {local_f64}");
|
error: variables can be used directly in the `format!` string
--> $DIR/uninlined_format_args.rs:64:5
--> $DIR/uninlined_format_args.rs:13:5
|
LL | println!("{}, {}", local_i32, local_opt.unwrap());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -237,672 +72,5 @@ LL - println!("{}, {}", local_i32, local_opt.unwrap());
LL + println!("{local_i32}, {}", local_opt.unwrap());
|
error: variables can be used directly in the `format!` string
--> $DIR/uninlined_format_args.rs:65:5
|
LL | println!("{}", val);
| ^^^^^^^^^^^^^^^^^^^
|
help: change this to
|
LL - println!("{}", val);
LL + println!("{val}");
|
error: variables can be used directly in the `format!` string
--> $DIR/uninlined_format_args.rs:66:5
|
LL | println!("{}", v = val);
| ^^^^^^^^^^^^^^^^^^^^^^^
|
help: change this to
|
LL - println!("{}", v = val);
LL + println!("{val}");
|
error: variables can be used directly in the `format!` string
--> $DIR/uninlined_format_args.rs:68:5
|
LL | println!("val='{/t }'", local_i32);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: change this to
|
LL - println!("val='{/t }'", local_i32);
LL + println!("val='{local_i32}'");
|
error: variables can be used directly in the `format!` string
--> $DIR/uninlined_format_args.rs:69:5
|
LL | println!("val='{/n }'", local_i32);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: change this to
|
LL - println!("val='{/n }'", local_i32);
LL + println!("val='{local_i32}'");
|
error: variables can be used directly in the `format!` string
--> $DIR/uninlined_format_args.rs:70:5
|
LL | println!("val='{local_i32}'", local_i32 = local_i32);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: change this to
|
LL - println!("val='{local_i32}'", local_i32 = local_i32);
LL + println!("val='{local_i32}'");
|
error: variables can be used directly in the `format!` string
--> $DIR/uninlined_format_args.rs:71:5
|
LL | println!("val='{local_i32}'", local_i32 = fn_arg);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: change this to
|
LL - println!("val='{local_i32}'", local_i32 = fn_arg);
LL + println!("val='{fn_arg}'");
|
error: variables can be used directly in the `format!` string
--> $DIR/uninlined_format_args.rs:72:5
|
LL | println!("{0}", local_i32);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: change this to
|
LL - println!("{0}", local_i32);
LL + println!("{local_i32}");
|
error: variables can be used directly in the `format!` string
--> $DIR/uninlined_format_args.rs:73:5
|
LL | println!("{0:?}", local_i32);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: change this to
|
LL - println!("{0:?}", local_i32);
LL + println!("{local_i32:?}");
|
error: variables can be used directly in the `format!` string
--> $DIR/uninlined_format_args.rs:74:5
|
LL | println!("{0:#?}", local_i32);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: change this to
|
LL - println!("{0:#?}", local_i32);
LL + println!("{local_i32:#?}");
|
error: variables can be used directly in the `format!` string
--> $DIR/uninlined_format_args.rs:75:5
|
LL | println!("{0:04}", local_i32);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: change this to
|
LL - println!("{0:04}", local_i32);
LL + println!("{local_i32:04}");
|
error: variables can be used directly in the `format!` string
--> $DIR/uninlined_format_args.rs:76:5
|
LL | println!("{0:<3}", local_i32);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: change this to
|
LL - println!("{0:<3}", local_i32);
LL + println!("{local_i32:<3}");
|
error: variables can be used directly in the `format!` string
--> $DIR/uninlined_format_args.rs:77:5
|
LL | println!("{0:#010x}", local_i32);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: change this to
|
LL - println!("{0:#010x}", local_i32);
LL + println!("{local_i32:#010x}");
|
error: variables can be used directly in the `format!` string
--> $DIR/uninlined_format_args.rs:78:5
|
LL | println!("{0:.1}", local_f64);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: change this to
|
LL - println!("{0:.1}", local_f64);
LL + println!("{local_f64:.1}");
|
error: variables can be used directly in the `format!` string
--> $DIR/uninlined_format_args.rs:79:5
|
LL | println!("{0} {0}", local_i32);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: change this to
|
LL - println!("{0} {0}", local_i32);
LL + println!("{local_i32} {local_i32}");
|
error: variables can be used directly in the `format!` string
--> $DIR/uninlined_format_args.rs:80:5
|
LL | println!("{1} {} {0} {}", local_i32, local_f64);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: change this to
|
LL - println!("{1} {} {0} {}", local_i32, local_f64);
LL + println!("{local_f64} {local_i32} {local_i32} {local_f64}");
|
error: variables can be used directly in the `format!` string
--> $DIR/uninlined_format_args.rs:81:5
|
LL | println!("{0} {1}", local_i32, local_f64);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: change this to
|
LL - println!("{0} {1}", local_i32, local_f64);
LL + println!("{local_i32} {local_f64}");
|
error: variables can be used directly in the `format!` string
--> $DIR/uninlined_format_args.rs:82:5
|
LL | println!("{1} {0}", local_i32, local_f64);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: change this to
|
LL - println!("{1} {0}", local_i32, local_f64);
LL + println!("{local_f64} {local_i32}");
|
error: variables can be used directly in the `format!` string
--> $DIR/uninlined_format_args.rs:83:5
|
LL | println!("{1} {0} {1} {0}", local_i32, local_f64);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: change this to
|
LL - println!("{1} {0} {1} {0}", local_i32, local_f64);
LL + println!("{local_f64} {local_i32} {local_f64} {local_i32}");
|
error: variables can be used directly in the `format!` string
--> $DIR/uninlined_format_args.rs:85:5
|
LL | println!("{v}", v = local_i32);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: change this to
|
LL - println!("{v}", v = local_i32);
LL + println!("{local_i32}");
|
error: variables can be used directly in the `format!` string
--> $DIR/uninlined_format_args.rs:86:5
|
LL | println!("{local_i32:0$}", width);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: change this to
|
LL - println!("{local_i32:0$}", width);
LL + println!("{local_i32:width$}");
|
error: variables can be used directly in the `format!` string
--> $DIR/uninlined_format_args.rs:87:5
|
LL | println!("{local_i32:w$}", w = width);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: change this to
|
LL - println!("{local_i32:w$}", w = width);
LL + println!("{local_i32:width$}");
|
error: variables can be used directly in the `format!` string
--> $DIR/uninlined_format_args.rs:88:5
|
LL | println!("{local_i32:.0$}", prec);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: change this to
|
LL - println!("{local_i32:.0$}", prec);
LL + println!("{local_i32:.prec$}");
|
error: variables can be used directly in the `format!` string
--> $DIR/uninlined_format_args.rs:89:5
|
LL | println!("{local_i32:.p$}", p = prec);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: change this to
|
LL - println!("{local_i32:.p$}", p = prec);
LL + println!("{local_i32:.prec$}");
|
error: variables can be used directly in the `format!` string
--> $DIR/uninlined_format_args.rs:90:5
|
LL | println!("{:0$}", v = val);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: change this to
|
LL - println!("{:0$}", v = val);
LL + println!("{val:val$}");
|
error: variables can be used directly in the `format!` string
--> $DIR/uninlined_format_args.rs:91:5
|
LL | println!("{0:0$}", v = val);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: change this to
|
LL - println!("{0:0$}", v = val);
LL + println!("{val:val$}");
|
error: variables can be used directly in the `format!` string
--> $DIR/uninlined_format_args.rs:92:5
|
LL | println!("{:0$.0$}", v = val);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: change this to
|
LL - println!("{:0$.0$}", v = val);
LL + println!("{val:val$.val$}");
|
error: variables can be used directly in the `format!` string
--> $DIR/uninlined_format_args.rs:93:5
|
LL | println!("{0:0$.0$}", v = val);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: change this to
|
LL - println!("{0:0$.0$}", v = val);
LL + println!("{val:val$.val$}");
|
error: variables can be used directly in the `format!` string
--> $DIR/uninlined_format_args.rs:94:5
|
LL | println!("{0:0$.v$}", v = val);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: change this to
|
LL - println!("{0:0$.v$}", v = val);
LL + println!("{val:val$.val$}");
|
error: variables can be used directly in the `format!` string
--> $DIR/uninlined_format_args.rs:95:5
|
LL | println!("{0:v$.0$}", v = val);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: change this to
|
LL - println!("{0:v$.0$}", v = val);
LL + println!("{val:val$.val$}");
|
error: variables can be used directly in the `format!` string
--> $DIR/uninlined_format_args.rs:96:5
|
LL | println!("{v:0$.0$}", v = val);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: change this to
|
LL - println!("{v:0$.0$}", v = val);
LL + println!("{val:val$.val$}");
|
error: variables can be used directly in the `format!` string
--> $DIR/uninlined_format_args.rs:97:5
|
LL | println!("{v:v$.0$}", v = val);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: change this to
|
LL - println!("{v:v$.0$}", v = val);
LL + println!("{val:val$.val$}");
|
error: variables can be used directly in the `format!` string
--> $DIR/uninlined_format_args.rs:98:5
|
LL | println!("{v:0$.v$}", v = val);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: change this to
|
LL - println!("{v:0$.v$}", v = val);
LL + println!("{val:val$.val$}");
|
error: variables can be used directly in the `format!` string
--> $DIR/uninlined_format_args.rs:99:5
|
LL | println!("{v:v$.v$}", v = val);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: change this to
|
LL - println!("{v:v$.v$}", v = val);
LL + println!("{val:val$.val$}");
|
error: variables can be used directly in the `format!` string
--> $DIR/uninlined_format_args.rs:100:5
|
LL | println!("{:0$}", width);
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
help: change this to
|
LL - println!("{:0$}", width);
LL + println!("{width:width$}");
|
error: variables can be used directly in the `format!` string
--> $DIR/uninlined_format_args.rs:101:5
|
LL | println!("{:1$}", local_i32, width);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: change this to
|
LL - println!("{:1$}", local_i32, width);
LL + println!("{local_i32:width$}");
|
error: variables can be used directly in the `format!` string
--> $DIR/uninlined_format_args.rs:102:5
|
LL | println!("{:w$}", w = width);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: change this to
|
LL - println!("{:w$}", w = width);
LL + println!("{width:width$}");
|
error: variables can be used directly in the `format!` string
--> $DIR/uninlined_format_args.rs:103:5
|
LL | println!("{:w$}", local_i32, w = width);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: change this to
|
LL - println!("{:w$}", local_i32, w = width);
LL + println!("{local_i32:width$}");
|
error: variables can be used directly in the `format!` string
--> $DIR/uninlined_format_args.rs:104:5
|
LL | println!("{:.0$}", prec);
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
help: change this to
|
LL - println!("{:.0$}", prec);
LL + println!("{prec:.prec$}");
|
error: variables can be used directly in the `format!` string
--> $DIR/uninlined_format_args.rs:105:5
|
LL | println!("{:.1$}", local_i32, prec);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: change this to
|
LL - println!("{:.1$}", local_i32, prec);
LL + println!("{local_i32:.prec$}");
|
error: variables can be used directly in the `format!` string
--> $DIR/uninlined_format_args.rs:106:5
|
LL | println!("{:.p$}", p = prec);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: change this to
|
LL - println!("{:.p$}", p = prec);
LL + println!("{prec:.prec$}");
|
error: variables can be used directly in the `format!` string
--> $DIR/uninlined_format_args.rs:107:5
|
LL | println!("{:.p$}", local_i32, p = prec);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: change this to
|
LL - println!("{:.p$}", local_i32, p = prec);
LL + println!("{local_i32:.prec$}");
|
error: variables can be used directly in the `format!` string
--> $DIR/uninlined_format_args.rs:108:5
|
LL | println!("{:0$.1$}", width, prec);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: change this to
|
LL - println!("{:0$.1$}", width, prec);
LL + println!("{width:width$.prec$}");
|
error: variables can be used directly in the `format!` string
--> $DIR/uninlined_format_args.rs:109:5
|
LL | println!("{:0$.w$}", width, w = prec);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: change this to
|
LL - println!("{:0$.w$}", width, w = prec);
LL + println!("{width:width$.prec$}");
|
error: variables can be used directly in the `format!` string
--> $DIR/uninlined_format_args.rs:110:5
|
LL | println!("{:1$.2$}", local_f64, width, prec);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: change this to
|
LL - println!("{:1$.2$}", local_f64, width, prec);
LL + println!("{local_f64:width$.prec$}");
|
error: variables can be used directly in the `format!` string
--> $DIR/uninlined_format_args.rs:111:5
|
LL | println!("{:1$.2$} {0} {1} {2}", local_f64, width, prec);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: change this to
|
LL - println!("{:1$.2$} {0} {1} {2}", local_f64, width, prec);
LL + println!("{local_f64:width$.prec$} {local_f64} {width} {prec}");
|
error: variables can be used directly in the `format!` string
--> $DIR/uninlined_format_args.rs:112:5
|
LL | / println!(
LL | | "{0:1$.2$} {0:2$.1$} {1:0$.2$} {1:2$.0$} {2:0$.1$} {2:1$.0$}",
LL | | local_i32, width, prec,
LL | | );
| |_____^
error: variables can be used directly in the `format!` string
--> $DIR/uninlined_format_args.rs:123:5
|
LL | println!("Width = {}, value with width = {:0$}", local_i32, local_f64);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: change this to
|
LL - println!("Width = {}, value with width = {:0$}", local_i32, local_f64);
LL + println!("Width = {local_i32}, value with width = {local_f64:local_i32$}");
|
error: variables can be used directly in the `format!` string
--> $DIR/uninlined_format_args.rs:124:5
|
LL | println!("{:w$.p$}", local_i32, w = width, p = prec);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: change this to
|
LL - println!("{:w$.p$}", local_i32, w = width, p = prec);
LL + println!("{local_i32:width$.prec$}");
|
error: variables can be used directly in the `format!` string
--> $DIR/uninlined_format_args.rs:125:5
|
LL | println!("{:w$.p$}", w = width, p = prec);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: change this to
|
LL - println!("{:w$.p$}", w = width, p = prec);
LL + println!("{width:width$.prec$}");
|
error: variables can be used directly in the `format!` string
--> $DIR/uninlined_format_args.rs:126:20
|
LL | println!("{}", format!("{}", local_i32));
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
help: change this to
|
LL - println!("{}", format!("{}", local_i32));
LL + println!("{}", format!("{local_i32}"));
|
error: variables can be used directly in the `format!` string
--> $DIR/uninlined_format_args.rs:144:5
|
LL | / println!(
LL | | "{}",
LL | | // comment with a comma , in it
LL | | val,
LL | | );
| |_____^
error: variables can be used directly in the `format!` string
--> $DIR/uninlined_format_args.rs:149:5
|
LL | println!("{}", /* comment with a comma , in it */ val);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: change this to
|
LL - println!("{}", /* comment with a comma , in it */ val);
LL + println!("{val}");
|
error: variables can be used directly in the `format!` string
--> $DIR/uninlined_format_args.rs:155:9
|
LL | panic!("p1 {}", local_i32);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: change this to
|
LL - panic!("p1 {}", local_i32);
LL + panic!("p1 {local_i32}");
|
error: variables can be used directly in the `format!` string
--> $DIR/uninlined_format_args.rs:158:9
|
LL | panic!("p2 {0}", local_i32);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: change this to
|
LL - panic!("p2 {0}", local_i32);
LL + panic!("p2 {local_i32}");
|
error: variables can be used directly in the `format!` string
--> $DIR/uninlined_format_args.rs:161:9
|
LL | panic!("p3 {local_i32}", local_i32 = local_i32);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: change this to
|
LL - panic!("p3 {local_i32}", local_i32 = local_i32);
LL + panic!("p3 {local_i32}");
|
error: variables can be used directly in the `format!` string
--> $DIR/uninlined_format_args.rs:181:5
|
LL | println!("expand='{}'", local_i32);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: change this to
|
LL - println!("expand='{}'", local_i32);
LL + println!("expand='{local_i32}'");
|
error: aborting due to 76 previous errors
error: aborting due to 6 previous errors

View file

@ -177,42 +177,6 @@ LL - println!("{:.1}", local_f64);
LL + println!("{local_f64:.1}");
|
error: variables can be used directly in the `format!` string
--> $DIR/uninlined_format_args.rs:59:5
|
LL | println!("Hello {} is {:.*}", "x", local_i32, local_f64);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: change this to
|
LL - println!("Hello {} is {:.*}", "x", local_i32, local_f64);
LL + println!("Hello {} is {local_f64:.local_i32$}", "x");
|
error: variables can be used directly in the `format!` string
--> $DIR/uninlined_format_args.rs:60:5
|
LL | println!("Hello {} is {:.*}", local_i32, 5, local_f64);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: change this to
|
LL - println!("Hello {} is {:.*}", local_i32, 5, local_f64);
LL + println!("Hello {local_i32} is {local_f64:.*}", 5);
|
error: variables can be used directly in the `format!` string
--> $DIR/uninlined_format_args.rs:61:5
|
LL | println!("Hello {} is {2:.*}", local_i32, 5, local_f64);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: change this to
|
LL - println!("Hello {} is {2:.*}", local_i32, 5, local_f64);
LL + println!("Hello {local_i32} is {local_f64:.*}", 5);
|
error: variables can be used directly in the `format!` string
--> $DIR/uninlined_format_args.rs:62:5
|
@ -225,18 +189,6 @@ LL - println!("{} {}", local_i32, local_f64);
LL + println!("{local_i32} {local_f64}");
|
error: variables can be used directly in the `format!` string
--> $DIR/uninlined_format_args.rs:63:5
|
LL | println!("{}, {}", local_i32, local_opt.unwrap());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: change this to
|
LL - println!("{}, {}", local_i32, local_opt.unwrap());
LL + println!("{local_i32}, {}", local_opt.unwrap());
|
error: variables can be used directly in the `format!` string
--> $DIR/uninlined_format_args.rs:64:5
|
@ -904,5 +856,5 @@ LL - println!("expand='{}'", local_i32);
LL + println!("expand='{local_i32}'");
|
error: aborting due to 76 previous errors
error: aborting due to 72 previous errors

View file

@ -4,7 +4,6 @@ error: variables can be used directly in the `format!` string
LL | println!("val='{}'", var);
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this lint can also fix mixed format arg inlining if `allow-mixed-uninlined-format-args = false` is set in the `clippy.toml` file
= note: `-D clippy::uninlined-format-args` implied by `-D warnings`
help: change this to
|

View file

@ -4,7 +4,6 @@ error: variables can be used directly in the `format!` string
LL | println!("val='{}'", var);
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this lint can also fix mixed format arg inlining if `allow-mixed-uninlined-format-args = false` is set in the `clippy.toml` file
= note: `-D clippy::uninlined-format-args` implied by `-D warnings`
help: change this to
|