]> git.lizzy.rs Git - rust.git/commitdiff
Add AST node for pattern macros
authorKeegan McAllister <kmcallister@mozilla.com>
Mon, 19 May 2014 20:29:41 +0000 (13:29 -0700)
committerKeegan McAllister <kmcallister@mozilla.com>
Wed, 28 May 2014 19:42:21 +0000 (12:42 -0700)
12 files changed:
src/librustc/middle/cfg/construct.rs
src/librustc/middle/check_match.rs
src/librustc/middle/mem_categorization.rs
src/librustc/middle/trans/_match.rs
src/librustc/middle/trans/debuginfo.rs
src/librustc/middle/typeck/check/_match.rs
src/librustdoc/clean/mod.rs
src/libsyntax/ast.rs
src/libsyntax/ast_util.rs
src/libsyntax/fold.rs
src/libsyntax/print/pprust.rs
src/libsyntax/visit.rs

index acf2442f6c16bd33168f53775dad97edad0e3bed..3f7bfefe27e578d911dde59fb45f9e2617403ceb 100644 (file)
@@ -142,6 +142,10 @@ fn pat(&mut self, pat: @ast::Pat, pred: CFGIndex) -> CFGIndex {
                     self.pats_all(post.iter().map(|p| *p), vec_exit);
                 self.add_node(pat.id, [post_exit])
             }
+
+            ast::PatMac(_) => {
+                self.tcx.sess.span_bug(pat.span, "unexpanded macro");
+            }
         }
     }
 
index ffc9ee7ec767a770a4e7bbc33238d273d73d8b01..bbea1349c14749f167aec8d6ab423e33ecb9ad9c 100644 (file)
@@ -392,6 +392,7 @@ fn pat_ctor_id(cx: &MatchCheckCtxt, p: @Pat) -> Option<ctor> {
           None => Some(vec(before.len() + after.len()))
         }
       }
+      PatMac(_) => cx.tcx.sess.bug("unexpanded macro"),
     }
 }
 
@@ -849,6 +850,10 @@ fn specialize(cx: &MatchCheckCtxt,
                     _ => None
                 }
             }
+            PatMac(_) => {
+                cx.tcx.sess.span_err(pat_span, "unexpanded macro");
+                None
+            }
         }
     }
 }
@@ -947,6 +952,7 @@ macro_rules! this_pattern {
       }
       PatEnum(_,_) => {}
       PatVec(..) => { this_pattern!() }
+      PatMac(_) => cx.tcx.sess.bug("unexpanded macro"),
     }
 }
 
index 5787657d6396fa58463e7dceb0097a20c479d5a1..10357ef3d567754a45417897f65f1cbb02e092a5 100644 (file)
@@ -1088,6 +1088,10 @@ pub fn cat_pattern(&self,
           ast::PatLit(_) | ast::PatRange(_, _) => {
               /*always ok*/
           }
+
+          ast::PatMac(_) => {
+              self.tcx().sess.span_bug(pat.span, "unexpanded macro");
+          }
         }
 
         Ok(())
index a10b31e923b196c4652fb827d95cdfaf3b46270b..8df57e7adfbe82b723d7fcd3b9db796bb1a4bf24 100644 (file)
@@ -2282,6 +2282,9 @@ fn bind_irrefutable_pat<'a>(
             bcx.sess().span_bug(pat.span,
                                 "vector patterns are never irrefutable!");
         }
+        ast::PatMac(..) => {
+            bcx.sess().span_bug(pat.span, "unexpanded macro");
+        }
         ast::PatWild | ast::PatWildMulti | ast::PatLit(_) | ast::PatRange(_, _) => ()
     }
     return bcx;
index 225c3c48cf406786e7c82ead502692a85184b3a1..744200c80e8a45a1d9bd926f735337ea9bf1893a 100644 (file)
@@ -2664,6 +2664,11 @@ fn walk_pattern(cx: &CrateContext,
                     walk_pattern(cx, sub_pat, scope_stack, scope_map);
                 }
             }
+
+            ast::PatMac(_) => {
+                cx.sess().span_bug(pat.span, "debuginfo::populate_scope_map() - \
+                                              Found unexpanded macro.");
+            }
         }
     }
 
index 3d37de38e4523eba450b9ddc34a62703cf524a9e..e223f4001dfd6dff6834f86fd01dfcb5de18846c 100644 (file)
@@ -722,6 +722,8 @@ pub fn check_pat(pcx: &pat_ctxt, pat: &ast::Pat, expected: ty::t) {
         }
         fcx.write_ty(pat.id, expected);
       }
+
+      ast::PatMac(_) => tcx.sess.bug("unexpanded macro"),
     }
 }
 
index 33e3e5370e69ed8928b99866709d4eab0531c7e2..48e390b35fb103dc81934d7d805c093a14de754a 100644 (file)
@@ -1731,7 +1731,12 @@ fn name_from_pat(p: &ast::Pat) -> String {
         PatRange(..) => fail!("tried to get argument name from PatRange, \
                               which is not allowed in function arguments"),
         PatVec(..) => fail!("tried to get argument name from pat_vec, \
-                             which is not allowed in function arguments")
+                             which is not allowed in function arguments"),
+        PatMac(..) => {
+            warn!("can't document the name of a function argument \
+                   produced by a pattern macro");
+            "(argument produced by macro)".to_string()
+        }
     }
 }
 
index 69a92a871855c82158f62cf439a190cd71899866..edeff1229bd91ee1ad954d2751f62b8ee6bf588b 100644 (file)
@@ -353,7 +353,8 @@ pub enum Pat_ {
     PatRange(@Expr, @Expr),
     // [a, b, ..i, y, z] is represented as
     // PatVec(~[a, b], Some(i), ~[y, z])
-    PatVec(Vec<@Pat> , Option<@Pat>, Vec<@Pat> )
+    PatVec(Vec<@Pat> , Option<@Pat>, Vec<@Pat> ),
+    PatMac(Mac),
 }
 
 #[deriving(Clone, Eq, TotalEq, Encodable, Decodable, Hash, Show)]
index 3e41e58fbe21827e4a517d97960f7ccbb1151986..5b61cd45483ac2d2eac0a35654c6ad6299a31d4e 100644 (file)
@@ -665,6 +665,7 @@ pub fn walk_pat(pat: &Pat, it: |&Pat| -> bool) -> bool {
                 slice.iter().advance(|&p| walk_pat(p, |p| it(p))) &&
                 after.iter().advance(|&p| walk_pat(p, |p| it(p)))
         }
+        PatMac(_) => fail!("attempted to analyze unexpanded pattern"),
         PatWild | PatWildMulti | PatLit(_) | PatRange(_, _) | PatIdent(_, _, _) |
         PatEnum(_, _) => {
             true
index 1607820326bb55cfe0e594f7f9df7cda788ebca5..b66d1f7eae58258cd448c12aa399be6e35ce3c8d 100644 (file)
@@ -770,6 +770,7 @@ pub fn noop_fold_pat<T: Folder>(p: @Pat, folder: &mut T) -> @Pat {
                     slice.map(|x| folder.fold_pat(x)),
                     after.iter().map(|x| folder.fold_pat(*x)).collect())
         }
+        PatMac(ref mac) => PatMac(folder.fold_mac(mac)),
     };
 
     @Pat {
index 3cb2d0b421c2f3c312d94713b9c790d98e1c783f..3127085ffedca2684a070b01cd97abe6eb3e7050 100644 (file)
@@ -1757,6 +1757,7 @@ pub fn print_pat(&mut self, pat: &ast::Pat) -> IoResult<()> {
                                    |s, &p| s.print_pat(p)));
                 try!(word(&mut self.s, "]"));
             }
+            ast::PatMac(ref m) => try!(self.print_mac(m)),
         }
         self.ann.post(self, NodePat(pat))
     }
index ce10d0db3ba75d88c94b01501d0b2db0295c6d0d..eb7aeb0e327a0e116386ecfb18c32c69de2df2b1 100644 (file)
@@ -457,6 +457,7 @@ pub fn walk_pat<E: Clone, V: Visitor<E>>(visitor: &mut V, pattern: &Pat, env: E)
                 visitor.visit_pat(*postpattern, env.clone())
             }
         }
+        PatMac(ref macro) => visitor.visit_mac(macro, env),
     }
 }