Skip to content

Commit f4075e9

Browse files
committed
Use expand_mac_invoc in expand_pat
1 parent 8ee93b7 commit f4075e9

File tree

1 file changed

+3
-75
lines changed

1 file changed

+3
-75
lines changed

src/libsyntax/ext/expand.rs

Lines changed: 3 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -750,77 +750,10 @@ fn expand_pat(p: P<ast::Pat>, fld: &mut MacroExpander) -> P<ast::Pat> {
750750
PatKind::Mac(_) => {}
751751
_ => return noop_fold_pat(p, fld)
752752
}
753-
p.map(|ast::Pat {node, span, ..}| {
754-
let (pth, tts) = match node {
755-
PatKind::Mac(mac) => (mac.node.path, mac.node.tts),
753+
p.and_then(|ast::Pat {node, span, ..}| {
754+
match node {
755+
PatKind::Mac(mac) => expand_mac_invoc(mac, span, fld),
756756
_ => unreachable!()
757-
};
758-
759-
if pth.segments.len() > 1 {
760-
fld.cx.span_err(pth.span, "expected macro name without module separators");
761-
return DummyResult::raw_pat(span);
762-
}
763-
let extname = pth.segments[0].identifier.name;
764-
let marked_after = match fld.cx.syntax_env.find(extname) {
765-
None => {
766-
fld.cx.span_err(pth.span,
767-
&format!("macro undefined: '{}!'",
768-
extname));
769-
// let compilation continue
770-
return DummyResult::raw_pat(span);
771-
}
772-
773-
Some(rc) => match *rc {
774-
NormalTT(ref expander, tt_span, allow_internal_unstable) => {
775-
fld.cx.bt_push(ExpnInfo {
776-
call_site: span,
777-
callee: NameAndSpan {
778-
format: MacroBang(extname),
779-
span: tt_span,
780-
allow_internal_unstable: allow_internal_unstable,
781-
}
782-
});
783-
784-
let fm = fresh_mark();
785-
let marked_before = mark_tts(&tts[..], fm);
786-
let mac_span = fld.cx.original_span();
787-
let pat = expander.expand(fld.cx,
788-
mac_span,
789-
&marked_before[..]).make_pat();
790-
let expanded = match pat {
791-
Some(e) => e,
792-
None => {
793-
fld.cx.span_err(
794-
pth.span,
795-
&format!(
796-
"non-pattern macro in pattern position: {}",
797-
extname
798-
)
799-
);
800-
return DummyResult::raw_pat(span);
801-
}
802-
};
803-
804-
// mark after:
805-
mark_pat(expanded,fm)
806-
}
807-
_ => {
808-
fld.cx.span_err(span,
809-
&format!("{}! is not legal in pattern position",
810-
extname));
811-
return DummyResult::raw_pat(span);
812-
}
813-
}
814-
};
815-
816-
let fully_expanded =
817-
fld.fold_pat(marked_after).node.clone();
818-
fld.cx.bt_pop();
819-
820-
ast::Pat {
821-
id: ast::DUMMY_NODE_ID,
822-
node: fully_expanded,
823-
span: span
824757
}
825758
})
826759
}
@@ -1388,11 +1321,6 @@ fn mark_tts(tts: &[TokenTree], m: Mrk) -> Vec<TokenTree> {
13881321
noop_fold_tts(tts, &mut Marker{mark:m})
13891322
}
13901323

1391-
// apply a given mark to the given pattern. Used following the expansion of a macro.
1392-
fn mark_pat(pat: P<ast::Pat>, m: Mrk) -> P<ast::Pat> {
1393-
Marker{mark:m}.fold_pat(pat)
1394-
}
1395-
13961324
// apply a given mark to the given item. Used following the expansion of a macro.
13971325
fn mark_item(expr: P<ast::Item>, m: Mrk) -> P<ast::Item> {
13981326
Marker{mark:m}.fold_item(expr)

0 commit comments

Comments
 (0)