about summary refs log tree commit diff
path: root/src/libsyntax_ext
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2018-07-11 19:50:14 +0000
committerbors <bors@rust-lang.org>2018-07-11 19:50:14 +0000
commit704af2d7e1474ba60a0b70a5aa78e29905abb4e1 (patch)
treeecccdd7baa7a2aea62eb9fc8f40ffb877ce71903 /src/libsyntax_ext
parentd573fe17786b9c2f5a766498d411d54eee5fa19f (diff)
parenta0b288e1b85424bb3a5b1f89fc904d431d904a1c (diff)
downloadrust-704af2d7e1474ba60a0b70a5aa78e29905abb4e1.tar.gz
rust-704af2d7e1474ba60a0b70a5aa78e29905abb4e1.zip
Auto merge of #52268 - Mark-Simulacrum:rollup, r=Mark-Simulacrum
Rollup of 14 pull requests

Successful merges:

 - #51614 (Correct suggestion for println)
 - #51952 ( hygiene: Decouple transparencies from expansion IDs)
 - #52193 (step_by: leave time of item skip unspecified)
 - #52207 (improve error message shown for unsafe operations)
 - #52223 (Deny bare trait objects in in src/liballoc)
 - #52224 (Deny bare trait objects in in src/libsyntax)
 - #52239 (Remove sync::Once::call_once 'static bound)
 - #52247 (Deny bare trait objects in in src/librustc)
 - #52248 (Deny bare trait objects in in src/librustc_allocator)
 - #52252 (Deny bare trait objects in in src/librustc_codegen_llvm)
 - #52253 (Deny bare trait objects in in src/librustc_data_structures)
 - #52254 (Deny bare trait objects in in src/librustc_metadata)
 - #52261 (Deny bare trait objects in in src/libpanic_unwind)
 - #52265 (Deny bare trait objects in in src/librustc_codegen_utils)

Failed merges:

r? @ghost
Diffstat (limited to 'src/libsyntax_ext')
-rw-r--r--src/libsyntax_ext/concat.rs63
1 files changed, 34 insertions, 29 deletions
diff --git a/src/libsyntax_ext/concat.rs b/src/libsyntax_ext/concat.rs
index 6c085528a66..1c6f0089503 100644
--- a/src/libsyntax_ext/concat.rs
+++ b/src/libsyntax_ext/concat.rs
@@ -12,15 +12,16 @@ use syntax::ast;
 use syntax::ext::base;
 use syntax::ext::build::AstBuilder;
 use syntax::symbol::Symbol;
-use syntax_pos;
 use syntax::tokenstream;
+use syntax_pos;
 
 use std::string::String;
 
-pub fn expand_syntax_ext(cx: &mut base::ExtCtxt,
-                         sp: syntax_pos::Span,
-                         tts: &[tokenstream::TokenTree])
-                         -> Box<base::MacResult + 'static> {
+pub fn expand_syntax_ext(
+    cx: &mut base::ExtCtxt,
+    sp: syntax_pos::Span,
+    tts: &[tokenstream::TokenTree],
+) -> Box<base::MacResult + 'static> {
     let es = match base::get_exprs_from_tts(cx, sp, tts) {
         Some(e) => e,
         None => return base::DummyResult::expr(sp),
@@ -28,32 +29,36 @@ pub fn expand_syntax_ext(cx: &mut base::ExtCtxt,
     let mut accumulator = String::new();
     for e in es {
         match e.node {
-            ast::ExprKind::Lit(ref lit) => {
-                match lit.node {
-                    ast::LitKind::Str(ref s, _) |
-                    ast::LitKind::Float(ref s, _) |
-                    ast::LitKind::FloatUnsuffixed(ref s) => {
-                        accumulator.push_str(&s.as_str());
-                    }
-                    ast::LitKind::Char(c) => {
-                        accumulator.push(c);
-                    }
-                    ast::LitKind::Int(i, ast::LitIntType::Unsigned(_)) |
-                    ast::LitKind::Int(i, ast::LitIntType::Signed(_)) |
-                    ast::LitKind::Int(i, ast::LitIntType::Unsuffixed) => {
-                        accumulator.push_str(&format!("{}", i));
-                    }
-                    ast::LitKind::Bool(b) => {
-                        accumulator.push_str(&format!("{}", b));
-                    }
-                    ast::LitKind::Byte(..) |
-                    ast::LitKind::ByteStr(..) => {
-                        cx.span_err(e.span, "cannot concatenate a byte string literal");
-                    }
+            ast::ExprKind::Lit(ref lit) => match lit.node {
+                ast::LitKind::Str(ref s, _)
+                | ast::LitKind::Float(ref s, _)
+                | ast::LitKind::FloatUnsuffixed(ref s) => {
+                    accumulator.push_str(&s.as_str());
                 }
-            }
+                ast::LitKind::Char(c) => {
+                    accumulator.push(c);
+                }
+                ast::LitKind::Int(i, ast::LitIntType::Unsigned(_))
+                | ast::LitKind::Int(i, ast::LitIntType::Signed(_))
+                | ast::LitKind::Int(i, ast::LitIntType::Unsuffixed) => {
+                    accumulator.push_str(&format!("{}", i));
+                }
+                ast::LitKind::Bool(b) => {
+                    accumulator.push_str(&format!("{}", b));
+                }
+                ast::LitKind::Byte(..) | ast::LitKind::ByteStr(..) => {
+                    cx.span_err(e.span, "cannot concatenate a byte string literal");
+                }
+            },
             _ => {
-                cx.span_err(e.span, "expected a literal");
+                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();
             }
         }
     }