]> git.lizzy.rs Git - rust.git/commitdiff
syntax: use a single Path for Trait::Item in QPath.
authorEduard Burtescu <edy.burt@gmail.com>
Sat, 31 Jan 2015 19:20:24 +0000 (21:20 +0200)
committerEduard Burtescu <edy.burt@gmail.com>
Tue, 24 Feb 2015 12:14:16 +0000 (14:14 +0200)
17 files changed:
src/librustc/lint/context.rs
src/librustc/lint/mod.rs
src/librustc/middle/dead.rs
src/librustc_back/svh.rs
src/librustc_privacy/lib.rs
src/librustc_resolve/lib.rs
src/librustc_trans/save/mod.rs
src/librustc_typeck/astconv.rs
src/librustc_typeck/check/mod.rs
src/librustc_typeck/collect.rs
src/librustdoc/clean/mod.rs
src/libsyntax/ast.rs
src/libsyntax/ext/build.rs
src/libsyntax/fold.rs
src/libsyntax/parse/parser.rs
src/libsyntax/print/pprust.rs
src/libsyntax/visit.rs

index 81fb1c8e913f62ab4fa45d5d1dcfac6f2be76afa..d344ee8c881c5ab4fa796f64f80f9ae2264ffcb2 100644 (file)
@@ -717,11 +717,6 @@ fn visit_path(&mut self, p: &ast::Path, id: ast::NodeId) {
         visit::walk_path(self, p);
     }
 
-    fn visit_qpath(&mut self, p: &ast::QPath, id: ast::NodeId) {
-        run_lints!(self, check_qpath, p, id);
-        visit::walk_qpath(self, p);
-    }
-
     fn visit_attribute(&mut self, attr: &ast::Attribute) {
         run_lints!(self, check_attribute, attr);
     }
index 1e2ddb7db0bfa768be3b33091b7f787312ff8853..021827b0101c81f7dee8caf04ab20ca6bcc9cac5 100644 (file)
@@ -157,7 +157,6 @@ fn check_lifetime_def(&mut self, _: &Context, _: &ast::LifetimeDef) { }
     fn check_explicit_self(&mut self, _: &Context, _: &ast::ExplicitSelf) { }
     fn check_mac(&mut self, _: &Context, _: &ast::Mac) { }
     fn check_path(&mut self, _: &Context, _: &ast::Path, _: ast::NodeId) { }
-    fn check_qpath(&mut self, _: &Context, _: &ast::QPath, _: ast::NodeId) { }
     fn check_attribute(&mut self, _: &Context, _: &ast::Attribute) { }
 
     /// Called when entering a syntax node that can have lint attributes such
index 4f9b900a5f8765c6f32eb46025ff7e800f62a89b..ff78deb8d12ea6ba945531b6c34f0762b38a2ee6 100644 (file)
@@ -306,11 +306,6 @@ fn visit_path(&mut self, path: &ast::Path, id: ast::NodeId) {
         visit::walk_path(self, path);
     }
 
-    fn visit_qpath(&mut self, qpath: &ast::QPath, id: ast::NodeId) {
-        self.lookup_and_handle_definition(&id);
-        visit::walk_qpath(self, qpath);
-    }
-
     fn visit_item(&mut self, _: &ast::Item) {
         // Do not recurse into items. These items will be added to the
         // worklist and recursed into manually if necessary.
index af886ed25ab20a8b1b639ce9e1e23fee02fbc3ba..2fc43ab26b58ef328699c5a295df5386f79f982f 100644 (file)
@@ -194,7 +194,6 @@ enum SawAbiComponent<'a> {
         SawVariant,
         SawExplicitSelf,
         SawPath,
-        SawQPath,
         SawOptLifetimeRef,
         SawBlock,
         SawPat,
@@ -486,10 +485,6 @@ fn visit_path(&mut self, path: &Path, _: ast::NodeId) {
             SawPath.hash(self.st); visit::walk_path(self, path)
         }
 
-        fn visit_qpath(&mut self, qpath: &QPath, _: ast::NodeId) {
-            SawQPath.hash(self.st); visit::walk_qpath(self, qpath)
-        }
-
         fn visit_block(&mut self, b: &Block) {
             SawBlock.hash(self.st); visit::walk_block(self, b)
         }
index 1f8ae3fbbcbb47875c96d1a719475101cd90930f..838ba9c658cf1661fda1b7e3b4ac3c9949d8d848 100644 (file)
@@ -1021,11 +1021,6 @@ fn visit_path(&mut self, path: &ast::Path, id: ast::NodeId) {
         self.check_path(path.span, id, path.segments.last().unwrap().identifier);
         visit::walk_path(self, path);
     }
-
-    fn visit_qpath(&mut self, qpath: &ast::QPath, id: ast::NodeId) {
-        self.check_path(qpath.trait_path.span, id, qpath.item_path.identifier);
-        visit::walk_qpath(self, qpath);
-    }
 }
 
 ////////////////////////////////////////////////////////////////////////////////
index 914663e75814e059bd2436a30954442f38537c50..6584e3cc19d4c9a7897a7902a3e17c72460a30e3 100644 (file)
@@ -1096,8 +1096,8 @@ fn names_to_string(&self, names: &[Name]) -> String {
         result
     }
 
-    fn path_names_to_string(&self, path: &Path) -> String {
-        let names: Vec<ast::Name> = path.segments
+    fn path_names_to_string(&self, path: &Path, depth: usize) -> String {
+        let names: Vec<ast::Name> = path.segments[..path.segments.len()-depth]
                                         .iter()
                                         .map(|seg| seg.identifier.name)
                                         .collect();
@@ -3162,7 +3162,7 @@ fn resolve_type_parameter_bound(&mut self,
         match *type_parameter_bound {
             TraitTyParamBound(ref tref, _) => {
                 self.resolve_trait_reference(tref.trait_ref.ref_id,
-                                             &tref.trait_ref.path,
+                                             &tref.trait_ref.path, 0,
                                              reference_type)
             }
             RegionTyParamBound(..) => {}
@@ -3172,10 +3172,11 @@ fn resolve_type_parameter_bound(&mut self,
     fn resolve_trait_reference(&mut self,
                                id: NodeId,
                                trait_path: &Path,
+                               path_depth: usize,
                                reference_type: TraitReferenceType) {
-        match self.resolve_path(id, trait_path, TypeNS, true) {
+        match self.resolve_path(id, trait_path, path_depth, TypeNS, true) {
             None => {
-                let path_str = self.path_names_to_string(trait_path);
+                let path_str = self.path_names_to_string(trait_path, path_depth);
                 let usage_str = match reference_type {
                     TraitBoundingTypeParameter => "bound type parameter with",
                     TraitImplementation        => "implement",
@@ -3196,7 +3197,7 @@ fn resolve_trait_reference(&mut self,
                     (def, _) => {
                         self.resolve_error(trait_path.span,
                             &format!("`{}` is not a trait",
-                                     self.path_names_to_string(trait_path)));
+                                     self.path_names_to_string(trait_path, path_depth)));
 
                         // If it's a typedef, give a note
                         if let DefTy(..) = def {
@@ -3221,7 +3222,7 @@ fn resolve_where_clause(&mut self, where_clause: &ast::WhereClause) {
                 }
                 &ast::WherePredicate::RegionPredicate(_) => {}
                 &ast::WherePredicate::EqPredicate(ref eq_pred) => {
-                    match self.resolve_path(eq_pred.id, &eq_pred.path, TypeNS, true) {
+                    match self.resolve_path(eq_pred.id, &eq_pred.path, 0, TypeNS, true) {
                         Some((def @ DefTyParam(..), last_private)) => {
                             self.record_def(eq_pred.id, (def, last_private));
                         }
@@ -3297,7 +3298,7 @@ fn with_optional_trait_ref<T, F>(&mut self,
         let new_val = match *opt_trait_ref {
             Some(ref trait_ref) => {
                 self.resolve_trait_reference(trait_ref.ref_id,
-                                             &trait_ref.path,
+                                             &trait_ref.path, 0,
                                              TraitImplementation);
 
                 match self.def_map.borrow().get(&trait_ref.ref_id) {
@@ -3395,7 +3396,7 @@ fn check_trait_item(&self, name: Name, span: Span) {
         // If there is a TraitRef in scope for an impl, then the method must be in the trait.
         if let Some((did, ref trait_ref)) = self.current_trait_ref {
             if self.trait_item_map.get(&(name, did)).is_none() {
-                let path_str = self.path_names_to_string(&trait_ref.path);
+                let path_str = self.path_names_to_string(&trait_ref.path, 0);
                 self.resolve_error(span,
                                     &format!("method `{}` is not a member of trait `{}`",
                                             token::get_name(name),
@@ -3563,23 +3564,15 @@ fn resolve_type(&mut self, ty: &Ty) {
         match ty.node {
             // Like path expressions, the interpretation of path types depends
             // on whether the path has multiple elements in it or not.
-            TyPath(_) | TyQPath(_) => {
-                let mut path_from_qpath;
-                let path = match ty.node {
-                    TyPath(ref path) => path,
-                    TyQPath(ref qpath) => {
-                        self.resolve_type(&*qpath.self_type);
-
-                        // Just make sure the trait is valid, don't record a def.
-                        self.resolve_trait_reference(ty.id, &qpath.trait_path, TraitQPath);
-                        self.def_map.borrow_mut().remove(&ty.id);
-
-                        path_from_qpath = qpath.trait_path.clone();
-                        path_from_qpath.segments.push(qpath.item_path.clone());
-                        &path_from_qpath
-                    }
-                    _ => unreachable!()
-                };
+
+            TyPath(ref path) | TyQPath(ast::QPath { ref path, .. }) => {
+                if let TyQPath(ref qpath) = ty.node {
+                    self.resolve_type(&*qpath.self_type);
+
+                    // Just make sure the trait is valid, don't record a def.
+                    self.resolve_trait_reference(ty.id, path, 1, TraitQPath);
+                    self.def_map.borrow_mut().remove(&ty.id);
+                }
 
                 // This is a path in the type namespace. Walk through scopes
                 // looking for it.
@@ -3612,7 +3605,7 @@ fn resolve_type(&mut self, ty: &Ty) {
                 }
 
                 if let None = result_def {
-                    result_def = self.resolve_path(ty.id, path, TypeNS, true);
+                    result_def = self.resolve_path(ty.id, path, 0, TypeNS, true);
                 }
 
                 match result_def {
@@ -3620,7 +3613,7 @@ fn resolve_type(&mut self, ty: &Ty) {
                         // Write the result into the def map.
                         debug!("(resolving type) writing resolution for `{}` \
                                 (id {}) = {:?}",
-                               self.path_names_to_string(path),
+                               self.path_names_to_string(path, 0),
                                ty.id, def);
                         self.record_def(ty.id, def);
                     }
@@ -3630,7 +3623,7 @@ fn resolve_type(&mut self, ty: &Ty) {
                             _ => "type name"
                         };
                         let msg = format!("use of undeclared {} `{}`", kind,
-                                          self.path_names_to_string(path));
+                                          self.path_names_to_string(path, 0));
                         self.resolve_error(ty.span, &msg[..]);
                     }
                 }
@@ -3765,7 +3758,7 @@ struct or enum variant",
 
                 PatEnum(ref path, _) => {
                     // This must be an enum variant, struct or const.
-                    match self.resolve_path(pat_id, path, ValueNS, false) {
+                    match self.resolve_path(pat_id, path, 0, ValueNS, false) {
                         Some(def @ (DefVariant(..), _)) |
                         Some(def @ (DefStruct(..), _))  |
                         Some(def @ (DefConst(..), _)) => {
@@ -3808,7 +3801,7 @@ struct or enum variant",
                 }
 
                 PatStruct(ref path, _, _) => {
-                    match self.resolve_path(pat_id, path, TypeNS, false) {
+                    match self.resolve_path(pat_id, path, 0, TypeNS, false) {
                         Some(definition) => {
                             self.record_def(pattern.id, definition);
                         }
@@ -3816,7 +3809,7 @@ struct or enum variant",
                             debug!("(resolving pattern) didn't find struct \
                                     def: {:?}", result);
                             let msg = format!("`{}` does not name a structure",
-                                              self.path_names_to_string(path));
+                                              self.path_names_to_string(path, 0));
                             self.resolve_error(path.span, &msg[..]);
                         }
                     }
@@ -3896,34 +3889,38 @@ fn resolve_bare_identifier_pattern(&mut self, name: Name, span: Span)
     fn resolve_path(&mut self,
                     id: NodeId,
                     path: &Path,
+                    path_depth: usize,
                     namespace: Namespace,
                     check_ribs: bool) -> Option<(Def, LastPrivate)> {
+        let span = path.span;
+        let segments = &path.segments[..path.segments.len()-path_depth];
+
         // First, resolve the types and associated type bindings.
-        for ty in path.segments.iter().flat_map(|s| s.parameters.types().into_iter()) {
+        for ty in segments.iter().flat_map(|s| s.parameters.types().into_iter()) {
             self.resolve_type(&**ty);
         }
-        for binding in path.segments.iter().flat_map(|s| s.parameters.bindings().into_iter()) {
+        for binding in segments.iter().flat_map(|s| s.parameters.bindings().into_iter()) {
             self.resolve_type(&*binding.ty);
         }
 
         // A special case for sugared associated type paths `T::A` where `T` is
         // a type parameter and `A` is an associated type on some bound of `T`.
-        if namespace == TypeNS && path.segments.len() == 2 {
-            match self.resolve_identifier(path.segments[0].identifier,
+        if namespace == TypeNS && segments.len() == 2 {
+            match self.resolve_identifier(segments[0].identifier,
                                           TypeNS,
                                           true,
-                                          path.span) {
+                                          span) {
                 Some((def, last_private)) => {
                     match def {
                         DefTyParam(_, _, did, _) => {
                             let def = DefAssociatedPath(TyParamProvenance::FromParam(did),
-                                                        path.segments.last()
+                                                        segments.last()
                                                             .unwrap().identifier);
                             return Some((def, last_private));
                         }
                         DefSelfTy(nid) => {
                             let def = DefAssociatedPath(TyParamProvenance::FromSelf(local_def(nid)),
-                                                        path.segments.last()
+                                                        segments.last()
                                                             .unwrap().identifier);
                             return Some((def, last_private));
                         }
@@ -3935,24 +3932,23 @@ fn resolve_path(&mut self,
         }
 
         if path.global {
-            return self.resolve_crate_relative_path(path, namespace);
+            return self.resolve_crate_relative_path(span, segments, namespace);
         }
 
         // Try to find a path to an item in a module.
         let unqualified_def =
-                self.resolve_identifier(path.segments.last().unwrap().identifier,
+                self.resolve_identifier(segments.last().unwrap().identifier,
                                         namespace,
                                         check_ribs,
-                                        path.span);
+                                        span);
 
-        if path.segments.len() > 1 {
-            let def = self.resolve_module_relative_path(path, namespace);
+        if segments.len() > 1 {
+            let def = self.resolve_module_relative_path(span, segments, namespace);
             match (def, unqualified_def) {
                 (Some((ref d, _)), Some((ref ud, _))) if *d == *ud => {
                     self.session
                         .add_lint(lint::builtin::UNUSED_QUALIFICATIONS,
-                                  id,
-                                  path.span,
+                                  id, span,
                                   "unnecessary qualification".to_string());
                 }
                 _ => ()
@@ -4063,12 +4059,13 @@ fn resolve_definition_of_name_in_module(&mut self,
 
     // resolve a "module-relative" path, e.g. a::b::c
     fn resolve_module_relative_path(&mut self,
-                                    path: &Path,
+                                    span: Span,
+                                    segments: &[ast::PathSegment],
                                     namespace: Namespace)
                                     -> Option<(Def, LastPrivate)> {
-        let module_path = path.segments.init().iter()
-                                              .map(|ps| ps.identifier.name)
-                                              .collect::<Vec<_>>();
+        let module_path = segments.init().iter()
+                                         .map(|ps| ps.identifier.name)
+                                         .collect::<Vec<_>>();
 
         let containing_module;
         let last_private;
@@ -4076,7 +4073,7 @@ fn resolve_module_relative_path(&mut self,
         match self.resolve_module_path(module,
                                        &module_path[..],
                                        UseLexicalScope,
-                                       path.span,
+                                       span,
                                        PathSearch) {
             Failed(err) => {
                 let (span, msg) = match err {
@@ -4084,7 +4081,7 @@ fn resolve_module_relative_path(&mut self,
                     None => {
                         let msg = format!("Use of undeclared type or module `{}`",
                                           self.names_to_string(&module_path));
-                        (path.span, msg)
+                        (span, msg)
                     }
                 };
 
@@ -4099,7 +4096,7 @@ fn resolve_module_relative_path(&mut self,
             }
         }
 
-        let name = path.segments.last().unwrap().identifier.name;
+        let name = segments.last().unwrap().identifier.name;
         let def = match self.resolve_definition_of_name_in_module(containing_module.clone(),
                                                                   name,
                                                                   namespace) {
@@ -4120,12 +4117,13 @@ fn resolve_module_relative_path(&mut self,
     /// Invariant: This must be called only during main resolution, not during
     /// import resolution.
     fn resolve_crate_relative_path(&mut self,
-                                   path: &Path,
+                                   span: Span,
+                                   segments: &[ast::PathSegment],
                                    namespace: Namespace)
                                        -> Option<(Def, LastPrivate)> {
-        let module_path = path.segments.init().iter()
-                                              .map(|ps| ps.identifier.name)
-                                              .collect::<Vec<_>>();
+        let module_path = segments.init().iter()
+                                         .map(|ps| ps.identifier.name)
+                                         .collect::<Vec<_>>();
 
         let root_module = self.graph_root.get_module();
 
@@ -4134,7 +4132,7 @@ fn resolve_crate_relative_path(&mut self,
         match self.resolve_module_path_from_root(root_module,
                                                  &module_path[..],
                                                  0,
-                                                 path.span,
+                                                 span,
                                                  PathSearch,
                                                  LastMod(AllPublic)) {
             Failed(err) => {
@@ -4143,7 +4141,7 @@ fn resolve_crate_relative_path(&mut self,
                     None => {
                         let msg = format!("Use of undeclared module `::{}`",
                                           self.names_to_string(&module_path[..]));
-                        (path.span, msg)
+                        (span, msg)
                     }
                 };
 
@@ -4162,7 +4160,7 @@ fn resolve_crate_relative_path(&mut self,
             }
         }
 
-        let name = path.segments.last().unwrap().identifier.name;
+        let name = segments.last().unwrap().identifier.name;
         match self.resolve_definition_of_name_in_module(containing_module,
                                                         name,
                                                         namespace) {
@@ -4342,7 +4340,7 @@ fn get_module(this: &mut Resolver, span: Span, name_path: &[ast::Name])
         match get_module(self, path.span, &name_path[..]) {
             Some(module) => match module.children.borrow().get(&name) {
                 Some(binding) => {
-                    let p_str = self.path_names_to_string(&path);
+                    let p_str = self.path_names_to_string(&path, 0);
                     match binding.def_for_namespace(ValueNS) {
                         Some(DefStaticMethod(_, provenance)) => {
                             match provenance {
@@ -4363,7 +4361,7 @@ fn get_module(this: &mut Resolver, span: Span, name_path: &[ast::Name])
         // Look for a method in the current trait.
         match self.current_trait_ref {
             Some((did, ref trait_ref)) => {
-                let path_str = self.path_names_to_string(&trait_ref.path);
+                let path_str = self.path_names_to_string(&trait_ref.path, 0);
 
                 match self.trait_item_map.get(&(name, did)) {
                     Some(&StaticMethodTraitItemKind) => {
@@ -4426,29 +4424,21 @@ fn resolve_expr(&mut self, expr: &Expr) {
             // The interpretation of paths depends on whether the path has
             // multiple elements in it or not.
 
-            ExprPath(_) | ExprQPath(_) => {
-                let mut path_from_qpath;
-                let path = match expr.node {
-                    ExprPath(ref path) => path,
-                    ExprQPath(ref qpath) => {
-                        self.resolve_type(&*qpath.self_type);
+            ExprPath(ref path) | ExprQPath(ast::QPath { ref path, .. }) => {
+                if let ExprQPath(ref qpath) = expr.node {
+                    self.resolve_type(&*qpath.self_type);
 
-                        // Just make sure the trait is valid, don't record a def.
-                        self.resolve_trait_reference(expr.id, &qpath.trait_path, TraitQPath);
-                        self.def_map.borrow_mut().remove(&expr.id);
+                    // Just make sure the trait is valid, don't record a def.
+                    self.resolve_trait_reference(expr.id, path, 1, TraitQPath);
+                    self.def_map.borrow_mut().remove(&expr.id);
+                }
 
-                        path_from_qpath = qpath.trait_path.clone();
-                        path_from_qpath.segments.push(qpath.item_path.clone());
-                        &path_from_qpath
-                    }
-                    _ => unreachable!()
-                };
                 // This is a local path in the value namespace. Walk through
                 // scopes looking for it.
-                match self.resolve_path(expr.id, path, ValueNS, true) {
+                match self.resolve_path(expr.id, path, 0, ValueNS, true) {
                     // Check if struct variant
                     Some((DefVariant(_, _, true), _)) => {
-                        let path_name = self.path_names_to_string(path);
+                        let path_name = self.path_names_to_string(path, 0);
                         self.resolve_error(expr.span,
                                 &format!("`{}` is a struct variant name, but \
                                           this expression \
@@ -4463,7 +4453,7 @@ fn resolve_expr(&mut self, expr: &Expr) {
                     Some(def) => {
                         // Write the result into the def map.
                         debug!("(resolving expr) resolved `{}`",
-                               self.path_names_to_string(path));
+                               self.path_names_to_string(path, 0));
 
                         self.record_def(expr.id, def);
                     }
@@ -4472,9 +4462,9 @@ fn resolve_expr(&mut self, expr: &Expr) {
                         // (The pattern matching def_tys where the id is in self.structs
                         // matches on regular structs while excluding tuple- and enum-like
                         // structs, which wouldn't result in this error.)
-                        let path_name = self.path_names_to_string(path);
+                        let path_name = self.path_names_to_string(path, 0);
                         match self.with_no_errors(|this|
-                            this.resolve_path(expr.id, path, TypeNS, false)) {
+                            this.resolve_path(expr.id, path, 0, TypeNS, false)) {
                             Some((DefTy(struct_id, _), _))
                               if self.structs.contains_key(&struct_id) => {
                                 self.resolve_error(expr.span,
@@ -4557,13 +4547,13 @@ fn resolve_expr(&mut self, expr: &Expr) {
                 // Resolve the path to the structure it goes to. We don't
                 // check to ensure that the path is actually a structure; that
                 // is checked later during typeck.
-                match self.resolve_path(expr.id, path, TypeNS, false) {
+                match self.resolve_path(expr.id, path, 0, TypeNS, false) {
                     Some(definition) => self.record_def(expr.id, definition),
                     result => {
                         debug!("(resolving expression) didn't find struct \
                                 def: {:?}", result);
                         let msg = format!("`{}` does not name a structure",
-                                          self.path_names_to_string(path));
+                                          self.path_names_to_string(path, 0));
                         self.resolve_error(path.span, &msg[..]);
                     }
                 }
index c92886651289270786fa1e75b2ff5a4cef13555a..6a20938da2e47d09945d4ea4b1e5b4ffb60cf9d4 100644 (file)
@@ -1334,16 +1334,10 @@ fn visit_expr(&mut self, ex: &ast::Expr) {
                 // Don't need to do anything for function calls,
                 // because just walking the callee path does what we want.
                 visit::walk_expr(self, ex);
-            },
-            ast::ExprPath(ref path) => {
-                self.process_path(ex.id, path.span, path, None);
-                visit::walk_path(self, path);
             }
-            ast::ExprQPath(ref qpath) => {
-                let mut path = qpath.trait_path.clone();
-                path.segments.push(qpath.item_path.clone());
-                self.process_path(ex.id, ex.span, &path, None);
-                visit::walk_qpath(self, &**qpath);
+            ast::ExprPath(ref path) | ast::ExprQPath(ast::QPath { ref path, .. }) => {
+                self.process_path(ex.id, path.span, path, None);
+                visit::walk_expr(self, ex);
             }
             ast::ExprStruct(ref path, ref fields, ref base) =>
                 self.process_struct_lit(ex, path, fields, base),
index cf567f709f52a6f7dd0515336759b880f87c162c..8eb75ece4a14587f3241dee3e12f80b6239b3811 100644 (file)
@@ -575,8 +575,7 @@ pub fn instantiate_poly_trait_ref<'tcx>(
     let shifted_rscope = ShiftedRscope::new(rscope);
 
     let trait_ref = instantiate_trait_ref(this, &shifted_rscope,
-                                          &ast_trait_ref.trait_ref.path,
-                                          ast_trait_ref.trait_ref.ref_id,
+                                          &ast_trait_ref.trait_ref,
                                           None, self_ty, Some(&mut projections));
 
     for projection in projections {
@@ -595,14 +594,14 @@ pub fn instantiate_poly_trait_ref<'tcx>(
 pub fn instantiate_trait_ref<'tcx>(
     this: &AstConv<'tcx>,
     rscope: &RegionScope,
-    path: &ast::Path,
-    path_id: ast::NodeId,
+    trait_ref: &ast::TraitRef,
     impl_id: Option<ast::NodeId>,
     self_ty: Option<Ty<'tcx>>,
     projections: Option<&mut Vec<ty::ProjectionPredicate<'tcx>>>)
     -> Rc<ty::TraitRef<'tcx>>
 {
-    match ::lookup_def_tcx(this.tcx(), path.span, path_id) {
+    let path = &trait_ref.path;
+    match ::lookup_def_tcx(this.tcx(), path.span, trait_ref.ref_id) {
         def::DefTrait(trait_def_id) => {
             let trait_ref = ast_path_to_trait_ref(this,
                                                   rscope,
@@ -1201,11 +1200,7 @@ pub fn ast_ty_to_ty<'tcx>(this: &AstConv<'tcx>,
             ast::TyPolyTraitRef(ref bounds) => {
                 conv_ty_poly_trait_ref(this, rscope, ast_ty.span, &bounds[..])
             }
-            ast::TyPath(_) | ast::TyQPath(_) => {
-                let simple_path = |&:| match ast_ty.node {
-                    ast::TyPath(ref path) => path,
-                    _ => tcx.sess.span_bug(ast_ty.span, "expected non-qualified path")
-                };
+            ast::TyPath(ref path) | ast::TyQPath(ast::QPath { ref path, .. }) => {
                 let a_def = match tcx.def_map.borrow().get(&ast_ty.id) {
                     None => {
                         tcx.sess
@@ -1224,24 +1219,24 @@ pub fn ast_ty_to_ty<'tcx>(this: &AstConv<'tcx>,
                         let trait_ref = object_path_to_poly_trait_ref(this,
                                                                       rscope,
                                                                       trait_def_id,
-                                                                      simple_path(),
+                                                                      path,
                                                                       &mut projection_bounds);
 
                         trait_ref_to_object_type(this, rscope, ast_ty.span,
                                                  trait_ref, projection_bounds, &[])
                     }
                     def::DefTy(did, _) | def::DefStruct(did) => {
-                        ast_path_to_ty(this, rscope, did, simple_path()).ty
+                        ast_path_to_ty(this, rscope, did, path).ty
                     }
                     def::DefTyParam(space, index, _, name) => {
-                        check_path_args(tcx, simple_path(), NO_TPS | NO_REGIONS);
+                        check_path_args(tcx, path, NO_TPS | NO_REGIONS);
                         ty::mk_param(tcx, space, index, name)
                     }
                     def::DefSelfTy(_) => {
                         // n.b.: resolve guarantees that the this type only appears in a
                         // trait, which we rely upon in various places when creating
                         // substs
-                        check_path_args(tcx, simple_path(), NO_TPS | NO_REGIONS);
+                        check_path_args(tcx, path, NO_TPS | NO_REGIONS);
                         ty::mk_self_type(tcx)
                     }
                     def::DefMod(id) => {
@@ -1253,19 +1248,14 @@ pub fn ast_ty_to_ty<'tcx>(this: &AstConv<'tcx>,
                         panic!("DefPrimTy arm missed in previous ast_ty_to_prim_ty call");
                     }
                     def::DefAssociatedTy(trait_did, _) => {
-                        let (opt_self_ty, trait_segment, item_segment) = match ast_ty.node {
-                            ast::TyQPath(ref qpath) => {
-                                (Some(&*qpath.self_type), qpath.trait_path.segments.last().unwrap(),
-                                 &qpath.item_path)
-                            }
-                            ast::TyPath(ref path) => {
-                                (None, &path.segments[path.segments.len()-2],
-                                 path.segments.last().unwrap())
-                            }
-                            _ => unreachable!()
+                        let opt_self_ty = if let ast::TyQPath(ref qpath) = ast_ty.node {
+                            Some(&*qpath.self_type)
+                        } else {
+                            None
                         };
-                        qpath_to_ty(this, rscope, ast_ty.span, opt_self_ty,
-                                    trait_did, trait_segment, item_segment)
+                        qpath_to_ty(this, rscope, ast_ty.span, opt_self_ty, trait_did,
+                                    &path.segments[path.segments.len()-2],
+                                    path.segments.last().unwrap())
                     }
                     def::DefAssociatedPath(provenance, assoc_ident) => {
                         associated_path_def_to_ty(this, ast_ty, provenance, assoc_ident.name)
index b6003071f8c725c218b81bcfec8c198259f8e953..5b3090be59372f93a1bbf63e2b1fff78e8fef10c 100644 (file)
@@ -3614,9 +3614,7 @@ fn check_struct_fields_on_error<'a,'tcx>(fcx: &FnCtxt<'a,'tcx>,
           let self_ty = fcx.to_ty(&*qpath.self_type);
           let defn = lookup_def(fcx, expr.span, id);
           let (scheme, predicates) = type_scheme_and_predicates_for_def(fcx, expr.span, defn);
-          let mut path = qpath.trait_path.clone();
-          path.segments.push(qpath.item_path.clone());
-          instantiate_path(fcx, &path, scheme, &predicates, Some(self_ty),
+          instantiate_path(fcx, &qpath.path, scheme, &predicates, Some(self_ty),
                            defn, expr.span, expr.id);
 
           // We always require that the type provided as the value for
index 65c1d7adf48769f7b25d523d6ec799dd1869890a..46e1f6f076a7bbd028aabeb3f29c80dbb2e24e2d 100644 (file)
@@ -740,8 +740,7 @@ fn convert_item(ccx: &CollectCtxt, it: &ast::Item) {
             if let Some(ref trait_ref) = *opt_trait_ref {
                 astconv::instantiate_trait_ref(ccx,
                                                &ExplicitRscope,
-                                               &trait_ref.path,
-                                               trait_ref.ref_id,
+                                               trait_ref,
                                                Some(it.id),
                                                Some(selfty),
                                                None);
index aff15761ae7755081b9f7f7c67ccfc3c7cc5c532..2af8107622301fdecdf66873165d6e3623c6ac1e 100644 (file)
@@ -1500,10 +1500,12 @@ fn clean(&self, cx: &DocContext) -> Type {
                 resolve_type(cx, p.clean(cx), self.id)
             }
             TyQPath(ref qp) => {
+                let mut trait_path = qp.path.clone();
+                trait_path.segments.pop();
                 Type::QPath {
-                    name: qp.item_path.identifier.clean(cx),
+                    name: qp.path.segments.last().unwrap().identifier.clean(cx),
                     self_type: box qp.self_type.clean(cx),
-                    trait_: box resolve_type(cx, qp.trait_path.clean(cx), self.id)
+                    trait_: box resolve_type(cx, trait_path.clean(cx), self.id)
                 }
             }
             TyObjectSum(ref lhs, ref bounds) => {
index 5f9776425c3ff641f15a02d888669c390bf6b993..80a5527cb948d35714bade381d3c9e71fe6102b9 100644 (file)
@@ -757,7 +757,7 @@ pub enum Expr_ {
     /// type parameters, e.g. foo::bar::<baz>
     ExprPath(Path),
     /// A "qualified path", e.g. `<Vec<T> as SomeTrait>::SomeType`
-    ExprQPath(P<QPath>),
+    ExprQPath(QPath),
 
     ExprAddrOf(Mutability, P<Expr>),
     ExprBreak(Option<Ident>),
@@ -781,13 +781,12 @@ pub enum Expr_ {
 /// A "qualified path":
 ///
 ///     <Vec<T> as SomeTrait>::SomeAssociatedItem
-///      ^~~~~     ^~~~~~~~~   ^~~~~~~~~~~~~~~~~~
-///      self_type  trait_path  item_path
+///      ^~~~~     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+///      self_type  path
 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
 pub struct QPath {
     pub self_type: P<Ty>,
-    pub trait_path: Path,
-    pub item_path: PathSegment,
+    pub path: Path,
 }
 
 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)]
@@ -1259,7 +1258,7 @@ pub enum Ty_ {
     /// Type parameters are stored in the Path itself
     TyPath(Path),
     /// A "qualified path", e.g. `<Vec<T> as SomeTrait>::SomeType`
-    TyQPath(P<QPath>),
+    TyQPath(QPath),
     /// Something like `A+B`. Note that `B` must always be a path.
     TyObjectSum(P<Ty>, TyParamBounds),
     /// A type like `for<'a> Foo<&'a Bar>`
index baa2fab044f3f6e320a4ab549d88b2eeb3e6f636..90842bbab47d217f76564e4a19a12ad11da8e082 100644 (file)
@@ -41,16 +41,16 @@ fn path_all(&self, sp: Span,
         -> ast::Path;
 
     fn qpath(&self, self_type: P<ast::Ty>,
-             trait_ref: P<ast::TraitRef>,
-             ident: ast::Ident )
-        -> P<ast::QPath>;
+             trait_path: ast::Path,
+             ident: ast::Ident)
+             -> ast::QPath;
     fn qpath_all(&self, self_type: P<ast::Ty>,
-                trait_ref: P<ast::TraitRef>,
+                trait_path: ast::Path,
                 ident: ast::Ident,
                 lifetimes: Vec<ast::Lifetime>,
                 types: Vec<P<ast::Ty>>,
-                bindings: Vec<P<ast::TypeBinding>> )
-        -> P<ast::QPath>;
+                bindings: Vec<P<ast::TypeBinding>>)
+                -> ast::QPath;
 
     // types
     fn ty_mt(&self, ty: P<ast::Ty>, mutbl: ast::Mutability) -> ast::MutTy;
@@ -114,7 +114,7 @@ fn block_all(&self, span: Span,
     // expressions
     fn expr(&self, span: Span, node: ast::Expr_) -> P<ast::Expr>;
     fn expr_path(&self, path: ast::Path) -> P<ast::Expr>;
-    fn expr_qpath(&self, span: Span, qpath: P<ast::QPath>) -> P<ast::Expr>;
+    fn expr_qpath(&self, span: Span, qpath: ast::QPath) -> P<ast::Expr>;
     fn expr_ident(&self, span: Span, id: ast::Ident) -> P<ast::Expr>;
 
     fn expr_self(&self, span: Span) -> P<ast::Expr>;
@@ -346,40 +346,40 @@ fn path_all(&self,
 
     /// Constructs a qualified path.
     ///
-    /// Constructs a path like `<self_type as trait_ref>::ident`.
+    /// Constructs a path like `<self_type as trait_path>::ident`.
     fn qpath(&self,
              self_type: P<ast::Ty>,
-             trait_ref: P<ast::TraitRef>,
+             trait_path: ast::Path,
              ident: ast::Ident)
-             -> P<ast::QPath> {
-        self.qpath_all(self_type, trait_ref, ident, Vec::new(), Vec::new(), Vec::new())
+             -> ast::QPath {
+        self.qpath_all(self_type, trait_path, ident, vec![], vec![], vec![])
     }
 
     /// Constructs a qualified path.
     ///
-    /// Constructs a path like `<self_type as trait_ref>::ident<a, T, A=Bar>`.
+    /// Constructs a path like `<self_type as trait_path>::ident<'a, T, A=Bar>`.
     fn qpath_all(&self,
                  self_type: P<ast::Ty>,
-                 trait_ref: P<ast::TraitRef>,
+                 trait_path: ast::Path,
                  ident: ast::Ident,
                  lifetimes: Vec<ast::Lifetime>,
                  types: Vec<P<ast::Ty>>,
-                 bindings: Vec<P<ast::TypeBinding>> )
-                 -> P<ast::QPath> {
-        let segment = ast::PathSegment {
+                 bindings: Vec<P<ast::TypeBinding>>)
+                 -> ast::QPath {
+        let mut path = trait_path;
+        path.segments.push(ast::PathSegment {
             identifier: ident,
             parameters: ast::AngleBracketedParameters(ast::AngleBracketedParameterData {
                 lifetimes: lifetimes,
                 types: OwnedSlice::from_vec(types),
                 bindings: OwnedSlice::from_vec(bindings),
             })
-        };
+        });
 
-        P(ast::QPath {
+        ast::QPath {
             self_type: self_type,
-            trait_ref: trait_ref,
-            item_path: segment,
-        })
+            path: path
+        }
     }
 
     fn ty_mt(&self, ty: P<ast::Ty>, mutbl: ast::Mutability) -> ast::MutTy {
@@ -607,7 +607,7 @@ fn expr_path(&self, path: ast::Path) -> P<ast::Expr> {
     }
 
     /// Constructs a QPath expression.
-    fn expr_qpath(&self, span: Span, qpath: P<ast::QPath>) -> P<ast::Expr> {
+    fn expr_qpath(&self, span: Span, qpath: ast::QPath) -> P<ast::Expr> {
         self.expr(span, ast::ExprQPath(qpath))
     }
 
index c0421fb6f1cf2050dfb551aca1e0c92c95d99375..c706ce9065dd5f9768db6465546c1cbde971a1b4 100644 (file)
@@ -146,10 +146,6 @@ fn fold_ty(&mut self, t: P<Ty>) -> P<Ty> {
         noop_fold_ty(t, self)
     }
 
-    fn fold_qpath(&mut self, t: P<QPath>) -> P<QPath> {
-        noop_fold_qpath(t, self)
-    }
-
     fn fold_ty_binding(&mut self, t: P<TypeBinding>) -> P<TypeBinding> {
         noop_fold_ty_binding(t, self)
     }
@@ -430,7 +426,10 @@ pub fn noop_fold_ty<T: Folder>(t: P<Ty>, fld: &mut T) -> P<Ty> {
             TyParen(ty) => TyParen(fld.fold_ty(ty)),
             TyPath(path) => TyPath(fld.fold_path(path)),
             TyQPath(qpath) => {
-                TyQPath(fld.fold_qpath(qpath))
+                TyQPath(QPath {
+                    self_type: fld.fold_ty(qpath.self_type),
+                    path: fld.fold_path(qpath.path)
+                })
             }
             TyObjectSum(ty, bounds) => {
                 TyObjectSum(fld.fold_ty(ty),
@@ -450,19 +449,6 @@ pub fn noop_fold_ty<T: Folder>(t: P<Ty>, fld: &mut T) -> P<Ty> {
     })
 }
 
-pub fn noop_fold_qpath<T: Folder>(qpath: P<QPath>, fld: &mut T) -> P<QPath> {
-    qpath.map(|qpath| {
-        QPath {
-            self_type: fld.fold_ty(qpath.self_type),
-            trait_path: fld.fold_path(qpath.trait_path),
-            item_path: PathSegment {
-                identifier: fld.fold_ident(qpath.item_path.identifier),
-                parameters: fld.fold_path_parameters(qpath.item_path.parameters),
-            }
-        }
-    })
-}
-
 pub fn noop_fold_foreign_mod<T: Folder>(ForeignMod {abi, items}: ForeignMod,
                                         fld: &mut T) -> ForeignMod {
     ForeignMod {
@@ -1362,7 +1348,10 @@ pub fn noop_fold_expr<T: Folder>(Expr {id, node, span}: Expr, folder: &mut T) ->
                           e2.map(|x| folder.fold_expr(x)))
             }
             ExprPath(pth) => ExprPath(folder.fold_path(pth)),
-            ExprQPath(qpath) => ExprQPath(folder.fold_qpath(qpath)),
+            ExprQPath(qpath) => ExprQPath(QPath {
+                self_type: folder.fold_ty(qpath.self_type),
+                path: folder.fold_path(qpath.path)
+            }),
             ExprBreak(opt_ident) => ExprBreak(opt_ident.map(|x| folder.fold_ident(x))),
             ExprAgain(opt_ident) => ExprAgain(opt_ident.map(|x| folder.fold_ident(x))),
             ExprRet(e) => ExprRet(e.map(|x| folder.fold_expr(x))),
index b2f597258558d18e8a26f5b7248f05d7be2af0e8..ad290da7d0a6209bc5b2ae8cb1ad06886f495752 100644 (file)
@@ -1525,18 +1525,14 @@ pub fn parse_ty(&mut self) -> P<Ty> {
             // QUALIFIED PATH `<TYPE as TRAIT_REF>::item`
             let self_type = self.parse_ty_sum();
             self.expect_keyword(keywords::As);
-            let trait_path = self.parse_path(LifetimeAndTypesWithoutColons);
+            let mut path = self.parse_path(LifetimeAndTypesWithoutColons);
             self.expect(&token::Gt);
             self.expect(&token::ModSep);
-            let item_name = self.parse_ident();
-            TyQPath(P(QPath {
-                self_type: self_type,
-                trait_path: trait_path,
-                item_path: ast::PathSegment {
-                    identifier: item_name,
-                    parameters: ast::PathParameters::none()
-                }
-            }))
+            path.segments.push(ast::PathSegment {
+                identifier: self.parse_ident(),
+                parameters: ast::PathParameters::none()
+            });
+            TyQPath(QPath { self_type: self_type, path: path })
         } else if self.check(&token::ModSep) ||
                   self.token.is_ident() ||
                   self.token.is_path() {
@@ -2220,7 +2216,7 @@ pub fn parse_bottom_expr(&mut self) -> P<Expr> {
                     // QUALIFIED PATH `<TYPE as TRAIT_REF>::item::<'a, T>`
                     let self_type = self.parse_ty_sum();
                     self.expect_keyword(keywords::As);
-                    let trait_path = self.parse_path(LifetimeAndTypesWithoutColons);
+                    let mut path = self.parse_path(LifetimeAndTypesWithoutColons);
                     self.expect(&token::Gt);
                     self.expect(&token::ModSep);
                     let item_name = self.parse_ident();
@@ -2237,15 +2233,13 @@ pub fn parse_bottom_expr(&mut self) -> P<Expr> {
                     } else {
                         ast::PathParameters::none()
                     };
+                    path.segments.push(ast::PathSegment {
+                        identifier: item_name,
+                        parameters: parameters
+                    });
                     let hi = self.span.hi;
-                    return self.mk_expr(lo, hi, ExprQPath(P(QPath {
-                        self_type: self_type,
-                        trait_path: trait_path,
-                        item_path: ast::PathSegment {
-                            identifier: item_name,
-                            parameters: parameters
-                        }
-                    })));
+                    return self.mk_expr(lo, hi,
+                        ExprQPath(QPath { self_type: self_type, path: path }));
                 }
                 if self.eat_keyword(keywords::Move) {
                     return self.parse_lambda_expr(CaptureByValue);
index 3cfb90a3e68182259ee8e09486aac5020af71ef7..11502c29ebb159551dbebbf8190e2d01211c149d 100644 (file)
@@ -373,7 +373,7 @@ pub fn fn_block_to_string(p: &ast::FnDecl) -> String {
 }
 
 pub fn path_to_string(p: &ast::Path) -> String {
-    $to_string(|s| s.print_path(p, false))
+    $to_string(|s| s.print_path(p, false, 0))
 }
 
 pub fn ident_to_string(id: &ast::Ident) -> String {
@@ -730,7 +730,10 @@ pub fn print_type(&mut self, ty: &ast::Ty) -> IoResult<()> {
                                       None));
             }
             ast::TyPath(ref path) => {
-                try!(self.print_path(path, false));
+                try!(self.print_path(path, false, 0));
+            }
+            ast::TyQPath(ref qpath) => {
+                try!(self.print_qpath(qpath, false))
             }
             ast::TyObjectSum(ref ty, ref bounds) => {
                 try!(self.print_type(&**ty));
@@ -739,9 +742,6 @@ pub fn print_type(&mut self, ty: &ast::Ty) -> IoResult<()> {
             ast::TyPolyTraitRef(ref bounds) => {
                 try!(self.print_bounds("", &bounds[..]));
             }
-            ast::TyQPath(ref qpath) => {
-                try!(self.print_qpath(&**qpath, false))
-            }
             ast::TyFixedLengthVec(ref ty, ref v) => {
                 try!(word(&mut self.s, "["));
                 try!(self.print_type(&**ty));
@@ -1018,7 +1018,7 @@ pub fn print_item(&mut self, item: &ast::Item) -> IoResult<()> {
             ast::ItemMac(codemap::Spanned { node: ast::MacInvocTT(ref pth, ref tts, _),
                                             ..}) => {
                 try!(self.print_visibility(item.vis));
-                try!(self.print_path(pth, false));
+                try!(self.print_path(pth, false, 0));
                 try!(word(&mut self.s, "! "));
                 try!(self.print_ident(item.ident));
                 try!(self.cbox(indent_unit));
@@ -1033,7 +1033,7 @@ pub fn print_item(&mut self, item: &ast::Item) -> IoResult<()> {
     }
 
     fn print_trait_ref(&mut self, t: &ast::TraitRef) -> IoResult<()> {
-        self.print_path(&t.path, false)
+        self.print_path(&t.path, false, 0)
     }
 
     fn print_formal_lifetime_list(&mut self, lifetimes: &[ast::LifetimeDef]) -> IoResult<()> {
@@ -1297,7 +1297,7 @@ pub fn print_method(&mut self, meth: &ast::Method) -> IoResult<()> {
             ast::MethMac(codemap::Spanned { node: ast::MacInvocTT(ref pth, ref tts, _),
                                             ..}) => {
                 // code copied from ItemMac:
-                try!(self.print_path(pth, false));
+                try!(self.print_path(pth, false, 0));
                 try!(word(&mut self.s, "! "));
                 try!(self.cbox(indent_unit));
                 try!(self.popen());
@@ -1514,7 +1514,7 @@ pub fn print_mac(&mut self, m: &ast::Mac, delim: token::DelimToken)
         match m.node {
             // I think it's reasonable to hide the ctxt here:
             ast::MacInvocTT(ref pth, ref tts, _) => {
-                try!(self.print_path(pth, false));
+                try!(self.print_path(pth, false, 0));
                 try!(word(&mut self.s, "!"));
                 match delim {
                     token::Paren => try!(self.popen()),
@@ -1584,7 +1584,7 @@ fn print_expr_struct(&mut self,
                          path: &ast::Path,
                          fields: &[ast::Field],
                          wth: &Option<P<ast::Expr>>) -> IoResult<()> {
-        try!(self.print_path(path, true));
+        try!(self.print_path(path, true, 0));
         if !(fields.is_empty() && wth.is_none()) {
             try!(word(&mut self.s, "{"));
             try!(self.commasep_cmnt(
@@ -1852,8 +1852,8 @@ pub fn print_expr(&mut self, expr: &ast::Expr) -> IoResult<()> {
                     try!(self.print_expr(&**e));
                 }
             }
-            ast::ExprPath(ref path) => try!(self.print_path(path, true)),
-            ast::ExprQPath(ref qpath) => try!(self.print_qpath(&**qpath, true)),
+            ast::ExprPath(ref path) => try!(self.print_path(path, true, 0)),
+            ast::ExprQPath(ref qpath) => try!(self.print_qpath(qpath, true)),
             ast::ExprBreak(opt_ident) => {
                 try!(word(&mut self.s, "break"));
                 try!(space(&mut self.s));
@@ -2014,16 +2014,14 @@ pub fn print_for_decl(&mut self, loc: &ast::Local,
 
     fn print_path(&mut self,
                   path: &ast::Path,
-                  colons_before_params: bool)
+                  colons_before_params: bool,
+                  depth: usize)
                   -> IoResult<()>
     {
         try!(self.maybe_print_comment(path.span.lo));
-        if path.global {
-            try!(word(&mut self.s, "::"));
-        }
 
-        let mut first = true;
-        for segment in &path.segments {
+        let mut first = !path.global;
+        for segment in &path.segments[..path.segments.len()-depth] {
             if first {
                 first = false
             } else {
@@ -2047,11 +2045,12 @@ fn print_qpath(&mut self,
         try!(self.print_type(&*qpath.self_type));
         try!(space(&mut self.s));
         try!(self.word_space("as"));
-        try!(self.print_path(&qpath.trait_path, false));
+        try!(self.print_path(&qpath.path, false, 1));
         try!(word(&mut self.s, ">"));
         try!(word(&mut self.s, "::"));
-        try!(self.print_ident(qpath.item_path.identifier));
-        self.print_path_parameters(&qpath.item_path.parameters, colons_before_params)
+        let item_segment = qpath.path.segments.last().unwrap();
+        try!(self.print_ident(item_segment.identifier));
+        self.print_path_parameters(&item_segment.parameters, colons_before_params)
     }
 
     fn print_path_parameters(&mut self,
@@ -2156,7 +2155,7 @@ pub fn print_pat(&mut self, pat: &ast::Pat) -> IoResult<()> {
                 }
             }
             ast::PatEnum(ref path, ref args_) => {
-                try!(self.print_path(path, true));
+                try!(self.print_path(path, true, 0));
                 match *args_ {
                     None => try!(word(&mut self.s, "(..)")),
                     Some(ref args) => {
@@ -2170,7 +2169,7 @@ pub fn print_pat(&mut self, pat: &ast::Pat) -> IoResult<()> {
                 }
             }
             ast::PatStruct(ref path, ref fields, etc) => {
-                try!(self.print_path(path, true));
+                try!(self.print_path(path, true, 0));
                 try!(self.nbsp());
                 try!(self.word_space("{"));
                 try!(self.commasep_cmnt(
@@ -2555,7 +2554,7 @@ pub fn print_where_clause(&mut self, generics: &ast::Generics)
                     }
                 }
                 &ast::WherePredicate::EqPredicate(ast::WhereEqPredicate{ref path, ref ty, ..}) => {
-                    try!(self.print_path(path, false));
+                    try!(self.print_path(path, false, 0));
                     try!(space(&mut self.s));
                     try!(self.word_space("="));
                     try!(self.print_type(&**ty));
@@ -2592,7 +2591,7 @@ pub fn print_meta_item(&mut self, item: &ast::MetaItem) -> IoResult<()> {
     pub fn print_view_path(&mut self, vp: &ast::ViewPath) -> IoResult<()> {
         match vp.node {
             ast::ViewPathSimple(ident, ref path) => {
-                try!(self.print_path(path, false));
+                try!(self.print_path(path, false, 0));
 
                 // FIXME(#6993) can't compare identifiers directly here
                 if path.segments.last().unwrap().identifier.name !=
@@ -2606,7 +2605,7 @@ pub fn print_view_path(&mut self, vp: &ast::ViewPath) -> IoResult<()> {
             }
 
             ast::ViewPathGlob(ref path) => {
-                try!(self.print_path(path, false));
+                try!(self.print_path(path, false, 0));
                 word(&mut self.s, "::*")
             }
 
@@ -2614,7 +2613,7 @@ pub fn print_view_path(&mut self, vp: &ast::ViewPath) -> IoResult<()> {
                 if path.segments.is_empty() {
                     try!(word(&mut self.s, "{"));
                 } else {
-                    try!(self.print_path(path, false));
+                    try!(self.print_path(path, false, 0));
                     try!(word(&mut self.s, "::{"));
                 }
                 try!(self.commasep(Inconsistent, &idents[..], |s, w| {
index 4e90adea90c6211a4771446a3851a876cc589736..55372585062d8b44ff23145d1d91ba593d9a224a 100644 (file)
@@ -125,9 +125,6 @@ fn visit_mac(&mut self, _mac: &'v Mac) {
     fn visit_path(&mut self, path: &'v Path, _id: ast::NodeId) {
         walk_path(self, path)
     }
-    fn visit_qpath(&mut self, qpath: &'v QPath, _id: ast::NodeId) {
-        walk_qpath(self, qpath)
-    }
     fn visit_path_segment(&mut self, path_span: Span, path_segment: &'v PathSegment) {
         walk_path_segment(self, path_span, path_segment)
     }
@@ -403,7 +400,8 @@ pub fn walk_ty<'v, V: Visitor<'v>>(visitor: &mut V, typ: &'v Ty) {
             visitor.visit_path(path, typ.id);
         }
         TyQPath(ref qpath) => {
-            visitor.visit_qpath(&**qpath, typ.id);
+            visitor.visit_ty(&*qpath.self_type);
+            visitor.visit_path(&qpath.path, typ.id);
         }
         TyObjectSum(ref ty, ref bounds) => {
             visitor.visit_ty(&**ty);
@@ -436,12 +434,6 @@ pub fn walk_path<'v, V: Visitor<'v>>(visitor: &mut V, path: &'v Path) {
     }
 }
 
-pub fn walk_qpath<'v, V: Visitor<'v>>(visitor: &mut V, qpath: &'v QPath) {
-    visitor.visit_ty(&*qpath.self_type);
-    walk_path(visitor, &qpath.trait_path);
-    visitor.visit_path_segment(qpath.trait_path.span, &qpath.item_path);
-}
-
 pub fn walk_path_segment<'v, V: Visitor<'v>>(visitor: &mut V,
                                              path_span: Span,
                                              segment: &'v PathSegment) {
@@ -871,7 +863,8 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr) {
             visitor.visit_path(path, expression.id)
         }
         ExprQPath(ref qpath) => {
-            visitor.visit_qpath(&**qpath, expression.id)
+            visitor.visit_ty(&*qpath.self_type);
+            visitor.visit_path(&qpath.path, expression.id);
         }
         ExprBreak(_) | ExprAgain(_) => {}
         ExprRet(ref optional_expression) => {