Skip to content

Commit d0c63d6

Browse files
committedDec 22, 2014
Merge rust-lang#18814 into rollup
Approved-by:
2 parents 5aac016 + 5d7afbe commit d0c63d6

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed
 

‎src/libsyntax/ext/base.rs

+41
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,47 @@ pub trait MacResult {
166166
}
167167
}
168168

169+
/// Single type implementing MacResult with Option fields for all the types
170+
/// MacResult can return, and a Default impl that fills in None.
171+
pub struct MacGeneral {
172+
expr: Option<P<ast::Expr>>,
173+
pat: Option<P<ast::Pat>>,
174+
items: Option<SmallVector<P<ast::Item>>>,
175+
methods: Option<SmallVector<P<ast::Method>>>,
176+
def: Option<MacroDef>
177+
}
178+
impl MacGeneral {
179+
pub fn new(expr: Option<P<ast::Expr>>,
180+
pat: Option<P<ast::Pat>>,
181+
items: Option<SmallVector<P<ast::Items>>>,
182+
methods: Option<SmallVector<P<ast::Method>>>,
183+
def: Option<MacroDef>)
184+
-> Box<MacResult+'static> {
185+
box MacGeneral { expr: expr, pat: pat, items: items,
186+
methods: methods, def: def } as Box<MacResult+'static>
187+
}
188+
pub fn Default() -> Box<MacResult+'static> {
189+
box MacGeneral { expr: None, pat: None, items: None
190+
methods: None, def: None} as Box<MacResult+'static>
191+
}
192+
}
193+
impl MacResult for MacGeneral {
194+
fn make_expr(self: Box<MacGeneral>) -> Option<P<ast::Expr>> {
195+
self.expr
196+
}
197+
fn make_pat(self: Box<MacGeneral>) -> Option<P<ast::Pat>> {
198+
self.pat
199+
}
200+
fn make_items(self: Box<MacGeneral>) -> Option<SmallVector<P<ast::Item>>> {
201+
self.items
202+
}
203+
fn make_methods(self: Box<Self>) -> Option<SmallVector<P<ast::Method>>> {
204+
self.methods
205+
}
206+
fn make_def(&mut self) -> Option<MacroDef> {
207+
self.def
208+
}
209+
}
169210
/// A convenience type for macros that return a single expression.
170211
pub struct MacExpr {
171212
e: P<ast::Expr>

0 commit comments

Comments
 (0)