Skip to content

Commit b191ff3

Browse files
committed
---
yaml --- r: 233129 b: refs/heads/beta c: 9fb11fe h: refs/heads/master i: 233127: a1a6d04 v: v3
1 parent 863932d commit b191ff3

File tree

4 files changed

+59
-1
lines changed

4 files changed

+59
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ refs/tags/0.9: 36870b185fc5f5486636d4515f0e22677493f225
2323
refs/tags/0.10: ac33f2b15782272ae348dbd7b14b8257b2148b5a
2424
refs/tags/0.11.0: e1247cb1d0d681be034adb4b558b5a0c0d5720f9
2525
refs/tags/0.12.0: f0c419429ef30723ceaf6b42f9b5a2aeb5d2e2d1
26-
refs/heads/beta: edca562c87362c80e409f53d28e19617ca44646a
26+
refs/heads/beta: 9fb11fe9f21051f4f03da55f949de402e78a95d5
2727
refs/tags/1.0.0-alpha: e42bd6d93a1d3433c486200587f8f9e12590a4d7
2828
refs/heads/tmp: 370fe2786109360f7c35b8ba552b83b773dd71d6
2929
refs/tags/1.0.0-alpha.2: 4c705f6bc559886632d3871b04f58aab093bfa2f

branches/beta/src/libsyntax/ext/base.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,10 @@ pub trait MacResult {
290290
fn make_stmts(self: Box<Self>) -> Option<SmallVector<P<ast::Stmt>>> {
291291
make_stmts_default!(self)
292292
}
293+
294+
fn make_ty(self: Box<Self>) -> Option<P<ast::Ty>> {
295+
None
296+
}
293297
}
294298

295299
macro_rules! make_MacEager {
@@ -322,6 +326,7 @@ make_MacEager! {
322326
items: SmallVector<P<ast::Item>>,
323327
impl_items: SmallVector<P<ast::ImplItem>>,
324328
stmts: SmallVector<P<ast::Stmt>>,
329+
ty: P<ast::Ty>,
325330
}
326331

327332
impl MacResult for MacEager {
@@ -359,6 +364,10 @@ impl MacResult for MacEager {
359364
}
360365
None
361366
}
367+
368+
fn make_ty(self: Box<Self>) -> Option<P<ast::Ty>> {
369+
self.ty
370+
}
362371
}
363372

364373
/// Fill-in macro expansion result, to allow compilation to continue
@@ -405,6 +414,12 @@ impl DummyResult {
405414
}
406415
}
407416

417+
pub fn raw_ty(sp: Span) -> P<ast::Ty> {
418+
P(ast::Ty {
419+
id: ast:DUMMY_NODE_ID,
420+
node: ast::TyInfer,
421+
span: sp
422+
})
408423
}
409424

410425
impl MacResult for DummyResult {

branches/beta/src/libsyntax/ext/expand.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1552,6 +1552,35 @@ fn expand_and_rename_method(sig: ast::MethodSig, body: P<ast::Block>,
15521552
}, rewritten_body)
15531553
}
15541554

1555+
pub fn expand_type(t: P<ast::Ty>, fld: &mut MacroExpander) -> P<ast::Ty> {
1556+
let t = match t.node.clone() {
1557+
ast::Ty_::TyMac(mac) => {
1558+
let expanded_ty = match expand_mac_invoc(mac, t.span,
1559+
|r| r.make_ty(),
1560+
mark_ty,
1561+
fld) {
1562+
Some(ty) => ty,
1563+
None => {
1564+
return DummyResult::raw_ty(t.span);
1565+
}
1566+
};
1567+
1568+
// Keep going, outside-in.
1569+
//
1570+
let fully_expanded = fld.fold_ty(expanded_ty);
1571+
fld.cx.bt_pop();
1572+
1573+
fully_expanded.map(|t| ast::Ty {
1574+
id: ast::DUMMY_NODE_ID,
1575+
node: t.node,
1576+
span: t.span,
1577+
})
1578+
}
1579+
_ => t
1580+
};
1581+
fold::noop_fold_ty(t, fld)
1582+
}
1583+
15551584
/// A tree-folder that performs macro expansion
15561585
pub struct MacroExpander<'a, 'b:'a> {
15571586
pub cx: &'a mut ExtCtxt<'b>,
@@ -1602,6 +1631,10 @@ impl<'a, 'b> Folder for MacroExpander<'a, 'b> {
16021631
.into_iter().map(|i| i.expect_impl_item()).collect()
16031632
}
16041633

1634+
fn fold_ty(&mut self, ty: P<ast::Ty>) -> P<ast::Ty> {
1635+
expand_type(ty, self)
1636+
}
1637+
16051638
fn new_span(&mut self, span: Span) -> Span {
16061639
new_span(self.cx, span)
16071640
}
@@ -1748,6 +1781,10 @@ fn mark_impl_item(ii: P<ast::ImplItem>, m: Mrk) -> P<ast::ImplItem> {
17481781
.expect_one("marking an impl item didn't return exactly one impl item")
17491782
}
17501783

1784+
fn mark_ty(ty: P<ast::Ty>, m: Mrk) -> P<ast::Ty> {
1785+
Marker { mark: m }.fold_ty(ty)
1786+
}
1787+
17511788
/// Check that there are no macro invocations left in the AST:
17521789
pub fn check_for_macros(sess: &parse::ParseSess, krate: &ast::Crate) {
17531790
visit::walk_crate(&mut MacroExterminator{sess:sess}, krate);

branches/beta/src/libsyntax/ext/tt/macro_rules.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,12 @@ impl<'a> MacResult for ParserAnyMacro<'a> {
117117
self.ensure_complete_parse(false);
118118
Some(ret)
119119
}
120+
121+
fn make_ty(self: Box<ParserAnyMacro<'a>>) -> Option<P<ast::Ty>> {
122+
let ret = self.parser.borrow_mut().parse_ty();
123+
self.ensure_complete_parse(true);
124+
Some(ret)
125+
}
120126
}
121127

122128
struct MacroRulesMacroExpander {

0 commit comments

Comments
 (0)