about summary refs log tree commit diff
diff options
context:
space:
mode:
authorYuri Astrakhan <YuriAstrakhan@gmail.com>2022-10-06 09:12:37 -0400
committerYuri Astrakhan <YuriAstrakhan@gmail.com>2022-10-06 09:24:57 -0400
commitcfd6c8d19d1db6f2da66415dd60a82f2c706363e (patch)
tree95e0e674704b4b5a358be29328347988681fb92f
parent45343e2bb8cbff3661586d4391e88dde90e5a276 (diff)
downloadrust-cfd6c8d19d1db6f2da66415dd60a82f2c706363e.tar.gz
rust-cfd6c8d19d1db6f2da66415dd60a82f2c706363e.zip
Add a temporary workaround for multiline formart arg inlining
per suggestion in
https://github.com/rust-lang/rust/pull/102729#discussion_r988990080

workaround for an internal crash when handling multi-line format
argument inlining.
-rw-r--r--clippy_lints/src/format_args.rs7
-rw-r--r--tests/ui/uninlined_format_args.fixed11
-rw-r--r--tests/ui/uninlined_format_args.stderr53
3 files changed, 15 insertions, 56 deletions
diff --git a/clippy_lints/src/format_args.rs b/clippy_lints/src/format_args.rs
index d4bb357fb4f..45ed21e066a 100644
--- a/clippy_lints/src/format_args.rs
+++ b/clippy_lints/src/format_args.rs
@@ -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;
@@ -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,
diff --git a/tests/ui/uninlined_format_args.fixed b/tests/ui/uninlined_format_args.fixed
index dcf10ed60a2..3ca7a401902 100644
--- a/tests/ui/uninlined_format_args.fixed
+++ b/tests/ui/uninlined_format_args.fixed
@@ -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}");
@@ -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}",
@@ -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}");
 
diff --git a/tests/ui/uninlined_format_args.stderr b/tests/ui/uninlined_format_args.stderr
index 1b4dada28da..d1a77492634 100644
--- a/tests/ui/uninlined_format_args.stderr
+++ b/tests/ui/uninlined_format_args.stderr
@@ -60,22 +60,6 @@ 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
    |
 LL |     println!("{}", local_i32);
@@ -784,25 +768,6 @@ 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
    |
 LL |     println!("Width = {}, value with width = {:0$}", local_i32, local_f64);
@@ -851,22 +816,6 @@ 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
    |
 LL |     println!("{}", /* comment with a comma , in it */ val);
@@ -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