Skip to content

Commit

Permalink
A few cleanups and minor improvements to save_analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
ljedrz committed Sep 3, 2018
1 parent 2687112 commit 9883dd7
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 23 deletions.
22 changes: 9 additions & 13 deletions src/librustc_save_analysis/dump_visitor.rs
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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, _) => {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_save_analysis/lib.rs
Expand Up @@ -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),
Expand All @@ -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()) {
Expand Down Expand Up @@ -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) => {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_save_analysis/sig.rs
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
7 changes: 2 additions & 5 deletions src/librustc_save_analysis/span_utils.rs
Expand Up @@ -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 {
Expand Down

0 comments on commit 9883dd7

Please sign in to comment.