about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPhilipp Krones <hello@philkrones.com>2022-10-06 17:41:53 +0200
committerPhilipp Krones <hello@philkrones.com>2022-10-06 17:41:53 +0200
commit2b30ce04ac23aaea8d35502aa67079f1072cad2d (patch)
treebcbbf29e253633df6ed1385958221f842625cad0
parentdb490d0f8451083a6a40281777a517827fc4aa73 (diff)
parent8f1ebdd18bdecc621f16baaf779898cc08cc2766 (diff)
downloadrust-2b30ce04ac23aaea8d35502aa67079f1072cad2d.tar.gz
rust-2b30ce04ac23aaea8d35502aa67079f1072cad2d.zip
Merge commit '8f1ebdd18bdecc621f16baaf779898cc08cc2766' into clippyup
-rw-r--r--src/tools/clippy/clippy_lints/src/attrs.rs3
-rw-r--r--src/tools/clippy/clippy_lints/src/format_args.rs17
-rw-r--r--src/tools/clippy/clippy_utils/src/macros.rs2
-rw-r--r--src/tools/clippy/tests/ui/uninlined_format_args.fixed11
-rw-r--r--src/tools/clippy/tests/ui/uninlined_format_args.stderr53
-rw-r--r--src/tools/clippy/tests/ui/unsafe_removed_from_name.rs3
6 files changed, 20 insertions, 69 deletions
diff --git a/src/tools/clippy/clippy_lints/src/attrs.rs b/src/tools/clippy/clippy_lints/src/attrs.rs
index 5f45c69d7f9..0bd1f8b784e 100644
--- a/src/tools/clippy/clippy_lints/src/attrs.rs
+++ b/src/tools/clippy/clippy_lints/src/attrs.rs
@@ -357,7 +357,8 @@ impl<'tcx> LateLintPass<'tcx> for Attributes {
                                                     "wildcard_imports"
                                                         | "enum_glob_use"
                                                         | "redundant_pub_crate"
-                                                        | "macro_use_imports",
+                                                        | "macro_use_imports"
+                                                        | "unsafe_removed_from_name",
                                                 )
                                             })
                                         {
diff --git a/src/tools/clippy/clippy_lints/src/format_args.rs b/src/tools/clippy/clippy_lints/src/format_args.rs
index cefebc2a98a..99bef62f814 100644
--- a/src/tools/clippy/clippy_lints/src/format_args.rs
+++ b/src/tools/clippy/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,17 +173,10 @@ fn check_uninlined_args(cx: &LateContext<'_>, args: &FormatArgsExpn<'_>, call_si
         return;
     }
 
-    // FIXME: Properly ignore a rare case where the format string is wrapped in a macro.
-    // Example:  `format!(indoc!("{}"), foo);`
-    // If inlined, they will cause a compilation error:
-    //     > to avoid ambiguity, `format_args!` cannot capture variables
-    //     > when the format string is expanded from a macro
-    // @Alexendoo explanation:
-    //     > indoc! is a proc macro that is producing a string literal with its span
-    //     > set to its input it's not marked as from expansion, and since it's compatible
-    //     > tokenization wise clippy_utils::is_from_proc_macro wouldn't catch it either
-    // This might be a relatively expensive test, so do it only we are ready to replace.
-    // See more examples in tests/ui/uninlined_format_args.rs
+    // 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,
diff --git a/src/tools/clippy/clippy_utils/src/macros.rs b/src/tools/clippy/clippy_utils/src/macros.rs
index dd0ce1da657..5a63c290a31 100644
--- a/src/tools/clippy/clippy_utils/src/macros.rs
+++ b/src/tools/clippy/clippy_utils/src/macros.rs
@@ -414,7 +414,7 @@ impl FormatString {
 
 struct FormatArgsValues<'tcx> {
     /// Values passed after the format string and implicit captures. `[1, z + 2, x]` for
-    /// `format!("{x} {} {y}", 1, z + 2)`.
+    /// `format!("{x} {} {}", 1, z + 2)`.
     value_args: Vec<&'tcx Expr<'tcx>>,
     /// Maps an `rt::v1::Argument::position` or an `rt::v1::Count::Param` to its index in
     /// `value_args`
diff --git a/src/tools/clippy/tests/ui/uninlined_format_args.fixed b/src/tools/clippy/tests/ui/uninlined_format_args.fixed
index dcf10ed60a2..3ca7a401902 100644
--- a/src/tools/clippy/tests/ui/uninlined_format_args.fixed
+++ b/src/tools/clippy/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/src/tools/clippy/tests/ui/uninlined_format_args.stderr b/src/tools/clippy/tests/ui/uninlined_format_args.stderr
index 1b4dada28da..d1a77492634 100644
--- a/src/tools/clippy/tests/ui/uninlined_format_args.stderr
+++ b/src/tools/clippy/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
 
diff --git a/src/tools/clippy/tests/ui/unsafe_removed_from_name.rs b/src/tools/clippy/tests/ui/unsafe_removed_from_name.rs
index cde4e96d668..d29888ac62f 100644
--- a/src/tools/clippy/tests/ui/unsafe_removed_from_name.rs
+++ b/src/tools/clippy/tests/ui/unsafe_removed_from_name.rs
@@ -24,4 +24,7 @@ use mod_with_some_unsafe_things::Unsafe as LieAboutModSafety;
 use mod_with_some_unsafe_things::Safe as IPromiseItsSafeThisTime;
 use mod_with_some_unsafe_things::Unsafe as SuperUnsafeModThing;
 
+#[allow(clippy::unsafe_removed_from_name)]
+use mod_with_some_unsafe_things::Unsafe as SuperSafeThing;
+
 fn main() {}