Skip to content

Commit 91e9b59

Browse files
committed
Merge #19019 into rollup
Approved-by:
2 parents 2276785 + f008bfd commit 91e9b59

File tree

2 files changed

+59
-14
lines changed

2 files changed

+59
-14
lines changed

src/libsyntax/ext/base.rs

+54-1
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ impl MacResult for MacPat {
204204
Some(self.p)
205205
}
206206
}
207-
/// A type for macros that return multiple items.
207+
/// A convenience type for macros that return multiple items.
208208
pub struct MacItems {
209209
items: SmallVector<P<ast::Item>>
210210
}
@@ -221,6 +221,59 @@ impl MacResult for MacItems {
221221
}
222222
}
223223

224+
/// A convenience type for macros that return a single statement
225+
pub struct MacStmt {
226+
stmt: P<ast::Stmt>,
227+
}
228+
229+
impl MacStmt {
230+
pub fn new(stmt: P<ast::Stmt>) -> MacStmt {
231+
MacStmt{ stmt: stmt }
232+
}
233+
}
234+
235+
impl MacResult for MacStmt {
236+
fn make_stmt(self: Box<MacStmt>) -> Option<P<ast::Stmt>> {
237+
Some(self.stmt)
238+
}
239+
}
240+
241+
242+
/// A convenience type for macros that return a macro def
243+
pub struct MacDef {
244+
def: Option<MacroDef>
245+
}
246+
247+
impl MacDef {
248+
pub fn new(def: MacroDef) -> MacDef {
249+
MacDef{ def: Some(def) }
250+
}
251+
}
252+
253+
impl MacResult for MacDef {
254+
fn make_def(&mut self) -> Option<MacroDef> {
255+
Some(self.def.take().expect("empty MacDef"))
256+
}
257+
}
258+
259+
/// A convenience type for macros that return methods
260+
pub struct MacMethods {
261+
methods: SmallVector<P<ast::Method>>
262+
}
263+
264+
impl MacMethods {
265+
pub fn new(methods: SmallVector<P<ast::Method>>) -> MacMethods {
266+
MacMethods{ methods: methods }
267+
}
268+
}
269+
270+
impl MacResult for MacMethods {
271+
fn make_methods(self: Box<MacMethods>) -> Option<SmallVector<P<ast::Method>>> {
272+
Some(self.methods)
273+
}
274+
}
275+
276+
224277
/// Fill-in macro expansion result, to allow compilation to continue
225278
/// after hitting errors.
226279
#[deriving(Copy)]

src/libsyntax/ext/tt/macro_rules.rs

+5-13
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use ast::{Ident, TtDelimited, TtSequence, TtToken};
1212
use ast;
1313
use codemap::{Span, DUMMY_SP};
14-
use ext::base::{ExtCtxt, MacResult, MacroDef};
14+
use ext::base::{ExtCtxt, MacDef, MacResult, MacroDef};
1515
use ext::base::{NormalTT, TTMacroExpander};
1616
use ext::tt::macro_parser::{Success, Error, Failure};
1717
use ext::tt::macro_parser::{NamedMatch, MatchedSeq, MatchedNonterminal};
@@ -129,14 +129,6 @@ impl TTMacroExpander for MacroRulesMacroExpander {
129129
}
130130
}
131131

132-
struct MacroRulesDefiner {
133-
def: Option<MacroDef>
134-
}
135-
impl MacResult for MacroRulesDefiner {
136-
fn make_def(&mut self) -> Option<MacroDef> {
137-
Some(self.def.take().expect("empty MacroRulesDefiner"))
138-
}
139-
}
140132

141133
/// Given `lhses` and `rhses`, this is the new macro we create
142134
fn generic_extension<'cx>(cx: &'cx ExtCtxt,
@@ -279,10 +271,10 @@ pub fn add_new_extension<'cx>(cx: &'cx mut ExtCtxt,
279271
rhses: rhses,
280272
};
281273

282-
box MacroRulesDefiner {
283-
def: Some(MacroDef {
274+
box MacDef::new(
275+
MacroDef {
284276
name: token::get_ident(name).to_string(),
285277
ext: NormalTT(exp, Some(sp))
286-
})
287-
} as Box<MacResult+'cx>
278+
}
279+
) as Box<MacResult+'cx>
288280
}

0 commit comments

Comments
 (0)