1 use rustc_data_structures::thin_vec::ThinVec;
4 use syntax_expand::base::{self, *};
5 use syntax::token::{self, Token};
8 use syntax_pos::symbol::Symbol;
9 use syntax::tokenstream::{TokenTree, TokenStream};
11 pub fn expand_concat_idents<'cx>(cx: &'cx mut ExtCtxt<'_>,
14 -> Box<dyn base::MacResult + 'cx> {
16 cx.span_err(sp, "concat_idents! takes 1 or more arguments.");
17 return DummyResult::any(sp);
20 let mut res_str = String::new();
21 for (i, e) in tts.into_trees().enumerate() {
24 TokenTree::Token(Token { kind: token::Comma, .. }) => {}
26 cx.span_err(sp, "concat_idents! expecting comma.");
27 return DummyResult::any(sp);
32 TokenTree::Token(Token { kind: token::Ident(name, _), .. }) =>
33 res_str.push_str(&name.as_str()),
35 cx.span_err(sp, "concat_idents! requires ident args.");
36 return DummyResult::any(sp);
42 let ident = ast::Ident::new(Symbol::intern(&res_str), cx.with_call_site_ctxt(sp));
44 struct ConcatIdentsResult { ident: ast::Ident }
46 impl base::MacResult for ConcatIdentsResult {
47 fn make_expr(self: Box<Self>) -> Option<P<ast::Expr>> {
49 id: ast::DUMMY_NODE_ID,
50 kind: ast::ExprKind::Path(None, ast::Path::from_ident(self.ident)),
51 span: self.ident.span,
52 attrs: ThinVec::new(),
56 fn make_ty(self: Box<Self>) -> Option<P<ast::Ty>> {
58 id: ast::DUMMY_NODE_ID,
59 kind: ast::TyKind::Path(None, ast::Path::from_ident(self.ident)),
60 span: self.ident.span,
65 Box::new(ConcatIdentsResult { ident })