diff options
| author | bors <bors@rust-lang.org> | 2018-09-04 02:50:59 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2018-09-04 02:50:59 +0000 |
| commit | 8b80390ead05671f0344a6208891f152cbb7a68c (patch) | |
| tree | baf834a5973ec408098c0d080d5e896b78bd832f | |
| parent | c7fc1a55a2fe3766e66f6424a34bbc7625efc009 (diff) | |
| parent | 9883dd73aa799ec73fb1ec31a189871265b137bf (diff) | |
Auto merge of #53927 - ljedrz:save_analysis_cleanups, r=oli-obk
A few cleanups and minor improvements to save_analysis - calculate the capacity of some `Vec`s - change`to_owned()` to `clone()` for the purposes of `lower_attributes` - remove a superfluous `clone()` - prefer `to_owned()` to `to_string()` - a few other minor improvements
| -rw-r--r-- | src/librustc_save_analysis/dump_visitor.rs | 22 | ||||
| -rw-r--r-- | src/librustc_save_analysis/lib.rs | 6 | ||||
| -rw-r--r-- | src/librustc_save_analysis/sig.rs | 4 | ||||
| -rw-r--r-- | src/librustc_save_analysis/span_utils.rs | 7 |
4 files changed, 16 insertions, 23 deletions
diff --git a/src/librustc_save_analysis/dump_visitor.rs b/src/librustc_save_analysis/dump_visitor.rs index adc63497daf..d719d257f35 100644 --- a/src/librustc_save_analysis/dump_visitor.rs +++ b/src/librustc_save_analysis/dump_visitor.rs @@ -147,9 +147,9 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> { 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 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> { 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 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> { 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 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> { 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 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> { /// 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 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> Visitor<'l> for DumpVisitor<'l, 'tc } } 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 { diff --git a/src/librustc_save_analysis/lib.rs b/src/librustc_save_analysis/lib.rs index 56dfac84611..48e4d93e07b 100644 --- a/src/librustc_save_analysis/lib.rs +++ b/src/librustc_save_analysis/lib.rs @@ -101,7 +101,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> { 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 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> { // 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 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> { 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) => { diff --git a/src/librustc_save_analysis/sig.rs b/src/librustc_save_analysis/sig.rs index 13032562879..9cf64a9d1ca 100644 --- a/src/librustc_save_analysis/sig.rs +++ b/src/librustc_save_analysis/sig.rs @@ -435,7 +435,7 @@ impl Sig for ast::Item { }, ]; 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 @@ impl Sig for ast::Generics { 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 { diff --git a/src/librustc_save_analysis/span_utils.rs b/src/librustc_save_analysis/span_utils.rs index cc5c722e4f6..2550a312c5d 100644 --- a/src/librustc_save_analysis/span_utils.rs +++ b/src/librustc_save_analysis/span_utils.rs @@ -263,11 +263,8 @@ impl<'a> SpanUtils<'a> { /// 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 { |
