]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc/middle/pat_util.rs
Remove random Idents outside of libsyntax
[rust.git] / src / librustc / middle / pat_util.rs
index 6f55ddfdfd2017dc013a2c20a78d1c469c8aec19..f72a945741ff798d21030bbac9cbd56961a758c3 100644 (file)
@@ -16,9 +16,9 @@
 use syntax::ast;
 use rustc_front::hir;
 use rustc_front::util::walk_pat;
-use syntax::codemap::{Span, Spanned, DUMMY_SP};
+use syntax::codemap::{respan, Span, Spanned, DUMMY_SP};
 
-pub type PatIdMap = FnvHashMap<ast::Ident, ast::NodeId>;
+pub type PatIdMap = FnvHashMap<ast::Name, ast::NodeId>;
 
 // This is used because same-named variables in alternative patterns need to
 // use the NodeId of their namesake in the first pattern.
@@ -109,12 +109,26 @@ pub fn pat_is_binding_or_wild(dm: &DefMap, pat: &hir::Pat) -> bool {
 /// Call `it` on every "binding" in a pattern, e.g., on `a` in
 /// `match foo() { Some(a) => (), None => () }`
 pub fn pat_bindings<I>(dm: &DefMap, pat: &hir::Pat, mut it: I) where
+    I: FnMut(hir::BindingMode, ast::NodeId, Span, &Spanned<ast::Name>),
+{
+    walk_pat(pat, |p| {
+        match p.node {
+          hir::PatIdent(binding_mode, ref pth, _) if pat_is_binding(dm, p) => {
+            it(binding_mode, p.id, p.span, &respan(pth.span, pth.node.name));
+          }
+          _ => {}
+        }
+        true
+    });
+}
+
+pub fn pat_bindings_hygienic<I>(dm: &DefMap, pat: &hir::Pat, mut it: I) where
     I: FnMut(hir::BindingMode, ast::NodeId, Span, &Spanned<ast::Ident>),
 {
     walk_pat(pat, |p| {
         match p.node {
           hir::PatIdent(binding_mode, ref pth, _) if pat_is_binding(dm, p) => {
-            it(binding_mode, p.id, p.span, pth);
+            it(binding_mode, p.id, p.span, &respan(pth.span, pth.node));
           }
           _ => {}
         }
@@ -182,10 +196,10 @@ pub fn pat_contains_bindings_or_wild(dm: &DefMap, pat: &hir::Pat) -> bool {
     contains_bindings
 }
 
-pub fn simple_identifier<'a>(pat: &'a hir::Pat) -> Option<&'a ast::Ident> {
+pub fn simple_name<'a>(pat: &'a hir::Pat) -> Option<ast::Name> {
     match pat.node {
         hir::PatIdent(hir::BindByValue(_), ref path1, None) => {
-            Some(&path1.node)
+            Some(path1.node.name)
         }
         _ => {
             None