diff options
| author | bors <bors@rust-lang.org> | 2014-09-01 16:45:59 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2014-09-01 16:45:59 +0000 |
| commit | 3768ef477e2013fb565ce3c4b74c9af2a9841b21 (patch) | |
| tree | 1a1a67ecbacd0cd410aeef3d9d8dc441b05a0e85 /src/libsyntax | |
| parent | eb7589a1881e7a649cb7c23e973f01a60aac78b3 (diff) | |
| parent | a9c3109a6a79430729154498019b37591da5989a (diff) | |
| download | rust-3768ef477e2013fb565ce3c4b74c9af2a9841b21.tar.gz rust-3768ef477e2013fb565ce3c4b74c9af2a9841b21.zip | |
auto merge of #16891 : eddyb/rust/patlit-from-expr-macros, r=kballard
Enables any macros using `MacExpr` to be treated as patterns when they produce a literal in the form `ExprLit` (e.g. `stringify!` or `line!`). Fixes #16876.
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/ext/base.rs | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index b3b66a6a604..d59b20dfc4c 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -154,6 +154,16 @@ impl MacResult for MacExpr { fn make_expr(&self) -> Option<Gc<ast::Expr>> { Some(self.e) } + fn make_pat(&self) -> Option<Gc<ast::Pat>> { + match self.e.node { + ast::ExprLit(_) => Some(box(GC) ast::Pat { + id: ast::DUMMY_NODE_ID, + node: ast::PatLit(self.e), + span: self.e.span + }), + _ => None + } + } } /// A convenience type for macros that return a single pattern. pub struct MacPat { |
