use syntax::ast;
use rustc_front::hir;
use rustc_front::util::walk_pat;
-use syntax::codemap::{Span, 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.
/// 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, &hir::SpannedIdent),
+ 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, pth);
+ 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, &respan(pth.span, pth.node));
}
_ => {}
}
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