]> git.lizzy.rs Git - rust.git/commitdiff
Review changes
authorNick Cameron <ncameron@mozilla.com>
Wed, 28 Jan 2015 20:52:19 +0000 (09:52 +1300)
committerNick Cameron <ncameron@mozilla.com>
Thu, 29 Jan 2015 22:58:10 +0000 (11:58 +1300)
src/librustc_trans/save/mod.rs

index 354a9cb817bdf2f8b628a647728e7f92e3fe2d1d..0dc871703f983c9dff1f98c095b8b3b2ded6c98d 100644 (file)
@@ -130,9 +130,7 @@ fn process_path_prefixes(&self, path: &ast::Path) -> Vec<(Span, String)> {
                                      global: path.global,
                                      segments: segs};
             let qualname = if i == 0 && path.global {
-                let mut result = "::".to_string();
-                result.push_str(&path_to_string(&sub_path)[]);
-                result
+                format("::{}", path_to_string(&sub_path))
             } else {
                 path_to_string(&sub_path)
             };
@@ -143,6 +141,10 @@ fn process_path_prefixes(&self, path: &ast::Path) -> Vec<(Span, String)> {
         result
     }
 
+    // The global arg allows us to override the global-ness of the path (which
+    // actually means 'does the path start with `::`', rather than 'is the path
+    // semantically global). We use the override for `use` imports (etc.) where
+    // the syntax is non-global, but the semantics are global.
     fn write_sub_paths(&mut self, path: &ast::Path, global: bool) {
         let sub_paths = self.process_path_prefixes(path);
         for (i, &(ref span, ref qualname)) in sub_paths.iter().enumerate() {
@@ -159,7 +161,7 @@ fn write_sub_paths(&mut self, path: &ast::Path, global: bool) {
     }
 
     // As write_sub_paths, but does not process the last ident in the path (assuming it
-    // will be processed elsewhere).
+    // will be processed elsewhere). See note on write_sub_paths about global.
     fn write_sub_paths_truncated(&mut self, path: &ast::Path, global: bool) {
         let sub_paths = self.process_path_prefixes(path);
         let len = sub_paths.len();
@@ -291,7 +293,7 @@ fn process_method(&mut self, method: &ast::Method) {
 
         let mut scope_id;
         // The qualname for a method is the trait name or name of the struct in an impl in
-        // which the method is declared in followed by the method's name.
+        // which the method is declared in, followed by the method's name.
         let qualname = match ty::impl_of_method(&self.analysis.ty_cx,
                                                 ast_util::local_def(method.id)) {
             Some(impl_id) => match self.analysis.ty_cx.map.get(impl_id.node) {
@@ -311,7 +313,7 @@ fn process_method(&mut self, method: &ast::Method) {
                                 },
                                 None => {}
                             }
-                            result.push_str(">::");
+                            result.push_str(">");
                             result
                         }
                         _ => {
@@ -336,8 +338,7 @@ fn process_method(&mut self, method: &ast::Method) {
                     scope_id = def_id.node;
                     match self.analysis.ty_cx.map.get(def_id.node) {
                         NodeItem(_) => {
-                            let mut result = ty::item_path_str(&self.analysis.ty_cx, def_id);
-                            result.push_str("::");
+                            format!("::{}", ty::item_path_str(&self.analysis.ty_cx, def_id))
                             result
                         }
                         _ => {
@@ -355,7 +356,7 @@ fn process_method(&mut self, method: &ast::Method) {
             },
         };
 
-        let qualname = format!("::{}{}", qualname, get_ident(method.pe_ident()).get());
+        let qualname = format!("{}::{}", qualname, get_ident(method.pe_ident()).get());
         let qualname = &qualname[];
 
         // record the decl for this def (if it has one)