]> git.lizzy.rs Git - rust.git/commitdiff
A few cleanups and minor improvements to save_analysis
authorljedrz <ljedrz@gmail.com>
Mon, 3 Sep 2018 12:31:57 +0000 (14:31 +0200)
committerljedrz <ljedrz@gmail.com>
Mon, 3 Sep 2018 16:37:54 +0000 (18:37 +0200)
src/librustc_save_analysis/dump_visitor.rs
src/librustc_save_analysis/lib.rs
src/librustc_save_analysis/sig.rs
src/librustc_save_analysis/span_utils.rs

index adc63497daf2addfff96421cf82f16309379ecad..d719d257f352c6a9d61cd017a2cab3a665f24183 100644 (file)
@@ -147,9 +147,9 @@ pub fn dump_crate_info(&mut self, name: &str, krate: &ast::Crate) {
         let crate_root = source_file.map(|source_file| {
             let source_file = Path::new(source_file);
             match source_file.file_name() {
-                Some(_) => source_file.parent().unwrap().display().to_string(),
-                None => source_file.display().to_string(),
-            }
+                Some(_) => source_file.parent().unwrap().display(),
+                None => source_file.display(),
+            }.to_string()
         });
 
         let data = CratePreludeData {
@@ -176,8 +176,8 @@ fn process_path_prefixes(&self, path: &ast::Path) -> Vec<(Span, String)> {
         let segments = &path.segments[if path.is_global() { 1 } else { 0 }..];
 
         let mut result = Vec::with_capacity(segments.len());
+        let mut segs = Vec::with_capacity(segments.len());
 
-        let mut segs = vec![];
         for (i, seg) in segments.iter().enumerate() {
             segs.push(seg.clone());
             let sub_path = ast::Path {
@@ -591,9 +591,7 @@ fn process_enum(
 
         for variant in &enum_definition.variants {
             let name = variant.node.ident.name.to_string();
-            let mut qualname = enum_data.qualname.clone();
-            qualname.push_str("::");
-            qualname.push_str(&name);
+            let qualname = format!("{}::{}", enum_data.qualname, name);
 
             match variant.node.data {
                 ast::VariantData::Struct(ref fields, _) => {
@@ -973,9 +971,9 @@ fn process_var_decl_multi(&mut self, pats: &'l [P<ast::Pat>]) {
             match self.save_ctxt.get_path_def(id) {
                 HirDef::Local(id) => {
                     let mut value = if immut == ast::Mutability::Immutable {
-                        self.span.snippet(ident.span).to_string()
+                        self.span.snippet(ident.span)
                     } else {
-                        "<mutable>".to_string()
+                        "<mutable>".to_owned()
                     };
                     let hir_id = self.tcx.hir.node_to_hir_id(id);
                     let typ = self.save_ctxt
@@ -1103,10 +1101,9 @@ fn process_var_decl(&mut self, p: &'l ast::Pat, value: String) {
     /// mac_uses and mac_defs sets to prevent multiples.
     fn process_macro_use(&mut self, span: Span) {
         let source_span = span.source_callsite();
-        if self.macro_calls.contains(&source_span) {
+        if !self.macro_calls.insert(source_span) {
             return;
         }
-        self.macro_calls.insert(source_span);
 
         let data = match self.save_ctxt.get_macro_use_data(span) {
             None => return,
@@ -1608,8 +1605,7 @@ fn visit_expr(&mut self, ex: &'l ast::Expr) {
                 }
             }
             ast::ExprKind::Closure(_, _, _, ref decl, ref body, _fn_decl_span) => {
-                let mut id = String::from("$");
-                id.push_str(&ex.id.to_string());
+                let id = format!("${}", ex.id);
 
                 // walk arg and return types
                 for arg in &decl.inputs {
index 56dfac84611922b54012e64663fdff42aad296a0..48e4d93e07b36f82fb06aba96834cdd0f82ba3e6 100644 (file)
@@ -101,7 +101,7 @@ fn span_from_span(&self, span: Span) -> SpanData {
         let end = cm.lookup_char_pos(span.hi());
 
         SpanData {
-            file_name: start.file.name.clone().to_string().into(),
+            file_name: start.file.name.to_string().into(),
             byte_start: span.lo().0,
             byte_end: span.hi().0,
             line_start: Row::new_one_indexed(start.line as u32),
@@ -113,7 +113,7 @@ fn span_from_span(&self, span: Span) -> SpanData {
 
     // List external crates used by the current crate.
     pub fn get_external_crates(&self) -> Vec<ExternalCrateData> {
-        let mut result = Vec::new();
+        let mut result = Vec::with_capacity(self.tcx.crates().len());
 
         for &n in self.tcx.crates().iter() {
             let span = match *self.tcx.extern_crate(n.as_def_id()) {
@@ -321,7 +321,7 @@ pub fn get_item_data(&self, item: &ast::Item) -> Option<Data> {
                     decl_id: None,
                     docs: self.docs_for_attrs(&item.attrs),
                     sig: sig::item_signature(item, self),
-                    attributes: lower_attributes(item.attrs.to_owned(), self),
+                    attributes: lower_attributes(item.attrs.clone(), self),
                 }))
             }
             ast::ItemKind::Impl(.., ref trait_ref, ref typ, ref impls) => {
index 130325628796ecbd74f0d253e290c02954631ac7..9cf64a9d1ca81ba1b6f583e0f3263ed66d102ac4 100644 (file)
@@ -435,7 +435,7 @@ fn make(&self, offset: usize, _parent_id: Option<NodeId>, scx: &SaveContext) ->
                     },
                 ];
                 text.push_str(&name);
-                // Could be either `mod foo;` or `mod foo { ... }`, but we'll just puck one.
+                // Could be either `mod foo;` or `mod foo { ... }`, but we'll just pick one.
                 text.push(';');
 
                 Ok(Signature {
@@ -630,7 +630,7 @@ fn make(&self, offset: usize, _parent_id: Option<NodeId>, scx: &SaveContext) ->
 
         let mut text = "<".to_owned();
 
-        let mut defs = vec![];
+        let mut defs = Vec::with_capacity(self.params.len());
         for param in &self.params {
             let mut param_text = param.ident.to_string();
             defs.push(SigElement {
index cc5c722e4f6193bdc99ef229b474fc7ed3b47a5b..2550a312c5d6de6d13856b0fc111a6fb63f51aa5 100644 (file)
@@ -263,11 +263,8 @@ fn sub_span_after<F: Fn(Token) -> bool>(&self, span: Span, f: F) -> Option<Span>
     /// such as references to macro internal variables.
     pub fn filter_generated(&self, sub_span: Option<Span>, parent: Span) -> bool {
         if !generated_code(parent) {
-            if sub_span.is_none() {
-                // Edge case - this occurs on generated code with incorrect expansion info.
-                return true;
-            }
-            return false;
+            // Edge case - this occurs on generated code with incorrect expansion info.
+            return sub_span.is_none()
         }
         // If sub_span is none, filter out generated code.
         let sub_span = match sub_span {