1 use rustc_expand::base::{self, DummyResult};
2 use rustc_span::symbol::Symbol;
4 use syntax::tokenstream::TokenStream;
6 use std::string::String;
9 cx: &mut base::ExtCtxt<'_>,
12 ) -> Box<dyn base::MacResult + 'static> {
13 let es = match base::get_exprs_from_tts(cx, sp, tts) {
15 None => return DummyResult::any(sp),
17 let mut accumulator = String::new();
18 let mut missing_literal = vec![];
19 let mut has_errors = false;
22 ast::ExprKind::Lit(ref lit) => match lit.kind {
23 ast::LitKind::Str(ref s, _) | ast::LitKind::Float(ref s, _) => {
24 accumulator.push_str(&s.as_str());
26 ast::LitKind::Char(c) => {
29 ast::LitKind::Int(i, ast::LitIntType::Unsigned(_))
30 | ast::LitKind::Int(i, ast::LitIntType::Signed(_))
31 | ast::LitKind::Int(i, ast::LitIntType::Unsuffixed) => {
32 accumulator.push_str(&i.to_string());
34 ast::LitKind::Bool(b) => {
35 accumulator.push_str(&b.to_string());
37 ast::LitKind::Byte(..) | ast::LitKind::ByteStr(..) => {
38 cx.span_err(e.span, "cannot concatenate a byte string literal");
40 ast::LitKind::Err(_) => {
44 ast::ExprKind::Err => {
48 missing_literal.push(e.span);
52 if missing_literal.len() > 0 {
53 let mut err = cx.struct_span_err(missing_literal, "expected a literal");
54 err.note("only literals (like `\"foo\"`, `42` and `3.14`) can be passed to `concat!()`");
56 return DummyResult::any(sp);
57 } else if has_errors {
58 return DummyResult::any(sp);
60 let sp = cx.with_def_site_ctxt(sp);
61 base::MacEager::expr(cx.expr_str(sp, Symbol::intern(&accumulator)))