about summary refs log tree commit diff
path: root/clippy_lints/src/format.rs
diff options
context:
space:
mode:
authorJason Newcomb <jsnewcomb@pm.me>2022-08-31 09:24:45 -0400
committerJason Newcomb <jsnewcomb@pm.me>2022-08-31 09:24:45 -0400
commitfb41bfa77405233da5ddd324091380e018e3d956 (patch)
tree5542e247fac4af781cad93f553a8e6bbc4b8a842 /clippy_lints/src/format.rs
parent7ba06ec9c5fb165e717f6d732ce50771733f31c4 (diff)
downloadrust-fb41bfa77405233da5ddd324091380e018e3d956.tar.gz
rust-fb41bfa77405233da5ddd324091380e018e3d956.zip
Merge commit 'f51aade56f93175dde89177a92e3669ebd8e7592' into clippyup
Diffstat (limited to 'clippy_lints/src/format.rs')
-rw-r--r--clippy_lints/src/format.rs24
1 files changed, 11 insertions, 13 deletions
diff --git a/clippy_lints/src/format.rs b/clippy_lints/src/format.rs
index 925a8cb8dee..0c5851cdbed 100644
--- a/clippy_lints/src/format.rs
+++ b/clippy_lints/src/format.rs
@@ -1,6 +1,6 @@
 use clippy_utils::diagnostics::span_lint_and_sugg;
 use clippy_utils::macros::{root_macro_call_first_node, FormatArgsExpn};
-use clippy_utils::source::{snippet_opt, snippet_with_applicability};
+use clippy_utils::source::snippet_with_applicability;
 use clippy_utils::sugg::Sugg;
 use if_chain::if_chain;
 use rustc_errors::Applicability;
@@ -56,29 +56,27 @@ impl<'tcx> LateLintPass<'tcx> for UselessFormat {
         };
 
         let mut applicability = Applicability::MachineApplicable;
-        if format_args.value_args.is_empty() {
-            match *format_args.format_string_parts {
+        if format_args.args.is_empty() {
+            match *format_args.format_string.parts {
                 [] => span_useless_format_empty(cx, call_site, "String::new()".to_owned(), applicability),
                 [_] => {
-                    if let Some(s_src) = snippet_opt(cx, format_args.format_string_span) {
-                        // Simulate macro expansion, converting {{ and }} to { and }.
-                        let s_expand = s_src.replace("{{", "{").replace("}}", "}");
-                        let sugg = format!("{}.to_string()", s_expand);
-                        span_useless_format(cx, call_site, sugg, applicability);
-                    }
+                    // Simulate macro expansion, converting {{ and }} to { and }.
+                    let s_expand = format_args.format_string.snippet.replace("{{", "{").replace("}}", "}");
+                    let sugg = format!("{}.to_string()", s_expand);
+                    span_useless_format(cx, call_site, sugg, applicability);
                 },
                 [..] => {},
             }
-        } else if let [value] = *format_args.value_args {
+        } else if let [arg] = &*format_args.args {
+            let value = arg.param.value;
             if_chain! {
-                if format_args.format_string_parts == [kw::Empty];
+                if format_args.format_string.parts == [kw::Empty];
                 if match cx.typeck_results().expr_ty(value).peel_refs().kind() {
                     ty::Adt(adt, _) => cx.tcx.is_diagnostic_item(sym::String, adt.did()),
                     ty::Str => true,
                     _ => false,
                 };
-                if let Some(args) = format_args.args();
-                if args.iter().all(|arg| arg.format_trait == sym::Display && !arg.has_string_formatting());
+                if !arg.format.has_string_formatting();
                 then {
                     let is_new_string = match value.kind {
                         ExprKind::Binary(..) => true,