Skip to content

Commit 5fdd0e4

Browse files
author
Keegan McAllister
committed
Add AST node for pattern macros
1 parent 28a4ee5 commit 5fdd0e4

File tree

12 files changed

+36
-2
lines changed

12 files changed

+36
-2
lines changed

src/librustc/middle/cfg/construct.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,10 @@ impl<'a> CFGBuilder<'a> {
142142
self.pats_all(post.iter().map(|p| *p), vec_exit);
143143
self.add_node(pat.id, [post_exit])
144144
}
145+
146+
ast::PatMac(_) => {
147+
self.tcx.sess.span_bug(pat.span, "unexpanded macro");
148+
}
145149
}
146150
}
147151

src/librustc/middle/check_match.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,7 @@ fn pat_ctor_id(cx: &MatchCheckCtxt, p: @Pat) -> Option<ctor> {
392392
None => Some(vec(before.len() + after.len()))
393393
}
394394
}
395+
PatMac(_) => cx.tcx.sess.bug("unexpanded macro"),
395396
}
396397
}
397398

@@ -849,6 +850,10 @@ fn specialize(cx: &MatchCheckCtxt,
849850
_ => None
850851
}
851852
}
853+
PatMac(_) => {
854+
cx.tcx.sess.span_err(pat_span, "unexpanded macro");
855+
None
856+
}
852857
}
853858
}
854859
}
@@ -947,6 +952,7 @@ fn find_refutable(cx: &MatchCheckCtxt, pat: &Pat, spans: &mut Vec<Span>) {
947952
}
948953
PatEnum(_,_) => {}
949954
PatVec(..) => { this_pattern!() }
955+
PatMac(_) => cx.tcx.sess.bug("unexpanded macro"),
950956
}
951957
}
952958

src/librustc/middle/mem_categorization.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1088,6 +1088,10 @@ impl<'t,TYPER:Typer> MemCategorizationContext<'t,TYPER> {
10881088
ast::PatLit(_) | ast::PatRange(_, _) => {
10891089
/*always ok*/
10901090
}
1091+
1092+
ast::PatMac(_) => {
1093+
self.tcx().sess.span_bug(pat.span, "unexpanded macro");
1094+
}
10911095
}
10921096

10931097
Ok(())

src/librustc/middle/trans/_match.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2282,6 +2282,9 @@ fn bind_irrefutable_pat<'a>(
22822282
bcx.sess().span_bug(pat.span,
22832283
"vector patterns are never irrefutable!");
22842284
}
2285+
ast::PatMac(..) => {
2286+
bcx.sess().span_bug(pat.span, "unexpanded macro");
2287+
}
22852288
ast::PatWild | ast::PatWildMulti | ast::PatLit(_) | ast::PatRange(_, _) => ()
22862289
}
22872290
return bcx;

src/librustc/middle/trans/debuginfo.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2664,6 +2664,11 @@ fn populate_scope_map(cx: &CrateContext,
26642664
walk_pattern(cx, sub_pat, scope_stack, scope_map);
26652665
}
26662666
}
2667+
2668+
ast::PatMac(_) => {
2669+
cx.sess().span_bug(pat.span, "debuginfo::populate_scope_map() - \
2670+
Found unexpanded macro.");
2671+
}
26672672
}
26682673
}
26692674

src/librustc/middle/typeck/check/_match.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,8 @@ pub fn check_pat(pcx: &pat_ctxt, pat: &ast::Pat, expected: ty::t) {
722722
}
723723
fcx.write_ty(pat.id, expected);
724724
}
725+
726+
ast::PatMac(_) => tcx.sess.bug("unexpanded macro"),
725727
}
726728
}
727729

src/librustdoc/clean/mod.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1731,7 +1731,12 @@ fn name_from_pat(p: &ast::Pat) -> String {
17311731
PatRange(..) => fail!("tried to get argument name from PatRange, \
17321732
which is not allowed in function arguments"),
17331733
PatVec(..) => fail!("tried to get argument name from pat_vec, \
1734-
which is not allowed in function arguments")
1734+
which is not allowed in function arguments"),
1735+
PatMac(..) => {
1736+
warn!("can't document the name of a function argument \
1737+
produced by a pattern macro");
1738+
"(argument produced by macro)".to_string()
1739+
}
17351740
}
17361741
}
17371742

src/libsyntax/ast.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,8 @@ pub enum Pat_ {
353353
PatRange(@Expr, @Expr),
354354
// [a, b, ..i, y, z] is represented as
355355
// PatVec(~[a, b], Some(i), ~[y, z])
356-
PatVec(Vec<@Pat> , Option<@Pat>, Vec<@Pat> )
356+
PatVec(Vec<@Pat> , Option<@Pat>, Vec<@Pat> ),
357+
PatMac(Mac),
357358
}
358359

359360
#[deriving(Clone, Eq, TotalEq, Encodable, Decodable, Hash, Show)]

src/libsyntax/ast_util.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,7 @@ pub fn walk_pat(pat: &Pat, it: |&Pat| -> bool) -> bool {
665665
slice.iter().advance(|&p| walk_pat(p, |p| it(p))) &&
666666
after.iter().advance(|&p| walk_pat(p, |p| it(p)))
667667
}
668+
PatMac(_) => fail!("attempted to analyze unexpanded pattern"),
668669
PatWild | PatWildMulti | PatLit(_) | PatRange(_, _) | PatIdent(_, _, _) |
669670
PatEnum(_, _) => {
670671
true

src/libsyntax/fold.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -770,6 +770,7 @@ pub fn noop_fold_pat<T: Folder>(p: @Pat, folder: &mut T) -> @Pat {
770770
slice.map(|x| folder.fold_pat(x)),
771771
after.iter().map(|x| folder.fold_pat(*x)).collect())
772772
}
773+
PatMac(ref mac) => PatMac(folder.fold_mac(mac)),
773774
};
774775

775776
@Pat {

src/libsyntax/print/pprust.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1757,6 +1757,7 @@ impl<'a> State<'a> {
17571757
|s, &p| s.print_pat(p)));
17581758
try!(word(&mut self.s, "]"));
17591759
}
1760+
ast::PatMac(ref m) => try!(self.print_mac(m)),
17601761
}
17611762
self.ann.post(self, NodePat(pat))
17621763
}

src/libsyntax/visit.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,7 @@ pub fn walk_pat<E: Clone, V: Visitor<E>>(visitor: &mut V, pattern: &Pat, env: E)
457457
visitor.visit_pat(*postpattern, env.clone())
458458
}
459459
}
460+
PatMac(ref macro) => visitor.visit_mac(macro, env),
460461
}
461462
}
462463

0 commit comments

Comments
 (0)