diff options
| author | bors <bors@rust-lang.org> | 2016-05-23 07:53:43 -0700 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2016-05-23 07:53:43 -0700 |
| commit | 1ccada6cd3d187abe3b4cbbb51b07fa8c0c61cea (patch) | |
| tree | 1eed7a9c2de9fbe61c52c7744a0c116a20452880 | |
| parent | 4c6b6c200befdef9d5882a8edf135efc20de905a (diff) | |
| parent | e99279428223683bc149c12db712c9bca5b74cac (diff) | |
| download | rust-1ccada6cd3d187abe3b4cbbb51b07fa8c0c61cea.tar.gz rust-1ccada6cd3d187abe3b4cbbb51b07fa8c0c61cea.zip | |
Auto merge of #33735 - jseyfried:concat_idents_in_ty_positions, r=nrc
Allow `concat_idents!` in type positions as well as in expression positions This allows the `concat_idents!` macro in type positions as well as in expression positions. r? @nrc
| -rw-r--r-- | src/libsyntax_ext/concat_idents.rs | 50 | ||||
| -rw-r--r-- | src/test/compile-fail/syntax-extension-minor.rs | 9 |
2 files changed, 38 insertions, 21 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 }) } diff --git a/src/test/compile-fail/syntax-extension-minor.rs b/src/test/compile-fail/syntax-extension-minor.rs index 38a6834a9c4..3e36b126523 100644 --- a/src/test/compile-fail/syntax-extension-minor.rs +++ b/src/test/compile-fail/syntax-extension-minor.rs @@ -8,12 +8,15 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// this now fails (correctly, I claim) because hygiene prevents -// the assembled identifier from being a reference to the binding. -#![feature(concat_idents)] +#![feature(concat_idents, type_macros)] pub fn main() { + struct Foo; + let _: concat_idents!(F, oo) = Foo; // Test that `concat_idents!` can be used in type positions + let asdf_fdsa = "<.<".to_string(); + // this now fails (correctly, I claim) because hygiene prevents + // the assembled identifier from being a reference to the binding. assert!(concat_idents!(asd, f_f, dsa) == "<.<".to_string()); //~^ ERROR: unresolved name `asdf_fdsa` |
