about summary refs log tree commit diff
path: root/clippy_lints/src/format.rs
diff options
context:
space:
mode:
authorEduardo Broto <ebroto@tutanota.com>2020-10-23 22:16:59 +0200
committerEduardo Broto <ebroto@tutanota.com>2020-10-23 22:16:59 +0200
commitcdb555f4fcdb57741ffb59bd2b0e66af69ea0a85 (patch)
tree5c9c37427427a7d7b95dc090c560f006a9b92efe /clippy_lints/src/format.rs
parentfcde7683fe7ca10c83e5bc17f0969d2284affcd2 (diff)
downloadrust-cdb555f4fcdb57741ffb59bd2b0e66af69ea0a85.tar.gz
rust-cdb555f4fcdb57741ffb59bd2b0e66af69ea0a85.zip
Merge commit 'bf1c6f9871f430e284b17aa44059e0d0395e28a6' into clippyup
Diffstat (limited to 'clippy_lints/src/format.rs')
-rw-r--r--clippy_lints/src/format.rs8
1 files changed, 6 insertions, 2 deletions
diff --git a/clippy_lints/src/format.rs b/clippy_lints/src/format.rs
index d6541010bca..26da058598e 100644
--- a/clippy_lints/src/format.rs
+++ b/clippy_lints/src/format.rs
@@ -1,6 +1,6 @@
 use crate::utils::paths;
 use crate::utils::{
-    is_expn_of, is_type_diagnostic_item, last_path_segment, match_def_path, match_function_call, snippet,
+    is_expn_of, is_type_diagnostic_item, last_path_segment, match_def_path, match_function_call, snippet, snippet_opt,
     span_lint_and_then,
 };
 use if_chain::if_chain;
@@ -132,7 +132,11 @@ fn on_new_v1<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) -> Option<Strin
         then {
             // `format!("foo")` expansion contains `match () { () => [], }`
             if tup.is_empty() {
-                return Some(format!("{:?}.to_string()", s.as_str()));
+                if let Some(s_src) = snippet_opt(cx, lit.span) {
+                    // Simulate macro expansion, converting {{ and }} to { and }.
+                    let s_expand = s_src.replace("{{", "{").replace("}}", "}");
+                    return Some(format!("{}.to_string()", s_expand))
+                }
             } else if s.as_str().is_empty() {
                 return on_argumentv1_new(cx, &tup[0], arms);
             }