Skip to content

Add a temporary workaround for multiline formart arg inlining #9599

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

Merged
merged 1 commit into from
Oct 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion clippy_lints/src/format_args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use if_chain::if_chain;
use itertools::Itertools;
use rustc_errors::Applicability;
use rustc_hir::{Expr, ExprKind, HirId, QPath};
use rustc_lint::{LateContext, LateLintPass};
use rustc_lint::{LateContext, LateLintPass, LintContext};
use rustc_middle::ty::adjustment::{Adjust, Adjustment};
use rustc_middle::ty::Ty;
use rustc_semver::RustcVersion;
Expand Down Expand Up @@ -173,6 +173,11 @@ fn check_uninlined_args(cx: &LateContext<'_>, args: &FormatArgsExpn<'_>, call_si
return;
}

// Temporarily ignore multiline spans: https://github.com/rust-lang/rust/pull/102729#discussion_r988704308
if fixes.iter().any(|(span, _)| cx.sess().source_map().is_multiline(*span)) {
return;
}

span_lint_and_then(
cx,
UNINLINED_FORMAT_ARGS,
Expand Down
11 changes: 8 additions & 3 deletions tests/ui/uninlined_format_args.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ fn tester(fn_arg: i32) {
println!("val='{local_i32}'"); // space+tab
println!("val='{local_i32}'"); // tab+space
println!(
"val='{local_i32}'"
"val='{
}'",
local_i32
);
println!("{local_i32}");
println!("{fn_arg}");
Expand Down Expand Up @@ -108,7 +110,8 @@ fn tester(fn_arg: i32) {
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$}",
"{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}",
Expand Down Expand Up @@ -139,7 +142,9 @@ fn tester(fn_arg: i32) {
println!(no_param_str!(), local_i32);

println!(
"{val}",
"{}",
// comment with a comma , in it
val,
);
println!("{val}");

Expand Down
53 changes: 1 addition & 52 deletions tests/ui/uninlined_format_args.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -59,22 +59,6 @@ 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 | | );
| |_____^
|
help: change this to
|
LL - "val='{
LL + "val='{local_i32}'"
|

error: variables can be used directly in the `format!` string
--> $DIR/uninlined_format_args.rs:51:5
|
Expand Down Expand Up @@ -783,25 +767,6 @@ 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 | | );
| |_____^
|
help: change this to
|
LL ~ "{local_i32:width$.prec$} {local_i32:prec$.width$} {width:local_i32$.prec$} {width:prec$.local_i32$} {prec:local_i32$.width$} {prec:width$.local_i32$}", width, prec,
LL ~ "{0:1$.2$} {0:2$.1$} {1:0$.2$} {1:2$.0$} {2:0$.1$} {2:1$.0$}", width, prec,
LL ~ "{0:1$.2$} {0:2$.1$} {1:0$.2$} {1:2$.0$} {2:0$.1$} {2:1$.0$}", width, prec,
LL ~ "{0:1$.2$} {0:2$.1$} {1:0$.2$} {1:2$.0$} {2:0$.1$} {2:1$.0$}", width, prec,
LL ~ "{0:1$.2$} {0:2$.1$} {1:0$.2$} {1:2$.0$} {2:0$.1$} {2:1$.0$}", width, prec,
LL ~ "{0:1$.2$} {0:2$.1$} {1:0$.2$} {1:2$.0$} {2:0$.1$} {2:1$.0$}",
|

error: variables can be used directly in the `format!` string
--> $DIR/uninlined_format_args.rs:123:5
|
Expand Down Expand Up @@ -850,22 +815,6 @@ 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 | | );
| |_____^
|
help: change this to
|
LL - "{}",
LL + "{val}",
|

error: variables can be used directly in the `format!` string
--> $DIR/uninlined_format_args.rs:149:5
|
Expand All @@ -890,5 +839,5 @@ LL - println!("expand='{}'", local_i32);
LL + println!("expand='{local_i32}'");
|

error: aborting due to 73 previous errors
error: aborting due to 70 previous errors