summary refs log tree commit diff
path: root/src/libsyntax
diff options
context:
space:
mode:
authorVadim Petrochenkov <vadim.petrochenkov@gmail.com>2015-09-12 16:10:12 +0300
committerVadim Petrochenkov <vadim.petrochenkov@gmail.com>2015-09-17 14:13:12 +0300
commit50e42ea9f70361ccd71682070c01ea808891f0ce (patch)
tree2cd554300fc90df2e2432f6384b86bb1b2f069da /src/libsyntax
parentd3fc6e1858f6882bc9bd14641420bf3c4f7ee86b (diff)
downloadrust-50e42ea9f70361ccd71682070c01ea808891f0ce.tar.gz
rust-50e42ea9f70361ccd71682070c01ea808891f0ce.zip
Correctly walk import lists in AST visitors
Diffstat (limited to 'src/libsyntax')
-rw-r--r--src/libsyntax/visit.rs40
1 files changed, 21 insertions, 19 deletions
diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs
index 8365a7375c6..2a2f5c0f2c1 100644
--- a/src/libsyntax/visit.rs
+++ b/src/libsyntax/visit.rs
@@ -127,6 +127,9 @@ pub trait Visitor<'v> : Sized {
     fn visit_path(&mut self, path: &'v Path, _id: ast::NodeId) {
         walk_path(self, path)
     }
+    fn visit_path_list_item(&mut self, prefix: &'v Path, item: &'v PathListItem) {
+        walk_path_list_item(self, prefix, item)
+    }
     fn visit_path_segment(&mut self, path_span: Span, path_segment: &'v PathSegment) {
         walk_path_segment(self, path_span, path_segment)
     }
@@ -209,33 +212,21 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item) {
         ItemExternCrate(..) => {}
         ItemUse(ref vp) => {
             match vp.node {
-                ViewPathSimple(ident, ref path) => {
-                    visitor.visit_ident(vp.span, ident);
+                ViewPathSimple(_ident, ref path) => {
                     visitor.visit_path(path, item.id);
                 }
                 ViewPathGlob(ref path) => {
                     visitor.visit_path(path, item.id);
                 }
                 ViewPathList(ref prefix, ref list) => {
-                    for id in list {
-                        match id.node {
-                            PathListIdent { name, rename, .. } => {
-                                visitor.visit_ident(id.span, name);
-                                if let Some(ident) = rename {
-                                    visitor.visit_ident(id.span, ident);
-                                }
-                            }
-                            PathListMod { rename, .. } => {
-                                if let Some(ident) = rename {
-                                    visitor.visit_ident(id.span, ident);
-                                }
-                            }
+                    if !list.is_empty() {
+                        for item in list {
+                            visitor.visit_path_list_item(prefix, item)
                         }
+                    } else {
+                        // FIXME: uncomment this and fix the resulting ICE
+                        // visitor.visit_path(prefix, item.id);
                     }
-
-                    // Note that the `prefix` here is not a complete
-                    // path, so we don't use `visit_path`.
-                    walk_path(visitor, prefix);
                 }
             }
         }
@@ -417,6 +408,17 @@ pub fn walk_path<'v, V: Visitor<'v>>(visitor: &mut V, path: &'v Path) {
     }
 }
 
+pub fn walk_path_list_item<'v, V: Visitor<'v>>(visitor: &mut V, prefix: &'v Path,
+                                               item: &'v PathListItem) {
+    for segment in &prefix.segments {
+        visitor.visit_path_segment(prefix.span, segment);
+    }
+
+    if let PathListIdent { name, .. } = item.node {
+        visitor.visit_ident(item.span, name);
+    }
+}
+
 pub fn walk_path_segment<'v, V: Visitor<'v>>(visitor: &mut V,
                                              path_span: Span,
                                              segment: &'v PathSegment) {