about summary refs log tree commit diff
path: root/src/libsyntax_ext/concat.rs
diff options
context:
space:
mode:
authorEsteban Küber <esteban@kuber.com.ar>2018-07-14 20:50:30 -0700
committerEsteban Küber <esteban@commure.com>2018-07-19 23:18:07 -0700
commitf53c145ef18db6543e8e5420e172e04b6054db2e (patch)
tree9de9b0c1f029e7dfac14b0ab50181868f46bd9df /src/libsyntax_ext/concat.rs
parentbc14d71622378cf942a834e7c2b5358b9901f775 (diff)
downloadrust-f53c145ef18db6543e8e5420e172e04b6054db2e.tar.gz
rust-f53c145ef18db6543e8e5420e172e04b6054db2e.zip
Improve suggestion for missing fmt str in println
Avoid using `concat!(fmt, "\n")` to improve the diagnostics being
emitted when the first `println!()` argument isn't a formatting string
literal.
Diffstat (limited to 'src/libsyntax_ext/concat.rs')
-rw-r--r--src/libsyntax_ext/concat.rs15
1 files changed, 7 insertions, 8 deletions
diff --git a/src/libsyntax_ext/concat.rs b/src/libsyntax_ext/concat.rs
index 69b4a83764e..d58f4ce17e2 100644
--- a/src/libsyntax_ext/concat.rs
+++ b/src/libsyntax_ext/concat.rs
@@ -27,6 +27,7 @@ pub fn expand_syntax_ext(
         None => return base::DummyResult::expr(sp),
     };
     let mut accumulator = String::new();
+    let mut missing_literal = vec![];
     for e in es {
         match e.node {
             ast::ExprKind::Lit(ref lit) => match lit.node {
@@ -51,17 +52,15 @@ pub fn expand_syntax_ext(
                 }
             },
             _ => {
-                let mut err = cx.struct_span_err(e.span, "expected a literal");
-                let snippet = cx.codemap().span_to_snippet(e.span).unwrap();
-                err.span_suggestion(
-                    e.span,
-                    "you might be missing a string literal to format with",
-                    format!("\"{{}}\", {}", snippet),
-                );
-                err.emit();
+                missing_literal.push(e.span);
             }
         }
     }
+    if missing_literal.len() > 0 {
+        let mut err = cx.struct_span_err(missing_literal, "expected a literal");
+        err.note("only `&str` literals can be passed to `concat!()`");
+        err.emit();
+    }
     let sp = sp.apply_mark(cx.current_expansion.mark);
     base::MacEager::expr(cx.expr_str(sp, Symbol::intern(&accumulator)))
 }