Skip to content

Commit 6dd0c3a

Browse files
committed
Auto merge of #9599 - nyurik:inline-crash, r=flip1995
Add a temporary workaround for multiline formart arg inlining per suggestion in #102729 (comment) workaround for an internal crash when handling multi-line format argument inlining. changelog: none (no point for changelog because it is still a new lint being introduced)
2 parents 45343e2 + cfd6c8d commit 6dd0c3a

File tree

3 files changed

+15
-56
lines changed

3 files changed

+15
-56
lines changed

clippy_lints/src/format_args.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use if_chain::if_chain;
88
use itertools::Itertools;
99
use rustc_errors::Applicability;
1010
use rustc_hir::{Expr, ExprKind, HirId, QPath};
11-
use rustc_lint::{LateContext, LateLintPass};
11+
use rustc_lint::{LateContext, LateLintPass, LintContext};
1212
use rustc_middle::ty::adjustment::{Adjust, Adjustment};
1313
use rustc_middle::ty::Ty;
1414
use rustc_semver::RustcVersion;
@@ -173,6 +173,11 @@ fn check_uninlined_args(cx: &LateContext<'_>, args: &FormatArgsExpn<'_>, call_si
173173
return;
174174
}
175175

176+
// Temporarily ignore multiline spans: https://github.com/rust-lang/rust/pull/102729#discussion_r988704308
177+
if fixes.iter().any(|(span, _)| cx.sess().source_map().is_multiline(*span)) {
178+
return;
179+
}
180+
176181
span_lint_and_then(
177182
cx,
178183
UNINLINED_FORMAT_ARGS,

tests/ui/uninlined_format_args.fixed

+8-3
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ fn tester(fn_arg: i32) {
4444
println!("val='{local_i32}'"); // space+tab
4545
println!("val='{local_i32}'"); // tab+space
4646
println!(
47-
"val='{local_i32}'"
47+
"val='{
48+
}'",
49+
local_i32
4850
);
4951
println!("{local_i32}");
5052
println!("{fn_arg}");
@@ -108,7 +110,8 @@ fn tester(fn_arg: i32) {
108110
println!("{local_f64:width$.prec$}");
109111
println!("{local_f64:width$.prec$} {local_f64} {width} {prec}");
110112
println!(
111-
"{local_i32:width$.prec$} {local_i32:prec$.width$} {width:local_i32$.prec$} {width:prec$.local_i32$} {prec:local_i32$.width$} {prec:width$.local_i32$}",
113+
"{0:1$.2$} {0:2$.1$} {1:0$.2$} {1:2$.0$} {2:0$.1$} {2:1$.0$}",
114+
local_i32, width, prec,
112115
);
113116
println!(
114117
"{0:1$.2$} {0:2$.1$} {1:0$.2$} {1:2$.0$} {2:0$.1$} {2:1$.0$} {3}",
@@ -139,7 +142,9 @@ fn tester(fn_arg: i32) {
139142
println!(no_param_str!(), local_i32);
140143

141144
println!(
142-
"{val}",
145+
"{}",
146+
// comment with a comma , in it
147+
val,
143148
);
144149
println!("{val}");
145150

tests/ui/uninlined_format_args.stderr

+1-52
Original file line numberDiff line numberDiff line change
@@ -59,22 +59,6 @@ LL - println!("val='{ }'", local_i32); // tab+space
5959
LL + println!("val='{local_i32}'"); // tab+space
6060
|
6161

62-
error: variables can be used directly in the `format!` string
63-
--> $DIR/uninlined_format_args.rs:46:5
64-
|
65-
LL | / println!(
66-
LL | | "val='{
67-
LL | | }'",
68-
LL | | local_i32
69-
LL | | );
70-
| |_____^
71-
|
72-
help: change this to
73-
|
74-
LL - "val='{
75-
LL + "val='{local_i32}'"
76-
|
77-
7862
error: variables can be used directly in the `format!` string
7963
--> $DIR/uninlined_format_args.rs:51:5
8064
|
@@ -783,25 +767,6 @@ LL - println!("{:1$.2$} {0} {1} {2}", local_f64, width, prec);
783767
LL + println!("{local_f64:width$.prec$} {local_f64} {width} {prec}");
784768
|
785769

786-
error: variables can be used directly in the `format!` string
787-
--> $DIR/uninlined_format_args.rs:112:5
788-
|
789-
LL | / println!(
790-
LL | | "{0:1$.2$} {0:2$.1$} {1:0$.2$} {1:2$.0$} {2:0$.1$} {2:1$.0$}",
791-
LL | | local_i32, width, prec,
792-
LL | | );
793-
| |_____^
794-
|
795-
help: change this to
796-
|
797-
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,
798-
LL ~ "{0:1$.2$} {0:2$.1$} {1:0$.2$} {1:2$.0$} {2:0$.1$} {2:1$.0$}", width, prec,
799-
LL ~ "{0:1$.2$} {0:2$.1$} {1:0$.2$} {1:2$.0$} {2:0$.1$} {2:1$.0$}", width, prec,
800-
LL ~ "{0:1$.2$} {0:2$.1$} {1:0$.2$} {1:2$.0$} {2:0$.1$} {2:1$.0$}", width, prec,
801-
LL ~ "{0:1$.2$} {0:2$.1$} {1:0$.2$} {1:2$.0$} {2:0$.1$} {2:1$.0$}", width, prec,
802-
LL ~ "{0:1$.2$} {0:2$.1$} {1:0$.2$} {1:2$.0$} {2:0$.1$} {2:1$.0$}",
803-
|
804-
805770
error: variables can be used directly in the `format!` string
806771
--> $DIR/uninlined_format_args.rs:123:5
807772
|
@@ -850,22 +815,6 @@ LL - println!("{}", format!("{}", local_i32));
850815
LL + println!("{}", format!("{local_i32}"));
851816
|
852817

853-
error: variables can be used directly in the `format!` string
854-
--> $DIR/uninlined_format_args.rs:144:5
855-
|
856-
LL | / println!(
857-
LL | | "{}",
858-
LL | | // comment with a comma , in it
859-
LL | | val,
860-
LL | | );
861-
| |_____^
862-
|
863-
help: change this to
864-
|
865-
LL - "{}",
866-
LL + "{val}",
867-
|
868-
869818
error: variables can be used directly in the `format!` string
870819
--> $DIR/uninlined_format_args.rs:149:5
871820
|
@@ -890,5 +839,5 @@ LL - println!("expand='{}'", local_i32);
890839
LL + println!("expand='{local_i32}'");
891840
|
892841

893-
error: aborting due to 73 previous errors
842+
error: aborting due to 70 previous errors
894843

0 commit comments

Comments
 (0)