diff options
| author | Jeffrey Seyfried <jeffrey.seyfried@gmail.com> | 2016-05-19 05:22:42 +0000 |
|---|---|---|
| committer | Jeffrey Seyfried <jeffrey.seyfried@gmail.com> | 2016-05-19 09:25:59 +0000 |
| commit | e99279428223683bc149c12db712c9bca5b74cac (patch) | |
| tree | bd8c714084af635bb5032b812d806347c26cae37 /src/libsyntax_ext | |
| parent | 088d4178522d4e9464c6beac70b14724670ee735 (diff) | |
| download | rust-e99279428223683bc149c12db712c9bca5b74cac.tar.gz rust-e99279428223683bc149c12db712c9bca5b74cac.zip | |
Allow `concat_idents!` in type positions as well as in expression positions
Diffstat (limited to 'src/libsyntax_ext')
| -rw-r--r-- | src/libsyntax_ext/concat_idents.rs | 50 |
1 files changed, 32 insertions, 18 deletions
diff --git a/src/libsyntax_ext/concat_idents.rs b/src/libsyntax_ext/concat_idents.rs index dce808756cf..3d5f32eadb3 100644 --- a/src/libsyntax_ext/concat_idents.rs +++ b/src/libsyntax_ext/concat_idents.rs @@ -52,22 +52,36 @@ pub fn expand_syntax_ext<'cx>(cx: &mut ExtCtxt, sp: Span, tts: &[TokenTree]) } let res = str_to_ident(&res_str); - let e = P(ast::Expr { - id: ast::DUMMY_NODE_ID, - node: ast::ExprKind::Path(None, - ast::Path { - span: sp, - global: false, - segments: vec!( - ast::PathSegment { - identifier: res, - parameters: ast::PathParameters::none(), - } - ) - } - ), - span: sp, - attrs: None, - }); - MacEager::expr(e) + struct Result { ident: ast::Ident, span: Span }; + + impl Result { + fn path(&self) -> ast::Path { + let segment = ast::PathSegment { + identifier: self.ident, + parameters: ast::PathParameters::none() + }; + ast::Path { span: self.span, global: false, segments: vec![segment] } + } + } + + impl base::MacResult for Result { + fn make_expr(self: Box<Self>) -> Option<P<ast::Expr>> { + Some(P(ast::Expr { + id: ast::DUMMY_NODE_ID, + node: ast::ExprKind::Path(None, self.path()), + span: self.span, + attrs: None, + })) + } + + fn make_ty(self: Box<Self>) -> Option<P<ast::Ty>> { + Some(P(ast::Ty { + id: ast::DUMMY_NODE_ID, + node: ast::TyKind::Path(None, self.path()), + span: self.span, + })) + } + } + + Box::new(Result { ident: res, span: sp }) } |
