mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-28 20:16:58 +03:00
Auto merge of #45848 - nrc:rls-bugs-4, r=eddyb
save-analysis: two fixes + rustfmt Fix two regressions and run rustfmt. r? @eddyb
This commit is contained in:
@@ -32,22 +32,22 @@
|
||||
|
||||
use std::path::Path;
|
||||
|
||||
use syntax::ast::{self, NodeId, PatKind, Attribute, CRATE_NODE_ID};
|
||||
use syntax::ast::{self, Attribute, NodeId, PatKind, CRATE_NODE_ID};
|
||||
use syntax::parse::token;
|
||||
use syntax::symbol::keywords;
|
||||
use syntax::visit::{self, Visitor};
|
||||
use syntax::print::pprust::{path_to_string, ty_to_string, bounds_to_string, generics_to_string};
|
||||
use syntax::print::pprust::{bounds_to_string, generics_to_string, path_to_string, ty_to_string};
|
||||
use syntax::ptr::P;
|
||||
use syntax::codemap::Spanned;
|
||||
use syntax_pos::*;
|
||||
|
||||
use {escape, generated_code, SaveContext, PathCollector, lower_attributes};
|
||||
use json_dumper::{JsonDumper, DumpOutput};
|
||||
use {escape, generated_code, lower_attributes, PathCollector, SaveContext};
|
||||
use json_dumper::{DumpOutput, JsonDumper};
|
||||
use span_utils::SpanUtils;
|
||||
use sig;
|
||||
|
||||
use rls_data::{CratePreludeData, GlobalCrateId, Import, ImportKind, SpanData,
|
||||
Ref, RefKind, Def, DefKind, Relation, RelationKind};
|
||||
use rls_data::{CratePreludeData, Def, DefKind, GlobalCrateId, Import, ImportKind, Ref, RefKind,
|
||||
Relation, RelationKind, SpanData};
|
||||
|
||||
macro_rules! down_cast_data {
|
||||
($id:ident, $kind:ident, $sp:expr) => {
|
||||
@@ -77,9 +77,10 @@ pub struct DumpVisitor<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> {
|
||||
}
|
||||
|
||||
impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
|
||||
pub fn new(save_ctxt: SaveContext<'l, 'tcx>,
|
||||
dumper: &'ll mut JsonDumper<O>)
|
||||
-> DumpVisitor<'l, 'tcx, 'll, O> {
|
||||
pub fn new(
|
||||
save_ctxt: SaveContext<'l, 'tcx>,
|
||||
dumper: &'ll mut JsonDumper<O>,
|
||||
) -> DumpVisitor<'l, 'tcx, 'll, O> {
|
||||
let span_utils = SpanUtils::new(&save_ctxt.tcx.sess);
|
||||
DumpVisitor {
|
||||
tcx: save_ctxt.tcx,
|
||||
@@ -93,7 +94,8 @@ pub fn new(save_ctxt: SaveContext<'l, 'tcx>,
|
||||
}
|
||||
|
||||
fn nest_scope<F>(&mut self, scope_id: NodeId, f: F)
|
||||
where F: FnOnce(&mut DumpVisitor<'l, 'tcx, 'll, O>)
|
||||
where
|
||||
F: FnOnce(&mut DumpVisitor<'l, 'tcx, 'll, O>),
|
||||
{
|
||||
let parent_scope = self.cur_scope;
|
||||
self.cur_scope = scope_id;
|
||||
@@ -102,7 +104,8 @@ fn nest_scope<F>(&mut self, scope_id: NodeId, f: F)
|
||||
}
|
||||
|
||||
fn nest_tables<F>(&mut self, item_id: NodeId, f: F)
|
||||
where F: FnOnce(&mut DumpVisitor<'l, 'tcx, 'll, O>)
|
||||
where
|
||||
F: FnOnce(&mut DumpVisitor<'l, 'tcx, 'll, O>),
|
||||
{
|
||||
let item_def_id = self.tcx.hir.local_def_id(item_id);
|
||||
if self.tcx.has_typeck_tables(item_def_id) {
|
||||
@@ -133,8 +136,11 @@ pub fn dump_crate_info(&mut self, name: &str, krate: &ast::Crate) {
|
||||
let data = CratePreludeData {
|
||||
crate_id: GlobalCrateId {
|
||||
name: name.into(),
|
||||
disambiguator: self.tcx.sess.local_crate_disambiguator()
|
||||
.to_fingerprint().as_value(),
|
||||
disambiguator: self.tcx
|
||||
.sess
|
||||
.local_crate_disambiguator()
|
||||
.to_fingerprint()
|
||||
.as_value(),
|
||||
},
|
||||
crate_root: crate_root.unwrap_or("<no source>".to_owned()),
|
||||
external_crates: self.save_ctxt.get_external_crates(),
|
||||
@@ -210,10 +216,10 @@ fn write_sub_path_trait_truncated(&mut self, path: &ast::Path) {
|
||||
if len <= 1 {
|
||||
return;
|
||||
}
|
||||
let sub_paths = &sub_paths[.. (len-1)];
|
||||
let sub_paths = &sub_paths[..(len - 1)];
|
||||
|
||||
// write the trait part of the sub-path
|
||||
let (ref span, _) = sub_paths[len-2];
|
||||
let (ref span, _) = sub_paths[len - 2];
|
||||
let span = self.span_from_span(*span);
|
||||
self.dumper.dump_ref(Ref {
|
||||
kind: RefKind::Type,
|
||||
@@ -225,7 +231,7 @@ fn write_sub_path_trait_truncated(&mut self, path: &ast::Path) {
|
||||
if len <= 2 {
|
||||
return;
|
||||
}
|
||||
let sub_paths = &sub_paths[..len-2];
|
||||
let sub_paths = &sub_paths[..len - 2];
|
||||
for &(ref span, _) in sub_paths {
|
||||
let span = self.span_from_span(*span);
|
||||
self.dumper.dump_ref(Ref {
|
||||
@@ -243,11 +249,13 @@ fn lookup_def_id(&self, ref_id: NodeId) -> Option<DefId> {
|
||||
}
|
||||
}
|
||||
|
||||
fn process_def_kind(&mut self,
|
||||
ref_id: NodeId,
|
||||
span: Span,
|
||||
sub_span: Option<Span>,
|
||||
def_id: DefId) {
|
||||
fn process_def_kind(
|
||||
&mut self,
|
||||
ref_id: NodeId,
|
||||
span: Span,
|
||||
sub_span: Option<Span>,
|
||||
def_id: DefId,
|
||||
) {
|
||||
if self.span.filter_generated(sub_span, span) {
|
||||
return;
|
||||
}
|
||||
@@ -309,9 +317,7 @@ fn process_def_kind(&mut self,
|
||||
HirDef::PrimTy(_) |
|
||||
HirDef::GlobalAsm(_) |
|
||||
HirDef::Err => {
|
||||
span_bug!(span,
|
||||
"process_def_kind for unexpected item: {:?}",
|
||||
def);
|
||||
span_bug!(span, "process_def_kind for unexpected item: {:?}", def);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -334,49 +340,55 @@ fn process_formals(&mut self, formals: &'l [ast::Arg], qualname: &str) {
|
||||
let id = ::id_from_node_id(id, &self.save_ctxt);
|
||||
let span = self.span_from_span(sub_span.expect("No span found for variable"));
|
||||
|
||||
self.dumper.dump_def(false, Def {
|
||||
kind: DefKind::Local,
|
||||
id,
|
||||
span,
|
||||
name: i.to_string(),
|
||||
qualname: format!("{}::{}", qualname, i.to_string()),
|
||||
value: typ,
|
||||
parent: None,
|
||||
children: vec![],
|
||||
decl_id: None,
|
||||
docs: String::new(),
|
||||
sig: None,
|
||||
attributes:vec![],
|
||||
});
|
||||
self.dumper.dump_def(
|
||||
false,
|
||||
Def {
|
||||
kind: DefKind::Local,
|
||||
id,
|
||||
span,
|
||||
name: i.to_string(),
|
||||
qualname: format!("{}::{}", qualname, i.to_string()),
|
||||
value: typ,
|
||||
parent: None,
|
||||
children: vec![],
|
||||
decl_id: None,
|
||||
docs: String::new(),
|
||||
sig: None,
|
||||
attributes: vec![],
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn process_method(&mut self,
|
||||
sig: &'l ast::MethodSig,
|
||||
body: Option<&'l ast::Block>,
|
||||
id: ast::NodeId,
|
||||
name: ast::Ident,
|
||||
generics: &'l ast::Generics,
|
||||
vis: ast::Visibility,
|
||||
span: Span) {
|
||||
fn process_method(
|
||||
&mut self,
|
||||
sig: &'l ast::MethodSig,
|
||||
body: Option<&'l ast::Block>,
|
||||
id: ast::NodeId,
|
||||
name: ast::Ident,
|
||||
generics: &'l ast::Generics,
|
||||
vis: ast::Visibility,
|
||||
span: Span,
|
||||
) {
|
||||
debug!("process_method: {}:{}", id, name);
|
||||
|
||||
if let Some(mut method_data) = self.save_ctxt.get_method_data(id, name.name, span) {
|
||||
|
||||
let sig_str = ::make_signature(&sig.decl, &generics);
|
||||
if body.is_some() {
|
||||
self.nest_tables(id, |v| {
|
||||
v.process_formals(&sig.decl.inputs, &method_data.qualname)
|
||||
});
|
||||
self.nest_tables(
|
||||
id,
|
||||
|v| v.process_formals(&sig.decl.inputs, &method_data.qualname),
|
||||
);
|
||||
}
|
||||
|
||||
self.process_generic_params(&generics, span, &method_data.qualname, id);
|
||||
|
||||
method_data.value = sig_str;
|
||||
method_data.sig = sig::method_signature(id, name, generics, sig, &self.save_ctxt);
|
||||
self.dumper.dump_def(vis == ast::Visibility::Public, method_data);
|
||||
self.dumper
|
||||
.dump_def(vis == ast::Visibility::Public, method_data);
|
||||
}
|
||||
|
||||
// walk arg and return types
|
||||
@@ -397,57 +409,66 @@ fn process_method(&mut self,
|
||||
fn process_struct_field_def(&mut self, field: &ast::StructField, parent_id: NodeId) {
|
||||
let field_data = self.save_ctxt.get_field_data(field, parent_id);
|
||||
if let Some(field_data) = field_data {
|
||||
self.dumper.dump_def(field.vis == ast::Visibility::Public, field_data);
|
||||
self.dumper
|
||||
.dump_def(field.vis == ast::Visibility::Public, field_data);
|
||||
}
|
||||
}
|
||||
|
||||
// Dump generic params bindings, then visit_generics
|
||||
fn process_generic_params(&mut self,
|
||||
generics: &'l ast::Generics,
|
||||
full_span: Span,
|
||||
prefix: &str,
|
||||
id: NodeId) {
|
||||
fn process_generic_params(
|
||||
&mut self,
|
||||
generics: &'l ast::Generics,
|
||||
full_span: Span,
|
||||
prefix: &str,
|
||||
id: NodeId,
|
||||
) {
|
||||
for param in &generics.ty_params {
|
||||
let param_ss = param.span;
|
||||
let name = escape(self.span.snippet(param_ss));
|
||||
// Append $id to name to make sure each one is unique
|
||||
let qualname = format!("{}::{}${}",
|
||||
prefix,
|
||||
name,
|
||||
id);
|
||||
let qualname = format!("{}::{}${}", prefix, name, id);
|
||||
if !self.span.filter_generated(Some(param_ss), full_span) {
|
||||
let id = ::id_from_node_id(param.id, &self.save_ctxt);
|
||||
let span = self.span_from_span(param_ss);
|
||||
|
||||
self.dumper.dump_def(false, Def {
|
||||
kind: DefKind::Type,
|
||||
id,
|
||||
span,
|
||||
name,
|
||||
qualname,
|
||||
value: String::new(),
|
||||
parent: None,
|
||||
children: vec![],
|
||||
decl_id: None,
|
||||
docs: String::new(),
|
||||
sig: None,
|
||||
attributes: vec![],
|
||||
});
|
||||
self.dumper.dump_def(
|
||||
false,
|
||||
Def {
|
||||
kind: DefKind::Type,
|
||||
id,
|
||||
span,
|
||||
name,
|
||||
qualname,
|
||||
value: String::new(),
|
||||
parent: None,
|
||||
children: vec![],
|
||||
decl_id: None,
|
||||
docs: String::new(),
|
||||
sig: None,
|
||||
attributes: vec![],
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
self.visit_generics(generics);
|
||||
}
|
||||
|
||||
fn process_fn(&mut self,
|
||||
item: &'l ast::Item,
|
||||
decl: &'l ast::FnDecl,
|
||||
ty_params: &'l ast::Generics,
|
||||
body: &'l ast::Block) {
|
||||
fn process_fn(
|
||||
&mut self,
|
||||
item: &'l ast::Item,
|
||||
decl: &'l ast::FnDecl,
|
||||
ty_params: &'l ast::Generics,
|
||||
body: &'l ast::Block,
|
||||
) {
|
||||
if let Some(fn_data) = self.save_ctxt.get_item_data(item) {
|
||||
down_cast_data!(fn_data, DefData, item.span);
|
||||
self.nest_tables(item.id, |v| v.process_formals(&decl.inputs, &fn_data.qualname));
|
||||
self.nest_tables(
|
||||
item.id,
|
||||
|v| v.process_formals(&decl.inputs, &fn_data.qualname),
|
||||
);
|
||||
self.process_generic_params(ty_params, item.span, &fn_data.qualname, item.id);
|
||||
self.dumper.dump_def(item.vis == ast::Visibility::Public, fn_data);
|
||||
self.dumper
|
||||
.dump_def(item.vis == ast::Visibility::Public, fn_data);
|
||||
}
|
||||
|
||||
for arg in &decl.inputs {
|
||||
@@ -461,29 +482,34 @@ fn process_fn(&mut self,
|
||||
self.nest_tables(item.id, |v| v.nest_scope(item.id, |v| v.visit_block(&body)));
|
||||
}
|
||||
|
||||
fn process_static_or_const_item(&mut self,
|
||||
item: &'l ast::Item,
|
||||
typ: &'l ast::Ty,
|
||||
expr: &'l ast::Expr) {
|
||||
fn process_static_or_const_item(
|
||||
&mut self,
|
||||
item: &'l ast::Item,
|
||||
typ: &'l ast::Ty,
|
||||
expr: &'l ast::Expr,
|
||||
) {
|
||||
self.nest_tables(item.id, |v| {
|
||||
if let Some(var_data) = v.save_ctxt.get_item_data(item) {
|
||||
down_cast_data!(var_data, DefData, item.span);
|
||||
v.dumper.dump_def(item.vis == ast::Visibility::Public, var_data);
|
||||
v.dumper
|
||||
.dump_def(item.vis == ast::Visibility::Public, var_data);
|
||||
}
|
||||
v.visit_ty(&typ);
|
||||
v.visit_expr(expr);
|
||||
});
|
||||
}
|
||||
|
||||
fn process_assoc_const(&mut self,
|
||||
id: ast::NodeId,
|
||||
name: ast::Name,
|
||||
span: Span,
|
||||
typ: &'l ast::Ty,
|
||||
expr: Option<&'l ast::Expr>,
|
||||
parent_id: DefId,
|
||||
vis: ast::Visibility,
|
||||
attrs: &'l [Attribute]) {
|
||||
fn process_assoc_const(
|
||||
&mut self,
|
||||
id: ast::NodeId,
|
||||
name: ast::Name,
|
||||
span: Span,
|
||||
typ: &'l ast::Ty,
|
||||
expr: Option<&'l ast::Expr>,
|
||||
parent_id: DefId,
|
||||
vis: ast::Visibility,
|
||||
attrs: &'l [Attribute],
|
||||
) {
|
||||
let qualname = format!("::{}", self.tcx.node_path_str(id));
|
||||
|
||||
let sub_span = self.span.sub_span_after_keyword(span, keywords::Const);
|
||||
@@ -493,20 +519,23 @@ fn process_assoc_const(&mut self,
|
||||
let id = ::id_from_node_id(id, &self.save_ctxt);
|
||||
let span = self.span_from_span(sub_span.expect("No span found for variable"));
|
||||
|
||||
self.dumper.dump_def(vis == ast::Visibility::Public, Def {
|
||||
kind: DefKind::Const,
|
||||
id,
|
||||
span,
|
||||
name: name.to_string(),
|
||||
qualname,
|
||||
value: ty_to_string(&typ),
|
||||
parent: Some(::id_from_def_id(parent_id)),
|
||||
children: vec![],
|
||||
decl_id: None,
|
||||
docs: self.save_ctxt.docs_for_attrs(attrs),
|
||||
sig,
|
||||
attributes: lower_attributes(attrs.to_owned(), &self.save_ctxt),
|
||||
});
|
||||
self.dumper.dump_def(
|
||||
vis == ast::Visibility::Public,
|
||||
Def {
|
||||
kind: DefKind::Const,
|
||||
id,
|
||||
span,
|
||||
name: name.to_string(),
|
||||
qualname,
|
||||
value: ty_to_string(&typ),
|
||||
parent: Some(::id_from_def_id(parent_id)),
|
||||
children: vec![],
|
||||
decl_id: None,
|
||||
docs: self.save_ctxt.docs_for_attrs(attrs),
|
||||
sig,
|
||||
attributes: lower_attributes(attrs.to_owned(), &self.save_ctxt),
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
// walk type and init value
|
||||
@@ -517,10 +546,12 @@ fn process_assoc_const(&mut self,
|
||||
}
|
||||
|
||||
// FIXME tuple structs should generate tuple-specific data.
|
||||
fn process_struct(&mut self,
|
||||
item: &'l ast::Item,
|
||||
def: &'l ast::VariantData,
|
||||
ty_params: &'l ast::Generics) {
|
||||
fn process_struct(
|
||||
&mut self,
|
||||
item: &'l ast::Item,
|
||||
def: &'l ast::VariantData,
|
||||
ty_params: &'l ast::Generics,
|
||||
) {
|
||||
debug!("process_struct {:?} {:?}", item, item.span);
|
||||
let name = item.ident.to_string();
|
||||
let qualname = format!("::{}", self.tcx.node_path_str(item.id));
|
||||
@@ -540,36 +571,47 @@ fn process_struct(&mut self,
|
||||
.iter()
|
||||
.enumerate()
|
||||
.filter_map(|(i, f)| {
|
||||
if include_priv_fields || f.vis == ast::Visibility::Public {
|
||||
f.ident.map(|i| i.to_string()).or_else(|| Some(i.to_string()))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
if include_priv_fields || f.vis == ast::Visibility::Public {
|
||||
f.ident
|
||||
.map(|i| i.to_string())
|
||||
.or_else(|| Some(i.to_string()))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
.join(", ");
|
||||
let value = format!("{} {{ {} }}", name, fields_str);
|
||||
(value, fields.iter().map(|f| ::id_from_node_id(f.id, &self.save_ctxt)).collect())
|
||||
(
|
||||
value,
|
||||
fields
|
||||
.iter()
|
||||
.map(|f| ::id_from_node_id(f.id, &self.save_ctxt))
|
||||
.collect(),
|
||||
)
|
||||
}
|
||||
_ => (String::new(), vec![])
|
||||
_ => (String::new(), vec![]),
|
||||
};
|
||||
|
||||
if !self.span.filter_generated(sub_span, item.span) {
|
||||
let span = self.span_from_span(sub_span.expect("No span found for struct"));
|
||||
self.dumper.dump_def(item.vis == ast::Visibility::Public, Def {
|
||||
kind,
|
||||
id: ::id_from_node_id(item.id, &self.save_ctxt),
|
||||
span,
|
||||
name,
|
||||
qualname: qualname.clone(),
|
||||
value,
|
||||
parent: None,
|
||||
children: fields,
|
||||
decl_id: None,
|
||||
docs: self.save_ctxt.docs_for_attrs(&item.attrs),
|
||||
sig: sig::item_signature(item, &self.save_ctxt),
|
||||
attributes: lower_attributes(item.attrs.clone(), &self.save_ctxt),
|
||||
});
|
||||
self.dumper.dump_def(
|
||||
item.vis == ast::Visibility::Public,
|
||||
Def {
|
||||
kind,
|
||||
id: ::id_from_node_id(item.id, &self.save_ctxt),
|
||||
span,
|
||||
name,
|
||||
qualname: qualname.clone(),
|
||||
value,
|
||||
parent: None,
|
||||
children: fields,
|
||||
decl_id: None,
|
||||
docs: self.save_ctxt.docs_for_attrs(&item.attrs),
|
||||
sig: sig::item_signature(item, &self.save_ctxt),
|
||||
attributes: lower_attributes(item.attrs.clone(), &self.save_ctxt),
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
for field in def.fields() {
|
||||
@@ -580,10 +622,12 @@ fn process_struct(&mut self,
|
||||
self.process_generic_params(ty_params, item.span, &qualname, item.id);
|
||||
}
|
||||
|
||||
fn process_enum(&mut self,
|
||||
item: &'l ast::Item,
|
||||
enum_definition: &'l ast::EnumDef,
|
||||
ty_params: &'l ast::Generics) {
|
||||
fn process_enum(
|
||||
&mut self,
|
||||
item: &'l ast::Item,
|
||||
enum_definition: &'l ast::EnumDef,
|
||||
ty_params: &'l ast::Generics,
|
||||
) {
|
||||
let enum_data = self.save_ctxt.get_item_data(item);
|
||||
let enum_data = match enum_data {
|
||||
None => return,
|
||||
@@ -600,34 +644,41 @@ fn process_enum(&mut self,
|
||||
match variant.node.data {
|
||||
ast::VariantData::Struct(ref fields, _) => {
|
||||
let sub_span = self.span.span_for_first_ident(variant.span);
|
||||
let fields_str = fields.iter()
|
||||
.enumerate()
|
||||
.map(|(i, f)| f.ident.map(|i| i.to_string())
|
||||
.unwrap_or(i.to_string()))
|
||||
.collect::<Vec<_>>()
|
||||
.join(", ");
|
||||
let fields_str = fields
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(i, f)| {
|
||||
f.ident.map(|i| i.to_string()).unwrap_or(i.to_string())
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
.join(", ");
|
||||
let value = format!("{}::{} {{ {} }}", enum_data.name, name, fields_str);
|
||||
if !self.span.filter_generated(sub_span, variant.span) {
|
||||
let span = self.span_from_span(
|
||||
sub_span.expect("No span found for struct variant"));
|
||||
let span = self
|
||||
.span_from_span(sub_span.expect("No span found for struct variant"));
|
||||
let id = ::id_from_node_id(variant.node.data.id(), &self.save_ctxt);
|
||||
let parent = Some(::id_from_node_id(item.id, &self.save_ctxt));
|
||||
|
||||
self.dumper.dump_def(item.vis == ast::Visibility::Public, Def {
|
||||
kind: DefKind::StructVariant,
|
||||
id,
|
||||
span,
|
||||
name,
|
||||
qualname,
|
||||
value,
|
||||
parent,
|
||||
children: vec![],
|
||||
decl_id: None,
|
||||
docs: self.save_ctxt.docs_for_attrs(&variant.node.attrs),
|
||||
sig: sig::variant_signature(variant, &self.save_ctxt),
|
||||
attributes: lower_attributes(variant.node.attrs.clone(),
|
||||
&self.save_ctxt),
|
||||
});
|
||||
self.dumper.dump_def(
|
||||
item.vis == ast::Visibility::Public,
|
||||
Def {
|
||||
kind: DefKind::StructVariant,
|
||||
id,
|
||||
span,
|
||||
name,
|
||||
qualname,
|
||||
value,
|
||||
parent,
|
||||
children: vec![],
|
||||
decl_id: None,
|
||||
docs: self.save_ctxt.docs_for_attrs(&variant.node.attrs),
|
||||
sig: sig::variant_signature(variant, &self.save_ctxt),
|
||||
attributes: lower_attributes(
|
||||
variant.node.attrs.clone(),
|
||||
&self.save_ctxt,
|
||||
),
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
ref v => {
|
||||
@@ -635,10 +686,11 @@ fn process_enum(&mut self,
|
||||
let mut value = format!("{}::{}", enum_data.name, name);
|
||||
if let &ast::VariantData::Tuple(ref fields, _) = v {
|
||||
value.push('(');
|
||||
value.push_str(&fields.iter()
|
||||
.map(|f| ty_to_string(&f.ty))
|
||||
.collect::<Vec<_>>()
|
||||
.join(", "));
|
||||
value.push_str(&fields
|
||||
.iter()
|
||||
.map(|f| ty_to_string(&f.ty))
|
||||
.collect::<Vec<_>>()
|
||||
.join(", "));
|
||||
value.push(')');
|
||||
}
|
||||
if !self.span.filter_generated(sub_span, variant.span) {
|
||||
@@ -647,21 +699,26 @@ fn process_enum(&mut self,
|
||||
let id = ::id_from_node_id(variant.node.data.id(), &self.save_ctxt);
|
||||
let parent = Some(::id_from_node_id(item.id, &self.save_ctxt));
|
||||
|
||||
self.dumper.dump_def(item.vis == ast::Visibility::Public, Def {
|
||||
kind: DefKind::TupleVariant,
|
||||
id,
|
||||
span,
|
||||
name,
|
||||
qualname,
|
||||
value,
|
||||
parent,
|
||||
children: vec![],
|
||||
decl_id: None,
|
||||
docs: self.save_ctxt.docs_for_attrs(&variant.node.attrs),
|
||||
sig: sig::variant_signature(variant, &self.save_ctxt),
|
||||
attributes: lower_attributes(variant.node.attrs.clone(),
|
||||
&self.save_ctxt),
|
||||
});
|
||||
self.dumper.dump_def(
|
||||
item.vis == ast::Visibility::Public,
|
||||
Def {
|
||||
kind: DefKind::TupleVariant,
|
||||
id,
|
||||
span,
|
||||
name,
|
||||
qualname,
|
||||
value,
|
||||
parent,
|
||||
children: vec![],
|
||||
decl_id: None,
|
||||
docs: self.save_ctxt.docs_for_attrs(&variant.node.attrs),
|
||||
sig: sig::variant_signature(variant, &self.save_ctxt),
|
||||
attributes: lower_attributes(
|
||||
variant.node.attrs.clone(),
|
||||
&self.save_ctxt,
|
||||
),
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -673,15 +730,18 @@ fn process_enum(&mut self,
|
||||
}
|
||||
}
|
||||
self.process_generic_params(ty_params, item.span, &enum_data.qualname, item.id);
|
||||
self.dumper.dump_def(item.vis == ast::Visibility::Public, enum_data);
|
||||
self.dumper
|
||||
.dump_def(item.vis == ast::Visibility::Public, enum_data);
|
||||
}
|
||||
|
||||
fn process_impl(&mut self,
|
||||
item: &'l ast::Item,
|
||||
type_parameters: &'l ast::Generics,
|
||||
trait_ref: &'l Option<ast::TraitRef>,
|
||||
typ: &'l ast::Ty,
|
||||
impl_items: &'l [ast::ImplItem]) {
|
||||
fn process_impl(
|
||||
&mut self,
|
||||
item: &'l ast::Item,
|
||||
type_parameters: &'l ast::Generics,
|
||||
trait_ref: &'l Option<ast::TraitRef>,
|
||||
typ: &'l ast::Ty,
|
||||
impl_items: &'l [ast::ImplItem],
|
||||
) {
|
||||
if let Some(impl_data) = self.save_ctxt.get_item_data(item) {
|
||||
down_cast_data!(impl_data, RelationData, item.span);
|
||||
self.dumper.dump_relation(impl_data);
|
||||
@@ -697,11 +757,13 @@ fn process_impl(&mut self,
|
||||
}
|
||||
}
|
||||
|
||||
fn process_trait(&mut self,
|
||||
item: &'l ast::Item,
|
||||
generics: &'l ast::Generics,
|
||||
trait_refs: &'l ast::TyParamBounds,
|
||||
methods: &'l [ast::TraitItem]) {
|
||||
fn process_trait(
|
||||
&mut self,
|
||||
item: &'l ast::Item,
|
||||
generics: &'l ast::Generics,
|
||||
trait_refs: &'l ast::TyParamBounds,
|
||||
methods: &'l [ast::TraitItem],
|
||||
) {
|
||||
let name = item.ident.to_string();
|
||||
let qualname = format!("::{}", self.tcx.node_path_str(item.id));
|
||||
let mut val = name.clone();
|
||||
@@ -716,30 +778,33 @@ fn process_trait(&mut self,
|
||||
if !self.span.filter_generated(sub_span, item.span) {
|
||||
let id = ::id_from_node_id(item.id, &self.save_ctxt);
|
||||
let span = self.span_from_span(sub_span.expect("No span found for trait"));
|
||||
let children =
|
||||
methods.iter().map(|i| ::id_from_node_id(i.id, &self.save_ctxt)).collect();
|
||||
self.dumper.dump_def(item.vis == ast::Visibility::Public, Def {
|
||||
kind: DefKind::Trait,
|
||||
id,
|
||||
span,
|
||||
name,
|
||||
qualname: qualname.clone(),
|
||||
value: val,
|
||||
parent: None,
|
||||
children,
|
||||
decl_id: None,
|
||||
docs: self.save_ctxt.docs_for_attrs(&item.attrs),
|
||||
sig: sig::item_signature(item, &self.save_ctxt),
|
||||
attributes: lower_attributes(item.attrs.clone(), &self.save_ctxt),
|
||||
});
|
||||
let children = methods
|
||||
.iter()
|
||||
.map(|i| ::id_from_node_id(i.id, &self.save_ctxt))
|
||||
.collect();
|
||||
self.dumper.dump_def(
|
||||
item.vis == ast::Visibility::Public,
|
||||
Def {
|
||||
kind: DefKind::Trait,
|
||||
id,
|
||||
span,
|
||||
name,
|
||||
qualname: qualname.clone(),
|
||||
value: val,
|
||||
parent: None,
|
||||
children,
|
||||
decl_id: None,
|
||||
docs: self.save_ctxt.docs_for_attrs(&item.attrs),
|
||||
sig: sig::item_signature(item, &self.save_ctxt),
|
||||
attributes: lower_attributes(item.attrs.clone(), &self.save_ctxt),
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
// super-traits
|
||||
for super_bound in trait_refs.iter() {
|
||||
let trait_ref = match *super_bound {
|
||||
ast::TraitTyParamBound(ref trait_ref, _) => {
|
||||
trait_ref
|
||||
}
|
||||
ast::TraitTyParamBound(ref trait_ref, _) => trait_ref,
|
||||
ast::RegionTyParamBound(..) => {
|
||||
continue;
|
||||
}
|
||||
@@ -781,35 +846,32 @@ fn process_trait(&mut self,
|
||||
fn process_mod(&mut self, item: &ast::Item) {
|
||||
if let Some(mod_data) = self.save_ctxt.get_item_data(item) {
|
||||
down_cast_data!(mod_data, DefData, item.span);
|
||||
self.dumper.dump_def(item.vis == ast::Visibility::Public, mod_data);
|
||||
self.dumper
|
||||
.dump_def(item.vis == ast::Visibility::Public, mod_data);
|
||||
}
|
||||
}
|
||||
|
||||
fn dump_path_ref(&mut self, id: NodeId, path: &ast::Path) {
|
||||
let path_data = self.save_ctxt.get_path_data(id, path);
|
||||
if let Some(path_data) = path_data {
|
||||
self.dumper.dump_ref(path_data);
|
||||
}
|
||||
}
|
||||
|
||||
fn process_path(&mut self, id: NodeId, path: &'l ast::Path) {
|
||||
debug!("process_path {:?}", path);
|
||||
let path_data = self.save_ctxt.get_path_data(id, path);
|
||||
if generated_code(path.span) && path_data.is_none() {
|
||||
if generated_code(path.span) {
|
||||
return;
|
||||
}
|
||||
|
||||
let path_data = match path_data {
|
||||
Some(pd) => pd,
|
||||
None => {
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
self.dumper.dump_ref(path_data);
|
||||
self.dump_path_ref(id, path);
|
||||
|
||||
// Type parameters
|
||||
for seg in &path.segments {
|
||||
if let Some(ref params) = seg.parameters {
|
||||
match **params {
|
||||
ast::PathParameters::AngleBracketed(ref data) => {
|
||||
for t in &data.types {
|
||||
self.visit_ty(t);
|
||||
}
|
||||
}
|
||||
ast::PathParameters::AngleBracketed(ref data) => for t in &data.types {
|
||||
self.visit_ty(t);
|
||||
},
|
||||
ast::PathParameters::Parenthesized(ref data) => {
|
||||
for t in &data.inputs {
|
||||
self.visit_ty(t);
|
||||
@@ -847,12 +909,14 @@ fn process_path(&mut self, id: NodeId, path: &'l ast::Path) {
|
||||
}
|
||||
}
|
||||
|
||||
fn process_struct_lit(&mut self,
|
||||
ex: &'l ast::Expr,
|
||||
path: &'l ast::Path,
|
||||
fields: &'l [ast::Field],
|
||||
variant: &'l ty::VariantDef,
|
||||
base: &'l Option<P<ast::Expr>>) {
|
||||
fn process_struct_lit(
|
||||
&mut self,
|
||||
ex: &'l ast::Expr,
|
||||
path: &'l ast::Path,
|
||||
fields: &'l [ast::Field],
|
||||
variant: &'l ty::VariantDef,
|
||||
base: &'l Option<P<ast::Expr>>,
|
||||
) {
|
||||
self.write_sub_paths_truncated(path);
|
||||
|
||||
if let Some(struct_lit_data) = self.save_ctxt.get_expr_data(ex) {
|
||||
@@ -862,8 +926,7 @@ fn process_struct_lit(&mut self,
|
||||
}
|
||||
|
||||
for field in fields {
|
||||
if let Some(field_data) = self.save_ctxt
|
||||
.get_field_ref_data(field, variant) {
|
||||
if let Some(field_data) = self.save_ctxt.get_field_ref_data(field, variant) {
|
||||
self.dumper.dump_ref(field_data);
|
||||
}
|
||||
|
||||
@@ -874,10 +937,12 @@ fn process_struct_lit(&mut self,
|
||||
walk_list!(self, visit_expr, base);
|
||||
}
|
||||
|
||||
fn process_method_call(&mut self,
|
||||
ex: &'l ast::Expr,
|
||||
seg: &'l ast::PathSegment,
|
||||
args: &'l [P<ast::Expr>]) {
|
||||
fn process_method_call(
|
||||
&mut self,
|
||||
ex: &'l ast::Expr,
|
||||
seg: &'l ast::PathSegment,
|
||||
args: &'l [P<ast::Expr>],
|
||||
) {
|
||||
debug!("process_method_call {:?} {:?}", ex, ex.span);
|
||||
if let Some(mcd) = self.save_ctxt.get_expr_data(ex) {
|
||||
down_cast_data!(mcd, RefData, ex.span);
|
||||
@@ -913,7 +978,11 @@ fn process_pat(&mut self, p: &'l ast::Pat) {
|
||||
};
|
||||
let variant = adt.variant_of_def(self.save_ctxt.get_path_def(p.id));
|
||||
|
||||
for &Spanned { node: ref field, span } in fields {
|
||||
for &Spanned {
|
||||
node: ref field,
|
||||
span,
|
||||
} in fields
|
||||
{
|
||||
let sub_span = self.span.span_for_first_ident(span);
|
||||
if let Some(f) = variant.find_field_named(field.ident.name) {
|
||||
if !self.span.filter_generated(sub_span, span) {
|
||||
@@ -968,20 +1037,23 @@ fn process_var_decl(&mut self, p: &'l ast::Pat, value: String) {
|
||||
let id = ::id_from_node_id(id, &self.save_ctxt);
|
||||
let span = self.span_from_span(sub_span.expect("No span found for variable"));
|
||||
|
||||
self.dumper.dump_def(false, Def {
|
||||
kind: DefKind::Local,
|
||||
id,
|
||||
span,
|
||||
name: i.to_string(),
|
||||
qualname,
|
||||
value: typ,
|
||||
parent: None,
|
||||
children: vec![],
|
||||
decl_id: None,
|
||||
docs: String::new(),
|
||||
sig: None,
|
||||
attributes:vec![],
|
||||
});
|
||||
self.dumper.dump_def(
|
||||
false,
|
||||
Def {
|
||||
kind: DefKind::Local,
|
||||
id,
|
||||
span,
|
||||
name: i.to_string(),
|
||||
qualname,
|
||||
value: typ,
|
||||
parent: None,
|
||||
children: vec![],
|
||||
decl_id: None,
|
||||
docs: String::new(),
|
||||
sig: None,
|
||||
attributes: vec![],
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1032,52 +1104,62 @@ fn process_trait_item(&mut self, trait_item: &'l ast::TraitItem, trait_id: DefId
|
||||
self.process_macro_use(trait_item.span);
|
||||
match trait_item.node {
|
||||
ast::TraitItemKind::Const(ref ty, ref expr) => {
|
||||
self.process_assoc_const(trait_item.id,
|
||||
trait_item.ident.name,
|
||||
trait_item.span,
|
||||
&ty,
|
||||
expr.as_ref().map(|e| &**e),
|
||||
trait_id,
|
||||
ast::Visibility::Public,
|
||||
&trait_item.attrs);
|
||||
self.process_assoc_const(
|
||||
trait_item.id,
|
||||
trait_item.ident.name,
|
||||
trait_item.span,
|
||||
&ty,
|
||||
expr.as_ref().map(|e| &**e),
|
||||
trait_id,
|
||||
ast::Visibility::Public,
|
||||
&trait_item.attrs,
|
||||
);
|
||||
}
|
||||
ast::TraitItemKind::Method(ref sig, ref body) => {
|
||||
self.process_method(sig,
|
||||
body.as_ref().map(|x| &**x),
|
||||
trait_item.id,
|
||||
trait_item.ident,
|
||||
&trait_item.generics,
|
||||
ast::Visibility::Public,
|
||||
trait_item.span);
|
||||
self.process_method(
|
||||
sig,
|
||||
body.as_ref().map(|x| &**x),
|
||||
trait_item.id,
|
||||
trait_item.ident,
|
||||
&trait_item.generics,
|
||||
ast::Visibility::Public,
|
||||
trait_item.span,
|
||||
);
|
||||
}
|
||||
ast::TraitItemKind::Type(ref bounds, ref default_ty) => {
|
||||
// FIXME do something with _bounds (for type refs)
|
||||
let name = trait_item.ident.name.to_string();
|
||||
let qualname = format!("::{}", self.tcx.node_path_str(trait_item.id));
|
||||
let sub_span = self.span.sub_span_after_keyword(trait_item.span, keywords::Type);
|
||||
let sub_span = self.span
|
||||
.sub_span_after_keyword(trait_item.span, keywords::Type);
|
||||
|
||||
if !self.span.filter_generated(sub_span, trait_item.span) {
|
||||
let span = self.span_from_span(sub_span.expect("No span found for assoc type"));
|
||||
let id = ::id_from_node_id(trait_item.id, &self.save_ctxt);
|
||||
|
||||
self.dumper.dump_def(true, Def {
|
||||
kind: DefKind::Type,
|
||||
id,
|
||||
span,
|
||||
name,
|
||||
qualname,
|
||||
value: self.span.snippet(trait_item.span),
|
||||
parent: Some(::id_from_def_id(trait_id)),
|
||||
children: vec![],
|
||||
decl_id: None,
|
||||
docs: self.save_ctxt.docs_for_attrs(&trait_item.attrs),
|
||||
sig: sig::assoc_type_signature(trait_item.id,
|
||||
trait_item.ident,
|
||||
Some(bounds),
|
||||
default_ty.as_ref().map(|ty| &**ty),
|
||||
&self.save_ctxt),
|
||||
attributes: lower_attributes(trait_item.attrs.clone(), &self.save_ctxt),
|
||||
});
|
||||
self.dumper.dump_def(
|
||||
true,
|
||||
Def {
|
||||
kind: DefKind::Type,
|
||||
id,
|
||||
span,
|
||||
name,
|
||||
qualname,
|
||||
value: self.span.snippet(trait_item.span),
|
||||
parent: Some(::id_from_def_id(trait_id)),
|
||||
children: vec![],
|
||||
decl_id: None,
|
||||
docs: self.save_ctxt.docs_for_attrs(&trait_item.attrs),
|
||||
sig: sig::assoc_type_signature(
|
||||
trait_item.id,
|
||||
trait_item.ident,
|
||||
Some(bounds),
|
||||
default_ty.as_ref().map(|ty| &**ty),
|
||||
&self.save_ctxt,
|
||||
),
|
||||
attributes: lower_attributes(trait_item.attrs.clone(), &self.save_ctxt),
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
if let &Some(ref default_ty) = default_ty {
|
||||
@@ -1092,23 +1174,27 @@ fn process_impl_item(&mut self, impl_item: &'l ast::ImplItem, impl_id: DefId) {
|
||||
self.process_macro_use(impl_item.span);
|
||||
match impl_item.node {
|
||||
ast::ImplItemKind::Const(ref ty, ref expr) => {
|
||||
self.process_assoc_const(impl_item.id,
|
||||
impl_item.ident.name,
|
||||
impl_item.span,
|
||||
&ty,
|
||||
Some(expr),
|
||||
impl_id,
|
||||
impl_item.vis.clone(),
|
||||
&impl_item.attrs);
|
||||
self.process_assoc_const(
|
||||
impl_item.id,
|
||||
impl_item.ident.name,
|
||||
impl_item.span,
|
||||
&ty,
|
||||
Some(expr),
|
||||
impl_id,
|
||||
impl_item.vis.clone(),
|
||||
&impl_item.attrs,
|
||||
);
|
||||
}
|
||||
ast::ImplItemKind::Method(ref sig, ref body) => {
|
||||
self.process_method(sig,
|
||||
Some(body),
|
||||
impl_item.id,
|
||||
impl_item.ident,
|
||||
&impl_item.generics,
|
||||
impl_item.vis.clone(),
|
||||
impl_item.span);
|
||||
self.process_method(
|
||||
sig,
|
||||
Some(body),
|
||||
impl_item.id,
|
||||
impl_item.ident,
|
||||
&impl_item.generics,
|
||||
impl_item.vis.clone(),
|
||||
impl_item.span,
|
||||
);
|
||||
}
|
||||
ast::ImplItemKind::Type(ref ty) => {
|
||||
// FIXME uses of the assoc type should ideally point to this
|
||||
@@ -1132,23 +1218,29 @@ fn visit_mod(&mut self, m: &'l ast::Mod, span: Span, attrs: &[ast::Attribute], i
|
||||
let cm = self.tcx.sess.codemap();
|
||||
let filename = cm.span_to_filename(span);
|
||||
let data_id = ::id_from_node_id(id, &self.save_ctxt);
|
||||
let children = m.items.iter().map(|i| ::id_from_node_id(i.id, &self.save_ctxt)).collect();
|
||||
let children = m.items
|
||||
.iter()
|
||||
.map(|i| ::id_from_node_id(i.id, &self.save_ctxt))
|
||||
.collect();
|
||||
let span = self.span_from_span(span);
|
||||
|
||||
self.dumper.dump_def(true, Def {
|
||||
kind: DefKind::Mod,
|
||||
id: data_id,
|
||||
name: String::new(),
|
||||
qualname,
|
||||
span,
|
||||
value: filename,
|
||||
children,
|
||||
parent: None,
|
||||
decl_id: None,
|
||||
docs: self.save_ctxt.docs_for_attrs(attrs),
|
||||
sig: None,
|
||||
attributes: lower_attributes(attrs.to_owned(), &self.save_ctxt),
|
||||
});
|
||||
self.dumper.dump_def(
|
||||
true,
|
||||
Def {
|
||||
kind: DefKind::Mod,
|
||||
id: data_id,
|
||||
name: String::new(),
|
||||
qualname,
|
||||
span,
|
||||
value: filename,
|
||||
children,
|
||||
parent: None,
|
||||
decl_id: None,
|
||||
docs: self.save_ctxt.docs_for_attrs(attrs),
|
||||
sig: None,
|
||||
attributes: lower_attributes(attrs.to_owned(), &self.save_ctxt),
|
||||
},
|
||||
);
|
||||
self.nest_scope(id, |v| visit::walk_mod(v, m));
|
||||
}
|
||||
|
||||
@@ -1170,8 +1262,9 @@ fn visit_item(&mut self, item: &'l ast::Item) {
|
||||
|
||||
// 'use' always introduces an alias, if there is not an explicit
|
||||
// one, there is an implicit one.
|
||||
let sub_span = match self.span.sub_span_after_keyword(use_item.span,
|
||||
keywords::As) {
|
||||
let sub_span = match self.span
|
||||
.sub_span_after_keyword(use_item.span, keywords::As)
|
||||
{
|
||||
Some(sub_span) => Some(sub_span),
|
||||
None => sub_span,
|
||||
};
|
||||
@@ -1179,13 +1272,16 @@ fn visit_item(&mut self, item: &'l ast::Item) {
|
||||
if !self.span.filter_generated(sub_span, path.span) {
|
||||
let span =
|
||||
self.span_from_span(sub_span.expect("No span found for use"));
|
||||
self.dumper.import(item.vis == ast::Visibility::Public, Import {
|
||||
kind: ImportKind::Use,
|
||||
ref_id: mod_id.map(|id| ::id_from_def_id(id)),
|
||||
span,
|
||||
name: ident.to_string(),
|
||||
value: String::new(),
|
||||
});
|
||||
self.dumper.import(
|
||||
item.vis == ast::Visibility::Public,
|
||||
Import {
|
||||
kind: ImportKind::Use,
|
||||
ref_id: mod_id.map(|id| ::id_from_def_id(id)),
|
||||
span,
|
||||
name: ident.to_string(),
|
||||
value: String::new(),
|
||||
},
|
||||
);
|
||||
}
|
||||
self.write_sub_paths_truncated(path);
|
||||
}
|
||||
@@ -1201,17 +1297,20 @@ fn visit_item(&mut self, item: &'l ast::Item) {
|
||||
}
|
||||
|
||||
let sub_span = self.span
|
||||
.sub_span_of_token(item.span, token::BinOp(token::Star));
|
||||
.sub_span_of_token(item.span, token::BinOp(token::Star));
|
||||
if !self.span.filter_generated(sub_span, item.span) {
|
||||
let span =
|
||||
self.span_from_span(sub_span.expect("No span found for use glob"));
|
||||
self.dumper.import(item.vis == ast::Visibility::Public, Import {
|
||||
kind: ImportKind::GlobUse,
|
||||
ref_id: None,
|
||||
span,
|
||||
name: "*".to_owned(),
|
||||
value: names.join(", "),
|
||||
});
|
||||
self.dumper.import(
|
||||
item.vis == ast::Visibility::Public,
|
||||
Import {
|
||||
kind: ImportKind::GlobUse,
|
||||
ref_id: None,
|
||||
span,
|
||||
name: "*".to_owned(),
|
||||
value: names.join(", "),
|
||||
},
|
||||
);
|
||||
}
|
||||
self.write_sub_paths(path);
|
||||
}
|
||||
@@ -1234,34 +1333,33 @@ fn visit_item(&mut self, item: &'l ast::Item) {
|
||||
if !self.span.filter_generated(alias_span, item.span) {
|
||||
let span =
|
||||
self.span_from_span(alias_span.expect("No span found for extern crate"));
|
||||
self.dumper.import(false, Import {
|
||||
kind: ImportKind::ExternCrate,
|
||||
ref_id: None,
|
||||
span,
|
||||
name: item.ident.to_string(),
|
||||
value: String::new(),
|
||||
});
|
||||
self.dumper.import(
|
||||
false,
|
||||
Import {
|
||||
kind: ImportKind::ExternCrate,
|
||||
ref_id: None,
|
||||
span,
|
||||
name: item.ident.to_string(),
|
||||
value: String::new(),
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
Fn(ref decl, .., ref ty_params, ref body) =>
|
||||
self.process_fn(item, &decl, ty_params, &body),
|
||||
Static(ref typ, _, ref expr) =>
|
||||
self.process_static_or_const_item(item, typ, expr),
|
||||
Const(ref typ, ref expr) =>
|
||||
self.process_static_or_const_item(item, &typ, &expr),
|
||||
Fn(ref decl, .., ref ty_params, ref body) => {
|
||||
self.process_fn(item, &decl, ty_params, &body)
|
||||
}
|
||||
Static(ref typ, _, ref expr) => self.process_static_or_const_item(item, typ, expr),
|
||||
Const(ref typ, ref expr) => self.process_static_or_const_item(item, &typ, &expr),
|
||||
Struct(ref def, ref ty_params) | Union(ref def, ref ty_params) => {
|
||||
self.process_struct(item, def, ty_params)
|
||||
}
|
||||
Enum(ref def, ref ty_params) => self.process_enum(item, def, ty_params),
|
||||
Impl(..,
|
||||
ref ty_params,
|
||||
ref trait_ref,
|
||||
ref typ,
|
||||
ref impl_items) => {
|
||||
Impl(.., ref ty_params, ref trait_ref, ref typ, ref impl_items) => {
|
||||
self.process_impl(item, ty_params, trait_ref, &typ, impl_items)
|
||||
}
|
||||
Trait(_, _, ref generics, ref trait_refs, ref methods) =>
|
||||
self.process_trait(item, generics, trait_refs, methods),
|
||||
Trait(_, _, ref generics, ref trait_refs, ref methods) => {
|
||||
self.process_trait(item, generics, trait_refs, methods)
|
||||
}
|
||||
Mod(ref m) => {
|
||||
self.process_mod(item);
|
||||
self.nest_scope(item.id, |v| visit::walk_mod(v, m));
|
||||
@@ -1274,20 +1372,23 @@ fn visit_item(&mut self, item: &'l ast::Item) {
|
||||
let span = self.span_from_span(sub_span.expect("No span found for typedef"));
|
||||
let id = ::id_from_node_id(item.id, &self.save_ctxt);
|
||||
|
||||
self.dumper.dump_def(item.vis == ast::Visibility::Public, Def {
|
||||
kind: DefKind::Type,
|
||||
id,
|
||||
span,
|
||||
name: item.ident.to_string(),
|
||||
qualname: qualname.clone(),
|
||||
value,
|
||||
parent: None,
|
||||
children: vec![],
|
||||
decl_id: None,
|
||||
docs: self.save_ctxt.docs_for_attrs(&item.attrs),
|
||||
sig: sig::item_signature(item, &self.save_ctxt),
|
||||
attributes: lower_attributes(item.attrs.clone(), &self.save_ctxt),
|
||||
});
|
||||
self.dumper.dump_def(
|
||||
item.vis == ast::Visibility::Public,
|
||||
Def {
|
||||
kind: DefKind::Type,
|
||||
id,
|
||||
span,
|
||||
name: item.ident.to_string(),
|
||||
qualname: qualname.clone(),
|
||||
value,
|
||||
parent: None,
|
||||
children: vec![],
|
||||
decl_id: None,
|
||||
docs: self.save_ctxt.docs_for_attrs(&item.attrs),
|
||||
sig: sig::item_signature(item, &self.save_ctxt),
|
||||
attributes: lower_attributes(item.attrs.clone(), &self.save_ctxt),
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
self.visit_ty(&ty);
|
||||
@@ -1374,8 +1475,11 @@ fn visit_expr(&mut self, ex: &'l ast::Expr) {
|
||||
let hir_node = match self.save_ctxt.tcx.hir.find(sub_ex.id) {
|
||||
Some(Node::NodeExpr(expr)) => expr,
|
||||
_ => {
|
||||
debug!("Missing or weird node for sub-expression {} in {:?}",
|
||||
sub_ex.id, ex);
|
||||
debug!(
|
||||
"Missing or weird node for sub-expression {} in {:?}",
|
||||
sub_ex.id,
|
||||
ex
|
||||
);
|
||||
return;
|
||||
}
|
||||
};
|
||||
@@ -1400,9 +1504,7 @@ fn visit_expr(&mut self, ex: &'l ast::Expr) {
|
||||
}
|
||||
}
|
||||
ty::TyTuple(..) => {}
|
||||
_ => span_bug!(ex.span,
|
||||
"Expected struct or tuple type, found {:?}",
|
||||
ty),
|
||||
_ => span_bug!(ex.span, "Expected struct or tuple type, found {:?}", ty),
|
||||
}
|
||||
}
|
||||
ast::ExprKind::Closure(_, ref decl, ref body, _fn_decl_span) => {
|
||||
@@ -1445,15 +1547,16 @@ fn visit_expr(&mut self, ex: &'l ast::Expr) {
|
||||
}
|
||||
// In particular, we take this branch for call and path expressions,
|
||||
// where we'll index the idents involved just by continuing to walk.
|
||||
_ => {
|
||||
visit::walk_expr(self, ex)
|
||||
}
|
||||
_ => visit::walk_expr(self, ex),
|
||||
}
|
||||
}
|
||||
|
||||
fn visit_mac(&mut self, mac: &'l ast::Mac) {
|
||||
// These shouldn't exist in the AST at this point, log a span bug.
|
||||
span_bug!(mac.span, "macro invocation should have been expanded out of AST");
|
||||
span_bug!(
|
||||
mac.span,
|
||||
"macro invocation should have been expanded out of AST"
|
||||
);
|
||||
}
|
||||
|
||||
fn visit_pat(&mut self, p: &'l ast::Pat) {
|
||||
@@ -1480,10 +1583,10 @@ fn visit_arm(&mut self, arm: &'l ast::Arm) {
|
||||
};
|
||||
let hir_id = self.tcx.hir.node_to_hir_id(id);
|
||||
let typ = self.save_ctxt
|
||||
.tables
|
||||
.node_id_to_type_opt(hir_id)
|
||||
.map(|t| t.to_string())
|
||||
.unwrap_or(String::new());
|
||||
.tables
|
||||
.node_id_to_type_opt(hir_id)
|
||||
.map(|t| t.to_string())
|
||||
.unwrap_or(String::new());
|
||||
value.push_str(": ");
|
||||
value.push_str(&typ);
|
||||
|
||||
@@ -1492,24 +1595,40 @@ fn visit_arm(&mut self, arm: &'l ast::Arm) {
|
||||
let id = ::id_from_node_id(id, &self.save_ctxt);
|
||||
let span = self.span_from_span(sp);
|
||||
|
||||
self.dumper.dump_def(false, Def {
|
||||
kind: DefKind::Local,
|
||||
id,
|
||||
span,
|
||||
name: i.to_string(),
|
||||
qualname,
|
||||
value: typ,
|
||||
parent: None,
|
||||
children: vec![],
|
||||
decl_id: None,
|
||||
docs: String::new(),
|
||||
sig: None,
|
||||
attributes:vec![],
|
||||
});
|
||||
self.dumper.dump_def(
|
||||
false,
|
||||
Def {
|
||||
kind: DefKind::Local,
|
||||
id,
|
||||
span,
|
||||
name: i.to_string(),
|
||||
qualname,
|
||||
value: typ,
|
||||
parent: None,
|
||||
children: vec![],
|
||||
decl_id: None,
|
||||
docs: String::new(),
|
||||
sig: None,
|
||||
attributes: vec![],
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
def => error!("unexpected definition kind when processing collected idents: {:?}",
|
||||
def),
|
||||
HirDef::StructCtor(..) |
|
||||
HirDef::VariantCtor(..) |
|
||||
HirDef::Const(..) |
|
||||
HirDef::AssociatedConst(..) |
|
||||
HirDef::Struct(..) |
|
||||
HirDef::Variant(..) |
|
||||
HirDef::TyAlias(..) |
|
||||
HirDef::AssociatedTy(..) |
|
||||
HirDef::SelfTy(..) => {
|
||||
self.dump_path_ref(id, &ast::Path::from_ident(sp, i));
|
||||
}
|
||||
def => error!(
|
||||
"unexpected definition kind when processing collected idents: {:?}",
|
||||
def
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1531,7 +1650,10 @@ fn visit_stmt(&mut self, s: &'l ast::Stmt) {
|
||||
|
||||
fn visit_local(&mut self, l: &'l ast::Local) {
|
||||
self.process_macro_use(l.span);
|
||||
let value = l.init.as_ref().map(|i| self.span.snippet(i.span)).unwrap_or(String::new());
|
||||
let value = l.init
|
||||
.as_ref()
|
||||
.map(|i| self.span.snippet(i.span))
|
||||
.unwrap_or(String::new());
|
||||
self.process_var_decl(&l.pat, value);
|
||||
|
||||
// Just walk the initialiser and type (don't want to walk the pattern again).
|
||||
@@ -1545,10 +1667,13 @@ fn visit_foreign_item(&mut self, item: &'l ast::ForeignItem) {
|
||||
if let Some(fn_data) = self.save_ctxt.get_extern_item_data(item) {
|
||||
down_cast_data!(fn_data, DefData, item.span);
|
||||
|
||||
self.nest_tables(item.id, |v| v.process_formals(&decl.inputs,
|
||||
&fn_data.qualname));
|
||||
self.nest_tables(
|
||||
item.id,
|
||||
|v| v.process_formals(&decl.inputs, &fn_data.qualname),
|
||||
);
|
||||
self.process_generic_params(generics, item.span, &fn_data.qualname, item.id);
|
||||
self.dumper.dump_def(item.vis == ast::Visibility::Public, fn_data);
|
||||
self.dumper
|
||||
.dump_def(item.vis == ast::Visibility::Public, fn_data);
|
||||
}
|
||||
|
||||
for arg in &decl.inputs {
|
||||
@@ -1562,7 +1687,8 @@ fn visit_foreign_item(&mut self, item: &'l ast::ForeignItem) {
|
||||
ast::ForeignItemKind::Static(ref ty, _) => {
|
||||
if let Some(var_data) = self.save_ctxt.get_extern_item_data(item) {
|
||||
down_cast_data!(var_data, DefData, item.span);
|
||||
self.dumper.dump_def(item.vis == ast::Visibility::Public, var_data);
|
||||
self.dumper
|
||||
.dump_def(item.vis == ast::Visibility::Public, var_data);
|
||||
}
|
||||
|
||||
self.visit_ty(ty);
|
||||
@@ -1570,7 +1696,8 @@ fn visit_foreign_item(&mut self, item: &'l ast::ForeignItem) {
|
||||
ast::ForeignItemKind::Ty => {
|
||||
if let Some(var_data) = self.save_ctxt.get_extern_item_data(item) {
|
||||
down_cast_data!(var_data, DefData, item.span);
|
||||
self.dumper.dump_def(item.vis == ast::Visibility::Public, var_data);
|
||||
self.dumper
|
||||
.dump_def(item.vis == ast::Visibility::Public, var_data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,8 +12,8 @@
|
||||
|
||||
use rustc_serialize::json::as_json;
|
||||
|
||||
use rls_data::{self, Analysis, Import, Def, DefKind, Ref, RefKind, MacroRef,
|
||||
Relation, CratePreludeData};
|
||||
use rls_data::{self, Analysis, CratePreludeData, Def, DefKind, Import, MacroRef, Ref, RefKind,
|
||||
Relation};
|
||||
use rls_data::config::Config;
|
||||
use rls_span::{Column, Row};
|
||||
|
||||
@@ -54,15 +54,16 @@ pub fn new(writer: &'b mut W, config: Config) -> JsonDumper<WriteOutput<'b, W>>
|
||||
JsonDumper {
|
||||
output: WriteOutput { output: writer },
|
||||
config: config.clone(),
|
||||
result: Analysis::new(config)
|
||||
result: Analysis::new(config),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'b> JsonDumper<CallbackOutput<'b>> {
|
||||
pub fn with_callback(callback: &'b mut FnMut(&Analysis),
|
||||
config: Config)
|
||||
-> JsonDumper<CallbackOutput<'b>> {
|
||||
pub fn with_callback(
|
||||
callback: &'b mut FnMut(&Analysis),
|
||||
config: Config,
|
||||
) -> JsonDumper<CallbackOutput<'b>> {
|
||||
JsonDumper {
|
||||
output: CallbackOutput { callback: callback },
|
||||
config: config.clone(),
|
||||
|
||||
+248
-176
@@ -9,20 +9,22 @@
|
||||
// except according to those terms.
|
||||
|
||||
#![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
|
||||
html_favicon_url = "https://doc.rust-lang.org/favicon.ico",
|
||||
html_root_url = "https://doc.rust-lang.org/nightly/")]
|
||||
html_favicon_url = "https://doc.rust-lang.org/favicon.ico",
|
||||
html_root_url = "https://doc.rust-lang.org/nightly/")]
|
||||
#![deny(warnings)]
|
||||
|
||||
#![feature(custom_attribute)]
|
||||
#![allow(unused_attributes)]
|
||||
|
||||
#[macro_use] extern crate rustc;
|
||||
#[macro_use]
|
||||
extern crate rustc;
|
||||
|
||||
#[macro_use] extern crate log;
|
||||
#[macro_use] extern crate syntax;
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
extern crate rustc_data_structures;
|
||||
extern crate rustc_serialize;
|
||||
extern crate rustc_typeck;
|
||||
#[macro_use]
|
||||
extern crate syntax;
|
||||
extern crate syntax_pos;
|
||||
|
||||
extern crate rls_data;
|
||||
@@ -38,7 +40,7 @@
|
||||
use rustc::hir;
|
||||
use rustc::hir::def::Def as HirDef;
|
||||
use rustc::hir::map::{Node, NodeItem};
|
||||
use rustc::hir::def_id::{LOCAL_CRATE, DefId};
|
||||
use rustc::hir::def_id::{DefId, LOCAL_CRATE};
|
||||
use rustc::session::config::CrateType::CrateTypeExecutable;
|
||||
use rustc::ty::{self, TyCtxt};
|
||||
use rustc_typeck::hir_ty_to_ty;
|
||||
@@ -48,13 +50,13 @@
|
||||
use std::fs::File;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use syntax::ast::{self, NodeId, PatKind, Attribute};
|
||||
use syntax::ast::{self, Attribute, NodeId, PatKind};
|
||||
use syntax::parse::lexer::comments::strip_doc_comment_decoration;
|
||||
use syntax::parse::token;
|
||||
use syntax::print::pprust;
|
||||
use syntax::symbol::keywords;
|
||||
use syntax::visit::{self, Visitor};
|
||||
use syntax::print::pprust::{ty_to_string, arg_to_string};
|
||||
use syntax::print::pprust::{arg_to_string, ty_to_string};
|
||||
use syntax::codemap::MacroAttribute;
|
||||
use syntax_pos::*;
|
||||
|
||||
@@ -62,8 +64,8 @@
|
||||
use dump_visitor::DumpVisitor;
|
||||
use span_utils::SpanUtils;
|
||||
|
||||
use rls_data::{Ref, RefKind, SpanData, MacroRef, Def, DefKind, Relation, RelationKind,
|
||||
ExternalCrateData, GlobalCrateId};
|
||||
use rls_data::{Def, DefKind, ExternalCrateData, GlobalCrateId, MacroRef, Ref, RefKind, Relation,
|
||||
RelationKind, SpanData};
|
||||
use rls_data::config::Config;
|
||||
|
||||
|
||||
@@ -84,7 +86,7 @@ pub enum Data {
|
||||
|
||||
impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
|
||||
fn span_from_span(&self, span: Span) -> SpanData {
|
||||
use rls_span::{Row, Column};
|
||||
use rls_span::{Column, Row};
|
||||
|
||||
let cm = self.tcx.sess.codemap();
|
||||
let start = cm.lookup_char_pos(span.lo());
|
||||
@@ -119,8 +121,7 @@ pub fn get_external_crates(&self) -> Vec<ExternalCrateData> {
|
||||
num: n.as_u32(),
|
||||
id: GlobalCrateId {
|
||||
name: self.tcx.crate_name(n).to_string(),
|
||||
disambiguator: self.tcx.crate_disambiguator(n)
|
||||
.to_fingerprint().as_value(),
|
||||
disambiguator: self.tcx.crate_disambiguator(n).to_fingerprint().as_value(),
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -132,7 +133,8 @@ pub fn get_extern_item_data(&self, item: &ast::ForeignItem) -> Option<Data> {
|
||||
let qualname = format!("::{}", self.tcx.node_path_str(item.id));
|
||||
match item.node {
|
||||
ast::ForeignItemKind::Fn(ref decl, ref generics) => {
|
||||
let sub_span = self.span_utils.sub_span_after_keyword(item.span, keywords::Fn);
|
||||
let sub_span = self.span_utils
|
||||
.sub_span_after_keyword(item.span, keywords::Fn);
|
||||
filter!(self.span_utils, sub_span, item.span, None);
|
||||
|
||||
Some(Data::DefData(Def {
|
||||
@@ -182,7 +184,8 @@ pub fn get_item_data(&self, item: &ast::Item) -> Option<Data> {
|
||||
match item.node {
|
||||
ast::ItemKind::Fn(ref decl, .., ref generics, _) => {
|
||||
let qualname = format!("::{}", self.tcx.node_path_str(item.id));
|
||||
let sub_span = self.span_utils.sub_span_after_keyword(item.span, keywords::Fn);
|
||||
let sub_span = self.span_utils
|
||||
.sub_span_after_keyword(item.span, keywords::Fn);
|
||||
filter!(self.span_utils, sub_span, item.span, None);
|
||||
Some(Data::DefData(Def {
|
||||
kind: DefKind::Function,
|
||||
@@ -230,7 +233,8 @@ pub fn get_item_data(&self, item: &ast::Item) -> Option<Data> {
|
||||
}
|
||||
ast::ItemKind::Const(ref typ, _) => {
|
||||
let qualname = format!("::{}", self.tcx.node_path_str(item.id));
|
||||
let sub_span = self.span_utils.sub_span_after_keyword(item.span, keywords::Const);
|
||||
let sub_span = self.span_utils
|
||||
.sub_span_after_keyword(item.span, keywords::Const);
|
||||
filter!(self.span_utils, sub_span, item.span, None);
|
||||
|
||||
let id = id_from_node_id(item.id, self);
|
||||
@@ -257,7 +261,8 @@ pub fn get_item_data(&self, item: &ast::Item) -> Option<Data> {
|
||||
let cm = self.tcx.sess.codemap();
|
||||
let filename = cm.span_to_filename(m.inner);
|
||||
|
||||
let sub_span = self.span_utils.sub_span_after_keyword(item.span, keywords::Mod);
|
||||
let sub_span = self.span_utils
|
||||
.sub_span_after_keyword(item.span, keywords::Mod);
|
||||
filter!(self.span_utils, sub_span, item.span, None);
|
||||
|
||||
Some(Data::DefData(Def {
|
||||
@@ -268,7 +273,10 @@ pub fn get_item_data(&self, item: &ast::Item) -> Option<Data> {
|
||||
span: self.span_from_span(sub_span.unwrap()),
|
||||
value: filename,
|
||||
parent: None,
|
||||
children: m.items.iter().map(|i| id_from_node_id(i.id, self)).collect(),
|
||||
children: m.items
|
||||
.iter()
|
||||
.map(|i| id_from_node_id(i.id, self))
|
||||
.collect(),
|
||||
decl_id: None,
|
||||
docs: self.docs_for_attrs(&item.attrs),
|
||||
sig: sig::item_signature(item, self),
|
||||
@@ -278,12 +286,14 @@ pub fn get_item_data(&self, item: &ast::Item) -> Option<Data> {
|
||||
ast::ItemKind::Enum(ref def, _) => {
|
||||
let name = item.ident.to_string();
|
||||
let qualname = format!("::{}", self.tcx.node_path_str(item.id));
|
||||
let sub_span = self.span_utils.sub_span_after_keyword(item.span, keywords::Enum);
|
||||
let sub_span = self.span_utils
|
||||
.sub_span_after_keyword(item.span, keywords::Enum);
|
||||
filter!(self.span_utils, sub_span, item.span, None);
|
||||
let variants_str = def.variants.iter()
|
||||
.map(|v| v.node.name.to_string())
|
||||
.collect::<Vec<_>>()
|
||||
.join(", ");
|
||||
let variants_str = def.variants
|
||||
.iter()
|
||||
.map(|v| v.node.name.to_string())
|
||||
.collect::<Vec<_>>()
|
||||
.join(", ");
|
||||
let value = format!("{}::{{{}}}", name, variants_str);
|
||||
Some(Data::DefData(Def {
|
||||
kind: DefKind::Enum,
|
||||
@@ -294,9 +304,9 @@ pub fn get_item_data(&self, item: &ast::Item) -> Option<Data> {
|
||||
value,
|
||||
parent: None,
|
||||
children: def.variants
|
||||
.iter()
|
||||
.map(|v| id_from_node_id(v.node.data.id(), self))
|
||||
.collect(),
|
||||
.iter()
|
||||
.map(|v| id_from_node_id(v.node.data.id(), self))
|
||||
.collect(),
|
||||
decl_id: None,
|
||||
docs: self.docs_for_attrs(&item.attrs),
|
||||
sig: sig::item_signature(item, self),
|
||||
@@ -313,15 +323,18 @@ pub fn get_item_data(&self, item: &ast::Item) -> Option<Data> {
|
||||
filter!(self.span_utils, sub_span, typ.span, None);
|
||||
|
||||
let type_data = self.lookup_ref_id(typ.id);
|
||||
type_data.map(|type_data| Data::RelationData(Relation {
|
||||
kind: RelationKind::Impl,
|
||||
span: self.span_from_span(sub_span.unwrap()),
|
||||
from: id_from_def_id(type_data),
|
||||
to: trait_ref.as_ref()
|
||||
.and_then(|t| self.lookup_ref_id(t.ref_id))
|
||||
.map(id_from_def_id)
|
||||
.unwrap_or(null_id()),
|
||||
}))
|
||||
type_data.map(|type_data| {
|
||||
Data::RelationData(Relation {
|
||||
kind: RelationKind::Impl,
|
||||
span: self.span_from_span(sub_span.unwrap()),
|
||||
from: id_from_def_id(type_data),
|
||||
to: trait_ref
|
||||
.as_ref()
|
||||
.and_then(|t| self.lookup_ref_id(t.ref_id))
|
||||
.map(id_from_def_id)
|
||||
.unwrap_or(null_id()),
|
||||
})
|
||||
})
|
||||
} else {
|
||||
None
|
||||
}
|
||||
@@ -333,14 +346,12 @@ pub fn get_item_data(&self, item: &ast::Item) -> Option<Data> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_field_data(&self,
|
||||
field: &ast::StructField,
|
||||
scope: NodeId)
|
||||
-> Option<Def> {
|
||||
pub fn get_field_data(&self, field: &ast::StructField, scope: NodeId) -> Option<Def> {
|
||||
if let Some(ident) = field.ident {
|
||||
let name = ident.to_string();
|
||||
let qualname = format!("::{}::{}", self.tcx.node_path_str(scope), ident);
|
||||
let sub_span = self.span_utils.sub_span_before_token(field.span, token::Colon);
|
||||
let sub_span = self.span_utils
|
||||
.sub_span_before_token(field.span, token::Colon);
|
||||
filter!(self.span_utils, sub_span, field.span, None);
|
||||
let def_id = self.tcx.hir.local_def_id(field.id);
|
||||
let typ = self.tcx.type_of(def_id).to_string();
|
||||
@@ -370,18 +381,13 @@ pub fn get_field_data(&self,
|
||||
|
||||
// FIXME would be nice to take a MethodItem here, but the ast provides both
|
||||
// trait and impl flavours, so the caller must do the disassembly.
|
||||
pub fn get_method_data(&self,
|
||||
id: ast::NodeId,
|
||||
name: ast::Name,
|
||||
span: Span)
|
||||
-> Option<Def> {
|
||||
pub fn get_method_data(&self, id: ast::NodeId, name: ast::Name, span: Span) -> Option<Def> {
|
||||
// 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.
|
||||
let (qualname, parent_scope, decl_id, docs, attributes) =
|
||||
match self.tcx.impl_of_method(self.tcx.hir.local_def_id(id)) {
|
||||
Some(impl_id) => match self.tcx.hir.get_if_local(impl_id) {
|
||||
Some(Node::NodeItem(item)) => {
|
||||
match item.node {
|
||||
match self.tcx.impl_of_method(self.tcx.hir.local_def_id(id)) {
|
||||
Some(impl_id) => match self.tcx.hir.get_if_local(impl_id) {
|
||||
Some(Node::NodeItem(item)) => match item.node {
|
||||
hir::ItemImpl(.., ref ty, _) => {
|
||||
let mut result = String::from("<");
|
||||
result.push_str(&self.tcx.hir.node_to_pretty_string(ty.id));
|
||||
@@ -391,7 +397,8 @@ pub fn get_method_data(&self,
|
||||
if let Some(def_id) = trait_id {
|
||||
result.push_str(" as ");
|
||||
result.push_str(&self.tcx.item_path_str(def_id));
|
||||
self.tcx.associated_items(def_id)
|
||||
self.tcx
|
||||
.associated_items(def_id)
|
||||
.find(|item| item.name == name)
|
||||
.map(|item| decl_id = Some(item.def_id));
|
||||
} else {
|
||||
@@ -403,53 +410,61 @@ pub fn get_method_data(&self,
|
||||
}
|
||||
result.push_str(">");
|
||||
|
||||
(result, trait_id, decl_id,
|
||||
self.docs_for_attrs(&item.attrs),
|
||||
item.attrs.to_vec())
|
||||
(
|
||||
result,
|
||||
trait_id,
|
||||
decl_id,
|
||||
self.docs_for_attrs(&item.attrs),
|
||||
item.attrs.to_vec(),
|
||||
)
|
||||
}
|
||||
_ => {
|
||||
span_bug!(span,
|
||||
"Container {:?} for method {} not an impl?",
|
||||
impl_id,
|
||||
id);
|
||||
span_bug!(
|
||||
span,
|
||||
"Container {:?} for method {} not an impl?",
|
||||
impl_id,
|
||||
id
|
||||
);
|
||||
}
|
||||
},
|
||||
r => {
|
||||
span_bug!(
|
||||
span,
|
||||
"Container {:?} for method {} is not a node item {:?}",
|
||||
impl_id,
|
||||
id,
|
||||
r
|
||||
);
|
||||
}
|
||||
}
|
||||
r => {
|
||||
span_bug!(span,
|
||||
"Container {:?} for method {} is not a node item {:?}",
|
||||
impl_id,
|
||||
id,
|
||||
r);
|
||||
}
|
||||
},
|
||||
None => match self.tcx.trait_of_item(self.tcx.hir.local_def_id(id)) {
|
||||
Some(def_id) => {
|
||||
match self.tcx.hir.get_if_local(def_id) {
|
||||
Some(Node::NodeItem(item)) => {
|
||||
(format!("::{}", self.tcx.item_path_str(def_id)),
|
||||
Some(def_id), None,
|
||||
self.docs_for_attrs(&item.attrs),
|
||||
item.attrs.to_vec())
|
||||
}
|
||||
},
|
||||
None => match self.tcx.trait_of_item(self.tcx.hir.local_def_id(id)) {
|
||||
Some(def_id) => match self.tcx.hir.get_if_local(def_id) {
|
||||
Some(Node::NodeItem(item)) => (
|
||||
format!("::{}", self.tcx.item_path_str(def_id)),
|
||||
Some(def_id),
|
||||
None,
|
||||
self.docs_for_attrs(&item.attrs),
|
||||
item.attrs.to_vec(),
|
||||
),
|
||||
r => {
|
||||
span_bug!(span,
|
||||
"Could not find container {:?} for \
|
||||
method {}, got {:?}",
|
||||
def_id,
|
||||
id,
|
||||
r);
|
||||
span_bug!(
|
||||
span,
|
||||
"Could not find container {:?} for \
|
||||
method {}, got {:?}",
|
||||
def_id,
|
||||
id,
|
||||
r
|
||||
);
|
||||
}
|
||||
},
|
||||
None => {
|
||||
debug!("Could not find container for method {} at {:?}", id, span);
|
||||
// This is not necessarily a bug, if there was a compilation error,
|
||||
// the tables we need might not exist.
|
||||
return None;
|
||||
}
|
||||
}
|
||||
None => {
|
||||
debug!("Could not find container for method {} at {:?}", id, span);
|
||||
// This is not necessarily a bug, if there was a compilation error, the tables
|
||||
// we need might not exist.
|
||||
return None;
|
||||
}
|
||||
},
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
let qualname = format!("{}::{}", qualname, name);
|
||||
|
||||
@@ -473,9 +488,7 @@ pub fn get_method_data(&self,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn get_trait_ref_data(&self,
|
||||
trait_ref: &ast::TraitRef)
|
||||
-> Option<Ref> {
|
||||
pub fn get_trait_ref_data(&self, trait_ref: &ast::TraitRef) -> Option<Ref> {
|
||||
self.lookup_ref_id(trait_ref.ref_id).and_then(|def_id| {
|
||||
let span = trait_ref.path.span;
|
||||
if generated_code(span) {
|
||||
@@ -503,8 +516,11 @@ pub fn get_expr_data(&self, expr: &ast::Expr) -> Option<Data> {
|
||||
let hir_node = match self.tcx.hir.find(sub_ex.id) {
|
||||
Some(Node::NodeExpr(expr)) => expr,
|
||||
_ => {
|
||||
debug!("Missing or weird node for sub-expression {} in {:?}",
|
||||
sub_ex.id, expr);
|
||||
debug!(
|
||||
"Missing or weird node for sub-expression {} in {:?}",
|
||||
sub_ex.id,
|
||||
expr
|
||||
);
|
||||
return None;
|
||||
}
|
||||
};
|
||||
@@ -548,7 +564,13 @@ pub fn get_expr_data(&self, expr: &ast::Expr) -> Option<Data> {
|
||||
}
|
||||
ast::ExprKind::MethodCall(ref seg, ..) => {
|
||||
let expr_hir_id = self.tcx.hir.definitions().node_to_hir_id(expr.id);
|
||||
let method_id = self.tables.type_dependent_defs()[expr_hir_id].def_id();
|
||||
let method_id = match self.tables.type_dependent_defs().get(expr_hir_id) {
|
||||
Some(id) => id.def_id(),
|
||||
None => {
|
||||
debug!("Could not resolve method id for {:?}", expr);
|
||||
return None;
|
||||
}
|
||||
};
|
||||
let (def_id, decl_id) = match self.tcx.associated_item(method_id).container {
|
||||
ty::ImplContainer(_) => (Some(method_id), None),
|
||||
ty::TraitContainer(_) => (None, Some(method_id)),
|
||||
@@ -559,7 +581,10 @@ pub fn get_expr_data(&self, expr: &ast::Expr) -> Option<Data> {
|
||||
Some(Data::RefData(Ref {
|
||||
kind: RefKind::Function,
|
||||
span,
|
||||
ref_id: def_id.or(decl_id).map(|id| id_from_def_id(id)).unwrap_or(null_id()),
|
||||
ref_id: def_id
|
||||
.or(decl_id)
|
||||
.map(|id| id_from_def_id(id))
|
||||
.unwrap_or(null_id()),
|
||||
}))
|
||||
}
|
||||
ast::ExprKind::Path(_, ref path) => {
|
||||
@@ -576,40 +601,61 @@ pub fn get_path_def(&self, id: NodeId) -> HirDef {
|
||||
match self.tcx.hir.get(id) {
|
||||
Node::NodeTraitRef(tr) => tr.path.def,
|
||||
|
||||
Node::NodeItem(&hir::Item { node: hir::ItemUse(ref path, _), .. }) |
|
||||
Node::NodeItem(&hir::Item {
|
||||
node: hir::ItemUse(ref path, _),
|
||||
..
|
||||
}) |
|
||||
Node::NodeVisibility(&hir::Visibility::Restricted { ref path, .. }) => path.def,
|
||||
|
||||
Node::NodeExpr(&hir::Expr { node: hir::ExprStruct(ref qpath, ..), .. }) |
|
||||
Node::NodeExpr(&hir::Expr { node: hir::ExprPath(ref qpath), .. }) |
|
||||
Node::NodePat(&hir::Pat { node: hir::PatKind::Path(ref qpath), .. }) |
|
||||
Node::NodePat(&hir::Pat { node: hir::PatKind::Struct(ref qpath, ..), .. }) |
|
||||
Node::NodePat(&hir::Pat { node: hir::PatKind::TupleStruct(ref qpath, ..), .. }) => {
|
||||
Node::NodeExpr(&hir::Expr {
|
||||
node: hir::ExprStruct(ref qpath, ..),
|
||||
..
|
||||
}) |
|
||||
Node::NodeExpr(&hir::Expr {
|
||||
node: hir::ExprPath(ref qpath),
|
||||
..
|
||||
}) |
|
||||
Node::NodePat(&hir::Pat {
|
||||
node: hir::PatKind::Path(ref qpath),
|
||||
..
|
||||
}) |
|
||||
Node::NodePat(&hir::Pat {
|
||||
node: hir::PatKind::Struct(ref qpath, ..),
|
||||
..
|
||||
}) |
|
||||
Node::NodePat(&hir::Pat {
|
||||
node: hir::PatKind::TupleStruct(ref qpath, ..),
|
||||
..
|
||||
}) => {
|
||||
let hir_id = self.tcx.hir.node_to_hir_id(id);
|
||||
self.tables.qpath_def(qpath, hir_id)
|
||||
}
|
||||
|
||||
Node::NodeBinding(&hir::Pat {
|
||||
node: hir::PatKind::Binding(_, canonical_id, ..), ..
|
||||
node: hir::PatKind::Binding(_, canonical_id, ..),
|
||||
..
|
||||
}) => HirDef::Local(canonical_id),
|
||||
|
||||
Node::NodeTy(ty) => {
|
||||
if let hir::Ty { node: hir::TyPath(ref qpath), .. } = *ty {
|
||||
match *qpath {
|
||||
hir::QPath::Resolved(_, ref path) => path.def,
|
||||
hir::QPath::TypeRelative(..) => {
|
||||
let ty = hir_ty_to_ty(self.tcx, ty);
|
||||
if let ty::TyProjection(proj) = ty.sty {
|
||||
return HirDef::AssociatedTy(proj.item_def_id);
|
||||
}
|
||||
HirDef::Err
|
||||
Node::NodeTy(ty) => if let hir::Ty {
|
||||
node: hir::TyPath(ref qpath),
|
||||
..
|
||||
} = *ty
|
||||
{
|
||||
match *qpath {
|
||||
hir::QPath::Resolved(_, ref path) => path.def,
|
||||
hir::QPath::TypeRelative(..) => {
|
||||
let ty = hir_ty_to_ty(self.tcx, ty);
|
||||
if let ty::TyProjection(proj) = ty.sty {
|
||||
return HirDef::AssociatedTy(proj.item_def_id);
|
||||
}
|
||||
HirDef::Err
|
||||
}
|
||||
} else {
|
||||
HirDef::Err
|
||||
}
|
||||
}
|
||||
} else {
|
||||
HirDef::Err
|
||||
},
|
||||
|
||||
_ => HirDef::Err
|
||||
_ => HirDef::Err,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -636,8 +682,7 @@ fn fn_type(path: &ast::Path) -> bool {
|
||||
let sub_span = last_seg.span;
|
||||
filter!(self.span_utils, Some(sub_span), path.span, None);
|
||||
match def {
|
||||
HirDef::Upvar(id, ..) |
|
||||
HirDef::Local(id) => {
|
||||
HirDef::Upvar(id, ..) | HirDef::Local(id) => {
|
||||
let span = self.span_from_span(sub_span);
|
||||
Some(Ref {
|
||||
kind: RefKind::Variable,
|
||||
@@ -660,10 +705,12 @@ fn fn_type(path: &ast::Path) -> bool {
|
||||
// Function type bounds are desugared in the parser, so we have to
|
||||
// special case them here.
|
||||
let fn_span = self.span_utils.span_for_first_ident(path.span);
|
||||
fn_span.map(|span| Ref {
|
||||
kind: RefKind::Type,
|
||||
span: self.span_from_span(span),
|
||||
ref_id: id_from_def_id(def_id),
|
||||
fn_span.map(|span| {
|
||||
Ref {
|
||||
kind: RefKind::Type,
|
||||
span: self.span_from_span(span),
|
||||
ref_id: id_from_def_id(def_id),
|
||||
}
|
||||
})
|
||||
}
|
||||
HirDef::Struct(def_id) |
|
||||
@@ -697,7 +744,8 @@ fn fn_type(path: &ast::Path) -> bool {
|
||||
HirDef::Method(decl_id) => {
|
||||
let def_id = if decl_id.is_local() {
|
||||
let ti = self.tcx.associated_item(decl_id);
|
||||
self.tcx.associated_items(ti.container.id())
|
||||
self.tcx
|
||||
.associated_items(ti.container.id())
|
||||
.find(|item| item.name == ti.name && item.defaultness.has_value())
|
||||
.map(|item| item.def_id)
|
||||
} else {
|
||||
@@ -735,10 +783,11 @@ fn fn_type(path: &ast::Path) -> bool {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_field_ref_data(&self,
|
||||
field_ref: &ast::Field,
|
||||
variant: &ty::VariantDef)
|
||||
-> Option<Ref> {
|
||||
pub fn get_field_ref_data(
|
||||
&self,
|
||||
field_ref: &ast::Field,
|
||||
variant: &ty::VariantDef,
|
||||
) -> Option<Ref> {
|
||||
let f = variant.field_named(field_ref.ident.node.name);
|
||||
// We don't really need a sub-span here, but no harm done
|
||||
let sub_span = self.span_utils.span_for_last_ident(field_ref.ident.span);
|
||||
@@ -776,7 +825,12 @@ pub fn get_macro_use_data(&self, span: Span) -> Option<MacroRef> {
|
||||
// If the callee is an imported macro from an external crate, need to get
|
||||
// the source span and name from the session, as their spans are localized
|
||||
// when read in, and no longer correspond to the source.
|
||||
if let Some(mac) = self.tcx.sess.imported_macro_spans.borrow().get(&callee_span) {
|
||||
if let Some(mac) = self.tcx
|
||||
.sess
|
||||
.imported_macro_spans
|
||||
.borrow()
|
||||
.get(&callee_span)
|
||||
{
|
||||
let &(ref mac_name, mac_span) = mac;
|
||||
let mac_span = self.span_from_span(mac_span);
|
||||
return Some(MacroRef {
|
||||
@@ -831,21 +885,29 @@ fn make_signature(decl: &ast::FnDecl, generics: &ast::Generics) -> String {
|
||||
let mut sig = "fn ".to_owned();
|
||||
if !generics.lifetimes.is_empty() || !generics.ty_params.is_empty() {
|
||||
sig.push('<');
|
||||
sig.push_str(&generics.lifetimes.iter()
|
||||
.map(|l| l.lifetime.ident.name.to_string())
|
||||
.collect::<Vec<_>>()
|
||||
.join(", "));
|
||||
sig.push_str(&generics
|
||||
.lifetimes
|
||||
.iter()
|
||||
.map(|l| l.lifetime.ident.name.to_string())
|
||||
.collect::<Vec<_>>()
|
||||
.join(", "));
|
||||
if !generics.lifetimes.is_empty() {
|
||||
sig.push_str(", ");
|
||||
}
|
||||
sig.push_str(&generics.ty_params.iter()
|
||||
.map(|l| l.ident.to_string())
|
||||
.collect::<Vec<_>>()
|
||||
.join(", "));
|
||||
sig.push_str(&generics
|
||||
.ty_params
|
||||
.iter()
|
||||
.map(|l| l.ident.to_string())
|
||||
.collect::<Vec<_>>()
|
||||
.join(", "));
|
||||
sig.push_str("> ");
|
||||
}
|
||||
sig.push('(');
|
||||
sig.push_str(&decl.inputs.iter().map(arg_to_string).collect::<Vec<_>>().join(", "));
|
||||
sig.push_str(&decl.inputs
|
||||
.iter()
|
||||
.map(arg_to_string)
|
||||
.collect::<Vec<_>>()
|
||||
.join(", "));
|
||||
sig.push(')');
|
||||
match decl.output {
|
||||
ast::FunctionRetTy::Default(_) => sig.push_str(" -> ()"),
|
||||
@@ -877,15 +939,16 @@ fn visit_pat(&mut self, p: &'a ast::Pat) {
|
||||
PatKind::Struct(ref path, ..) => {
|
||||
self.collected_paths.push((p.id, path));
|
||||
}
|
||||
PatKind::TupleStruct(ref path, ..) |
|
||||
PatKind::Path(_, ref path) => {
|
||||
PatKind::TupleStruct(ref path, ..) | PatKind::Path(_, ref path) => {
|
||||
self.collected_paths.push((p.id, path));
|
||||
}
|
||||
PatKind::Ident(bm, ref path1, _) => {
|
||||
debug!("PathCollector, visit ident in pat {}: {:?} {:?}",
|
||||
path1.node,
|
||||
p.span,
|
||||
path1.span);
|
||||
debug!(
|
||||
"PathCollector, visit ident in pat {}: {:?} {:?}",
|
||||
path1.node,
|
||||
p.span,
|
||||
path1.span
|
||||
);
|
||||
let immut = match bm {
|
||||
// Even if the ref is mut, you can't change the ref, only
|
||||
// the data pointed at, so showing the initialising expression
|
||||
@@ -893,7 +956,8 @@ fn visit_pat(&mut self, p: &'a ast::Pat) {
|
||||
ast::BindingMode::ByRef(_) => ast::Mutability::Immutable,
|
||||
ast::BindingMode::ByValue(mt) => mt,
|
||||
};
|
||||
self.collected_idents.push((p.id, path1.node, path1.span, immut));
|
||||
self.collected_idents
|
||||
.push((p.id, path1.node, path1.span, immut));
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
@@ -903,23 +967,25 @@ fn visit_pat(&mut self, p: &'a ast::Pat) {
|
||||
|
||||
/// Defines what to do with the results of saving the analysis.
|
||||
pub trait SaveHandler {
|
||||
fn save<'l, 'tcx>(&mut self,
|
||||
save_ctxt: SaveContext<'l, 'tcx>,
|
||||
krate: &ast::Crate,
|
||||
cratename: &str);
|
||||
fn save<'l, 'tcx>(
|
||||
&mut self,
|
||||
save_ctxt: SaveContext<'l, 'tcx>,
|
||||
krate: &ast::Crate,
|
||||
cratename: &str,
|
||||
);
|
||||
}
|
||||
|
||||
/// Dump the save-analysis results to a file.
|
||||
pub struct DumpHandler<'a> {
|
||||
odir: Option<&'a Path>,
|
||||
cratename: String
|
||||
cratename: String,
|
||||
}
|
||||
|
||||
impl<'a> DumpHandler<'a> {
|
||||
pub fn new(odir: Option<&'a Path>, cratename: &str) -> DumpHandler<'a> {
|
||||
DumpHandler {
|
||||
odir,
|
||||
cratename: cratename.to_owned()
|
||||
cratename: cratename.to_owned(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -937,8 +1003,10 @@ fn output_file(&self, ctx: &SaveContext) -> File {
|
||||
error!("Could not create directory {}: {}", root_path.display(), e);
|
||||
}
|
||||
|
||||
let executable =
|
||||
sess.crate_types.borrow().iter().any(|ct| *ct == CrateTypeExecutable);
|
||||
let executable = sess.crate_types
|
||||
.borrow()
|
||||
.iter()
|
||||
.any(|ct| *ct == CrateTypeExecutable);
|
||||
let mut out_name = if executable {
|
||||
"".to_owned()
|
||||
} else {
|
||||
@@ -955,19 +1023,21 @@ fn output_file(&self, ctx: &SaveContext) -> File {
|
||||
|
||||
info!("Writing output to {}", file_name.display());
|
||||
|
||||
let output_file = File::create(&file_name).unwrap_or_else(|e| {
|
||||
sess.fatal(&format!("Could not open {}: {}", file_name.display(), e))
|
||||
});
|
||||
let output_file = File::create(&file_name).unwrap_or_else(
|
||||
|e| sess.fatal(&format!("Could not open {}: {}", file_name.display(), e)),
|
||||
);
|
||||
|
||||
output_file
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> SaveHandler for DumpHandler<'a> {
|
||||
fn save<'l, 'tcx>(&mut self,
|
||||
save_ctxt: SaveContext<'l, 'tcx>,
|
||||
krate: &ast::Crate,
|
||||
cratename: &str) {
|
||||
fn save<'l, 'tcx>(
|
||||
&mut self,
|
||||
save_ctxt: SaveContext<'l, 'tcx>,
|
||||
krate: &ast::Crate,
|
||||
cratename: &str,
|
||||
) {
|
||||
let output = &mut self.output_file(&save_ctxt);
|
||||
let mut dumper = JsonDumper::new(output, save_ctxt.config.clone());
|
||||
let mut visitor = DumpVisitor::new(save_ctxt, &mut dumper);
|
||||
@@ -983,10 +1053,12 @@ pub struct CallbackHandler<'b> {
|
||||
}
|
||||
|
||||
impl<'b> SaveHandler for CallbackHandler<'b> {
|
||||
fn save<'l, 'tcx>(&mut self,
|
||||
save_ctxt: SaveContext<'l, 'tcx>,
|
||||
krate: &ast::Crate,
|
||||
cratename: &str) {
|
||||
fn save<'l, 'tcx>(
|
||||
&mut self,
|
||||
save_ctxt: SaveContext<'l, 'tcx>,
|
||||
krate: &ast::Crate,
|
||||
cratename: &str,
|
||||
) {
|
||||
// We're using the JsonDumper here because it has the format of the
|
||||
// save-analysis results that we will pass to the callback. IOW, we are
|
||||
// using the JsonDumper to collect the save-analysis results, but not
|
||||
@@ -1000,12 +1072,14 @@ fn save<'l, 'tcx>(&mut self,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn process_crate<'l, 'tcx, H: SaveHandler>(tcx: TyCtxt<'l, 'tcx, 'tcx>,
|
||||
krate: &ast::Crate,
|
||||
analysis: &'l ty::CrateAnalysis,
|
||||
cratename: &str,
|
||||
config: Option<Config>,
|
||||
mut handler: H) {
|
||||
pub fn process_crate<'l, 'tcx, H: SaveHandler>(
|
||||
tcx: TyCtxt<'l, 'tcx, 'tcx>,
|
||||
krate: &ast::Crate,
|
||||
analysis: &'l ty::CrateAnalysis,
|
||||
cratename: &str,
|
||||
config: Option<Config>,
|
||||
mut handler: H,
|
||||
) {
|
||||
let _ignore = tcx.dep_graph.in_ignore();
|
||||
|
||||
assert!(analysis.glob_map.is_some());
|
||||
@@ -1028,10 +1102,8 @@ fn find_config(supplied: Option<Config>) -> Config {
|
||||
return config;
|
||||
}
|
||||
match env::var_os("RUST_SAVE_ANALYSIS_CONFIG") {
|
||||
Some(config_string) => {
|
||||
rustc_serialize::json::decode(config_string.to_str().unwrap())
|
||||
.expect("Could not deserialize save-analysis config")
|
||||
},
|
||||
Some(config_string) => rustc_serialize::json::decode(config_string.to_str().unwrap())
|
||||
.expect("Could not deserialize save-analysis config"),
|
||||
None => Config::default(),
|
||||
}
|
||||
}
|
||||
|
||||
+152
-173
@@ -35,9 +35,9 @@
|
||||
//
|
||||
// FIXME where clauses need implementing, defs/refs in generics are mostly missing.
|
||||
|
||||
use {SaveContext, id_from_def_id, id_from_node_id};
|
||||
use {id_from_def_id, id_from_node_id, SaveContext};
|
||||
|
||||
use rls_data::{Signature, SigElement};
|
||||
use rls_data::{SigElement, Signature};
|
||||
|
||||
use rustc::hir::def::Def;
|
||||
use syntax::ast::{self, NodeId};
|
||||
@@ -75,36 +75,39 @@ pub fn variant_signature(variant: &ast::Variant, scx: &SaveContext) -> Option<Si
|
||||
variant.node.make(0, None, scx).ok()
|
||||
}
|
||||
|
||||
pub fn method_signature(id: NodeId,
|
||||
ident: ast::Ident,
|
||||
generics: &ast::Generics,
|
||||
m: &ast::MethodSig,
|
||||
scx: &SaveContext)
|
||||
-> Option<Signature> {
|
||||
pub fn method_signature(
|
||||
id: NodeId,
|
||||
ident: ast::Ident,
|
||||
generics: &ast::Generics,
|
||||
m: &ast::MethodSig,
|
||||
scx: &SaveContext,
|
||||
) -> Option<Signature> {
|
||||
if !scx.config.signatures {
|
||||
return None;
|
||||
}
|
||||
make_method_signature(id, ident, generics, m, scx).ok()
|
||||
}
|
||||
|
||||
pub fn assoc_const_signature(id: NodeId,
|
||||
ident: ast::Name,
|
||||
ty: &ast::Ty,
|
||||
default: Option<&ast::Expr>,
|
||||
scx: &SaveContext)
|
||||
-> Option<Signature> {
|
||||
pub fn assoc_const_signature(
|
||||
id: NodeId,
|
||||
ident: ast::Name,
|
||||
ty: &ast::Ty,
|
||||
default: Option<&ast::Expr>,
|
||||
scx: &SaveContext,
|
||||
) -> Option<Signature> {
|
||||
if !scx.config.signatures {
|
||||
return None;
|
||||
}
|
||||
make_assoc_const_signature(id, ident, ty, default, scx).ok()
|
||||
}
|
||||
|
||||
pub fn assoc_type_signature(id: NodeId,
|
||||
ident: ast::Ident,
|
||||
bounds: Option<&ast::TyParamBounds>,
|
||||
default: Option<&ast::Ty>,
|
||||
scx: &SaveContext)
|
||||
-> Option<Signature> {
|
||||
pub fn assoc_type_signature(
|
||||
id: NodeId,
|
||||
ident: ast::Ident,
|
||||
bounds: Option<&ast::TyParamBounds>,
|
||||
default: Option<&ast::Ty>,
|
||||
scx: &SaveContext,
|
||||
) -> Option<Signature> {
|
||||
if !scx.config.signatures {
|
||||
return None;
|
||||
}
|
||||
@@ -117,11 +120,12 @@ trait Sig {
|
||||
fn make(&self, offset: usize, id: Option<NodeId>, scx: &SaveContext) -> Result;
|
||||
}
|
||||
|
||||
fn extend_sig(mut sig: Signature,
|
||||
text: String,
|
||||
defs: Vec<SigElement>,
|
||||
refs: Vec<SigElement>)
|
||||
-> Signature {
|
||||
fn extend_sig(
|
||||
mut sig: Signature,
|
||||
text: String,
|
||||
defs: Vec<SigElement>,
|
||||
refs: Vec<SigElement>,
|
||||
) -> Signature {
|
||||
sig.text = text;
|
||||
sig.defs.extend(defs.into_iter());
|
||||
sig.refs.extend(refs.into_iter());
|
||||
@@ -142,8 +146,12 @@ fn merge_sigs(text: String, sigs: Vec<Signature>) -> Signature {
|
||||
|
||||
let (defs, refs): (Vec<_>, Vec<_>) = sigs.into_iter().map(|s| (s.defs, s.refs)).unzip();
|
||||
|
||||
result.defs.extend(defs.into_iter().flat_map(|ds| ds.into_iter()));
|
||||
result.refs.extend(refs.into_iter().flat_map(|rs| rs.into_iter()));
|
||||
result
|
||||
.defs
|
||||
.extend(defs.into_iter().flat_map(|ds| ds.into_iter()));
|
||||
result
|
||||
.refs
|
||||
.extend(refs.into_iter().flat_map(|rs| rs.into_iter()));
|
||||
|
||||
result
|
||||
}
|
||||
@@ -188,9 +196,7 @@ fn make(&self, offset: usize, _parent_id: Option<NodeId>, scx: &SaveContext) ->
|
||||
let text = format!("{}{}", prefix, nested.text);
|
||||
Ok(replace_text(nested, text))
|
||||
}
|
||||
ast::TyKind::Never => {
|
||||
Ok(text_sig("!".to_owned()))
|
||||
},
|
||||
ast::TyKind::Never => Ok(text_sig("!".to_owned())),
|
||||
ast::TyKind::Tup(ref ts) => {
|
||||
let mut text = "(".to_owned();
|
||||
let mut defs = vec![];
|
||||
@@ -215,8 +221,11 @@ fn make(&self, offset: usize, _parent_id: Option<NodeId>, scx: &SaveContext) ->
|
||||
if !f.lifetimes.is_empty() {
|
||||
// FIXME defs, bounds on lifetimes
|
||||
text.push_str("for<");
|
||||
text.push_str(&f.lifetimes.iter().map(|l|
|
||||
l.lifetime.ident.to_string()).collect::<Vec<_>>().join(", "));
|
||||
text.push_str(&f.lifetimes
|
||||
.iter()
|
||||
.map(|l| l.lifetime.ident.to_string())
|
||||
.collect::<Vec<_>>()
|
||||
.join(", "));
|
||||
text.push('>');
|
||||
}
|
||||
|
||||
@@ -251,9 +260,7 @@ fn make(&self, offset: usize, _parent_id: Option<NodeId>, scx: &SaveContext) ->
|
||||
|
||||
Ok(Signature { text, defs, refs })
|
||||
}
|
||||
ast::TyKind::Path(None, ref path) => {
|
||||
path.make(offset, id, scx)
|
||||
}
|
||||
ast::TyKind::Path(None, ref path) => path.make(offset, id, scx),
|
||||
ast::TyKind::Path(Some(ref qself), ref path) => {
|
||||
let nested_ty = qself.ty.make(offset + 1, id, scx)?;
|
||||
let prefix = if qself.position == 0 {
|
||||
@@ -325,11 +332,13 @@ fn make(&self, offset: usize, _parent_id: Option<NodeId>, scx: &SaveContext) ->
|
||||
text.push_str("mut ");
|
||||
}
|
||||
let name = self.ident.to_string();
|
||||
let defs = vec![SigElement {
|
||||
id: id_from_node_id(self.id, scx),
|
||||
start: offset + text.len(),
|
||||
end: offset + text.len() + name.len(),
|
||||
}];
|
||||
let defs = vec![
|
||||
SigElement {
|
||||
id: id_from_node_id(self.id, scx),
|
||||
start: offset + text.len(),
|
||||
end: offset + text.len() + name.len(),
|
||||
},
|
||||
];
|
||||
text.push_str(&name);
|
||||
text.push_str(": ");
|
||||
|
||||
@@ -346,11 +355,13 @@ fn make(&self, offset: usize, _parent_id: Option<NodeId>, scx: &SaveContext) ->
|
||||
ast::ItemKind::Const(ref ty, ref expr) => {
|
||||
let mut text = "const ".to_owned();
|
||||
let name = self.ident.to_string();
|
||||
let defs = vec![SigElement {
|
||||
id: id_from_node_id(self.id, scx),
|
||||
start: offset + text.len(),
|
||||
end: offset + text.len() + name.len(),
|
||||
}];
|
||||
let defs = vec![
|
||||
SigElement {
|
||||
id: id_from_node_id(self.id, scx),
|
||||
start: offset + text.len(),
|
||||
end: offset + text.len() + name.len(),
|
||||
},
|
||||
];
|
||||
text.push_str(&name);
|
||||
text.push_str(": ");
|
||||
|
||||
@@ -379,12 +390,7 @@ fn make(&self, offset: usize, _parent_id: Option<NodeId>, scx: &SaveContext) ->
|
||||
}
|
||||
text.push_str("fn ");
|
||||
|
||||
let mut sig = name_and_generics(text,
|
||||
offset,
|
||||
generics,
|
||||
self.id,
|
||||
self.ident,
|
||||
scx)?;
|
||||
let mut sig = name_and_generics(text, offset, generics, self.id, self.ident, scx)?;
|
||||
|
||||
sig.text.push('(');
|
||||
for i in &decl.inputs {
|
||||
@@ -413,11 +419,13 @@ fn make(&self, offset: usize, _parent_id: Option<NodeId>, scx: &SaveContext) ->
|
||||
ast::ItemKind::Mod(ref _mod) => {
|
||||
let mut text = "mod ".to_owned();
|
||||
let name = self.ident.to_string();
|
||||
let defs = vec![SigElement {
|
||||
id: id_from_node_id(self.id, scx),
|
||||
start: offset + text.len(),
|
||||
end: offset + text.len() + name.len(),
|
||||
}];
|
||||
let defs = vec![
|
||||
SigElement {
|
||||
id: id_from_node_id(self.id, scx),
|
||||
start: offset + text.len(),
|
||||
end: offset + text.len() + name.len(),
|
||||
},
|
||||
];
|
||||
text.push_str(&name);
|
||||
// Could be either `mod foo;` or `mod foo { ... }`, but we'll just puck one.
|
||||
text.push(';');
|
||||
@@ -430,12 +438,7 @@ fn make(&self, offset: usize, _parent_id: Option<NodeId>, scx: &SaveContext) ->
|
||||
}
|
||||
ast::ItemKind::Ty(ref ty, ref generics) => {
|
||||
let text = "type ".to_owned();
|
||||
let mut sig = name_and_generics(text,
|
||||
offset,
|
||||
generics,
|
||||
self.id,
|
||||
self.ident,
|
||||
scx)?;
|
||||
let mut sig = name_and_generics(text, offset, generics, self.id, self.ident, scx)?;
|
||||
|
||||
sig.text.push_str(" = ");
|
||||
let ty = ty.make(offset + sig.text.len(), id, scx)?;
|
||||
@@ -446,34 +449,19 @@ fn make(&self, offset: usize, _parent_id: Option<NodeId>, scx: &SaveContext) ->
|
||||
}
|
||||
ast::ItemKind::Enum(_, ref generics) => {
|
||||
let text = "enum ".to_owned();
|
||||
let mut sig = name_and_generics(text,
|
||||
offset,
|
||||
generics,
|
||||
self.id,
|
||||
self.ident,
|
||||
scx)?;
|
||||
let mut sig = name_and_generics(text, offset, generics, self.id, self.ident, scx)?;
|
||||
sig.text.push_str(" {}");
|
||||
Ok(sig)
|
||||
}
|
||||
ast::ItemKind::Struct(_, ref generics) => {
|
||||
let text = "struct ".to_owned();
|
||||
let mut sig = name_and_generics(text,
|
||||
offset,
|
||||
generics,
|
||||
self.id,
|
||||
self.ident,
|
||||
scx)?;
|
||||
let mut sig = name_and_generics(text, offset, generics, self.id, self.ident, scx)?;
|
||||
sig.text.push_str(" {}");
|
||||
Ok(sig)
|
||||
}
|
||||
ast::ItemKind::Union(_, ref generics) => {
|
||||
let text = "union ".to_owned();
|
||||
let mut sig = name_and_generics(text,
|
||||
offset,
|
||||
generics,
|
||||
self.id,
|
||||
self.ident,
|
||||
scx)?;
|
||||
let mut sig = name_and_generics(text, offset, generics, self.id, self.ident, scx)?;
|
||||
sig.text.push_str(" {}");
|
||||
Ok(sig)
|
||||
}
|
||||
@@ -488,12 +476,7 @@ fn make(&self, offset: usize, _parent_id: Option<NodeId>, scx: &SaveContext) ->
|
||||
text.push_str("unsafe ");
|
||||
}
|
||||
text.push_str("trait ");
|
||||
let mut sig = name_and_generics(text,
|
||||
offset,
|
||||
generics,
|
||||
self.id,
|
||||
self.ident,
|
||||
scx)?;
|
||||
let mut sig = name_and_generics(text, offset, generics, self.id, self.ident, scx)?;
|
||||
|
||||
if !bounds.is_empty() {
|
||||
sig.text.push_str(": ");
|
||||
@@ -515,13 +498,15 @@ fn make(&self, offset: usize, _parent_id: Option<NodeId>, scx: &SaveContext) ->
|
||||
text.push_str(" for .. {}");
|
||||
Ok(replace_text(trait_sig, text))
|
||||
}
|
||||
ast::ItemKind::Impl(unsafety,
|
||||
polarity,
|
||||
defaultness,
|
||||
ref generics,
|
||||
ref opt_trait,
|
||||
ref ty,
|
||||
_) => {
|
||||
ast::ItemKind::Impl(
|
||||
unsafety,
|
||||
polarity,
|
||||
defaultness,
|
||||
ref generics,
|
||||
ref opt_trait,
|
||||
ref ty,
|
||||
_,
|
||||
) => {
|
||||
let mut text = String::new();
|
||||
if let ast::Defaultness::Default = defaultness {
|
||||
text.push_str("default ");
|
||||
@@ -562,8 +547,7 @@ fn make(&self, offset: usize, _parent_id: Option<NodeId>, scx: &SaveContext) ->
|
||||
ast::ItemKind::ExternCrate(_) => Err("extern crate"),
|
||||
// FIXME should implement this (e.g., pub use).
|
||||
ast::ItemKind::Use(_) => Err("import"),
|
||||
ast::ItemKind::Mac(..) |
|
||||
ast::ItemKind::MacroDef(_) => Err("Macro"),
|
||||
ast::ItemKind::Mac(..) | ast::ItemKind::MacroDef(_) => Err("Macro"),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -573,19 +557,14 @@ fn make(&self, offset: usize, id: Option<NodeId>, scx: &SaveContext) -> Result {
|
||||
let def = scx.get_path_def(id.ok_or("Missing id for Path")?);
|
||||
|
||||
let (name, start, end) = match def {
|
||||
Def::Label(..) |
|
||||
Def::PrimTy(..) |
|
||||
Def::SelfTy(..) |
|
||||
Def::Err => {
|
||||
Def::Label(..) | Def::PrimTy(..) | Def::SelfTy(..) | Def::Err => {
|
||||
return Ok(Signature {
|
||||
text: pprust::path_to_string(self),
|
||||
defs: vec![],
|
||||
refs: vec![],
|
||||
})
|
||||
}
|
||||
Def::AssociatedConst(..) |
|
||||
Def::Variant(..) |
|
||||
Def::VariantCtor(..) => {
|
||||
Def::AssociatedConst(..) | Def::Variant(..) | Def::VariantCtor(..) => {
|
||||
let len = self.segments.len();
|
||||
if len < 2 {
|
||||
return Err("Bad path");
|
||||
@@ -635,9 +614,11 @@ fn make(&self, offset: usize, _parent_id: Option<NodeId>, scx: &SaveContext) ->
|
||||
|
||||
if !l.bounds.is_empty() {
|
||||
l_text.push_str(": ");
|
||||
let bounds = l.bounds.iter().map(|l| {
|
||||
l.ident.to_string()
|
||||
}).collect::<Vec<_>>().join(" + ");
|
||||
let bounds = l.bounds
|
||||
.iter()
|
||||
.map(|l| l.ident.to_string())
|
||||
.collect::<Vec<_>>()
|
||||
.join(" + ");
|
||||
l_text.push_str(&bounds);
|
||||
// FIXME add lifetime bounds refs.
|
||||
}
|
||||
@@ -662,7 +643,11 @@ fn make(&self, offset: usize, _parent_id: Option<NodeId>, scx: &SaveContext) ->
|
||||
}
|
||||
|
||||
text.push('>');
|
||||
Ok(Signature {text, defs, refs: vec![] })
|
||||
Ok(Signature {
|
||||
text,
|
||||
defs,
|
||||
refs: vec![],
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -710,11 +695,7 @@ fn make(&self, offset: usize, _parent_id: Option<NodeId>, scx: &SaveContext) ->
|
||||
refs.extend(field_sig.refs.into_iter());
|
||||
}
|
||||
text.push('}');
|
||||
Ok(Signature {
|
||||
text,
|
||||
defs,
|
||||
refs,
|
||||
})
|
||||
Ok(Signature { text, defs, refs })
|
||||
}
|
||||
ast::VariantData::Tuple(ref fields, id) => {
|
||||
let name_def = SigElement {
|
||||
@@ -733,11 +714,7 @@ fn make(&self, offset: usize, _parent_id: Option<NodeId>, scx: &SaveContext) ->
|
||||
refs.extend(field_sig.refs.into_iter());
|
||||
}
|
||||
text.push(')');
|
||||
Ok(Signature {
|
||||
text,
|
||||
defs,
|
||||
refs,
|
||||
})
|
||||
Ok(Signature { text, defs, refs })
|
||||
}
|
||||
ast::VariantData::Unit(id) => {
|
||||
let name_def = SigElement {
|
||||
@@ -763,12 +740,7 @@ fn make(&self, offset: usize, _parent_id: Option<NodeId>, scx: &SaveContext) ->
|
||||
let mut text = String::new();
|
||||
text.push_str("fn ");
|
||||
|
||||
let mut sig = name_and_generics(text,
|
||||
offset,
|
||||
generics,
|
||||
self.id,
|
||||
self.ident,
|
||||
scx)?;
|
||||
let mut sig = name_and_generics(text, offset, generics, self.id, self.ident, scx)?;
|
||||
|
||||
sig.text.push('(');
|
||||
for i in &decl.inputs {
|
||||
@@ -800,11 +772,13 @@ fn make(&self, offset: usize, _parent_id: Option<NodeId>, scx: &SaveContext) ->
|
||||
text.push_str("mut ");
|
||||
}
|
||||
let name = self.ident.to_string();
|
||||
let defs = vec![SigElement {
|
||||
id: id_from_node_id(self.id, scx),
|
||||
start: offset + text.len(),
|
||||
end: offset + text.len() + name.len(),
|
||||
}];
|
||||
let defs = vec![
|
||||
SigElement {
|
||||
id: id_from_node_id(self.id, scx),
|
||||
start: offset + text.len(),
|
||||
end: offset + text.len() + name.len(),
|
||||
},
|
||||
];
|
||||
text.push_str(&name);
|
||||
text.push_str(": ");
|
||||
|
||||
@@ -816,11 +790,13 @@ fn make(&self, offset: usize, _parent_id: Option<NodeId>, scx: &SaveContext) ->
|
||||
ast::ForeignItemKind::Ty => {
|
||||
let mut text = "type ".to_owned();
|
||||
let name = self.ident.to_string();
|
||||
let defs = vec![SigElement {
|
||||
id: id_from_node_id(self.id, scx),
|
||||
start: offset + text.len(),
|
||||
end: offset + text.len() + name.len(),
|
||||
}];
|
||||
let defs = vec![
|
||||
SigElement {
|
||||
id: id_from_node_id(self.id, scx),
|
||||
start: offset + text.len(),
|
||||
end: offset + text.len() + name.len(),
|
||||
},
|
||||
];
|
||||
text.push_str(&name);
|
||||
text.push(';');
|
||||
|
||||
@@ -834,13 +810,14 @@ fn make(&self, offset: usize, _parent_id: Option<NodeId>, scx: &SaveContext) ->
|
||||
}
|
||||
}
|
||||
|
||||
fn name_and_generics(mut text: String,
|
||||
offset: usize,
|
||||
generics: &ast::Generics,
|
||||
id: NodeId,
|
||||
name: ast::Ident,
|
||||
scx: &SaveContext)
|
||||
-> Result {
|
||||
fn name_and_generics(
|
||||
mut text: String,
|
||||
offset: usize,
|
||||
generics: &ast::Generics,
|
||||
id: NodeId,
|
||||
name: ast::Ident,
|
||||
scx: &SaveContext,
|
||||
) -> Result {
|
||||
let name = name.to_string();
|
||||
let def = SigElement {
|
||||
id: id_from_node_id(id, scx),
|
||||
@@ -855,19 +832,22 @@ fn name_and_generics(mut text: String,
|
||||
}
|
||||
|
||||
|
||||
fn make_assoc_type_signature(id: NodeId,
|
||||
ident: ast::Ident,
|
||||
bounds: Option<&ast::TyParamBounds>,
|
||||
default: Option<&ast::Ty>,
|
||||
scx: &SaveContext)
|
||||
-> Result {
|
||||
fn make_assoc_type_signature(
|
||||
id: NodeId,
|
||||
ident: ast::Ident,
|
||||
bounds: Option<&ast::TyParamBounds>,
|
||||
default: Option<&ast::Ty>,
|
||||
scx: &SaveContext,
|
||||
) -> Result {
|
||||
let mut text = "type ".to_owned();
|
||||
let name = ident.to_string();
|
||||
let mut defs = vec![SigElement {
|
||||
id: id_from_node_id(id, scx),
|
||||
start: text.len(),
|
||||
end: text.len() + name.len(),
|
||||
}];
|
||||
let mut defs = vec![
|
||||
SigElement {
|
||||
id: id_from_node_id(id, scx),
|
||||
start: text.len(),
|
||||
end: text.len() + name.len(),
|
||||
},
|
||||
];
|
||||
let mut refs = vec![];
|
||||
text.push_str(&name);
|
||||
if let Some(bounds) = bounds {
|
||||
@@ -886,19 +866,22 @@ fn make_assoc_type_signature(id: NodeId,
|
||||
Ok(Signature { text, defs, refs })
|
||||
}
|
||||
|
||||
fn make_assoc_const_signature(id: NodeId,
|
||||
ident: ast::Name,
|
||||
ty: &ast::Ty,
|
||||
default: Option<&ast::Expr>,
|
||||
scx: &SaveContext)
|
||||
-> Result {
|
||||
fn make_assoc_const_signature(
|
||||
id: NodeId,
|
||||
ident: ast::Name,
|
||||
ty: &ast::Ty,
|
||||
default: Option<&ast::Expr>,
|
||||
scx: &SaveContext,
|
||||
) -> Result {
|
||||
let mut text = "const ".to_owned();
|
||||
let name = ident.to_string();
|
||||
let mut defs = vec![SigElement {
|
||||
id: id_from_node_id(id, scx),
|
||||
start: text.len(),
|
||||
end: text.len() + name.len(),
|
||||
}];
|
||||
let mut defs = vec![
|
||||
SigElement {
|
||||
id: id_from_node_id(id, scx),
|
||||
start: text.len(),
|
||||
end: text.len() + name.len(),
|
||||
},
|
||||
];
|
||||
let mut refs = vec![];
|
||||
text.push_str(&name);
|
||||
text.push_str(": ");
|
||||
@@ -916,12 +899,13 @@ fn make_assoc_const_signature(id: NodeId,
|
||||
Ok(Signature { text, defs, refs })
|
||||
}
|
||||
|
||||
fn make_method_signature(id: NodeId,
|
||||
ident: ast::Ident,
|
||||
generics: &ast::Generics,
|
||||
m: &ast::MethodSig,
|
||||
scx: &SaveContext)
|
||||
-> Result {
|
||||
fn make_method_signature(
|
||||
id: NodeId,
|
||||
ident: ast::Ident,
|
||||
generics: &ast::Generics,
|
||||
m: &ast::MethodSig,
|
||||
scx: &SaveContext,
|
||||
) -> Result {
|
||||
// FIXME code dup with function signature
|
||||
let mut text = String::new();
|
||||
if m.constness.node == ast::Constness::Const {
|
||||
@@ -937,12 +921,7 @@ fn make_method_signature(id: NodeId,
|
||||
}
|
||||
text.push_str("fn ");
|
||||
|
||||
let mut sig = name_and_generics(text,
|
||||
0,
|
||||
generics,
|
||||
id,
|
||||
ident,
|
||||
scx)?;
|
||||
let mut sig = name_and_generics(text, 0, generics, id, ident, scx)?;
|
||||
|
||||
sig.text.push('(');
|
||||
for i in &m.decl.inputs {
|
||||
|
||||
@@ -42,7 +42,11 @@ pub fn make_path_string(file_name: &str) -> String {
|
||||
if path.is_absolute() {
|
||||
path.clone().display().to_string()
|
||||
} else {
|
||||
env::current_dir().unwrap().join(&path).display().to_string()
|
||||
env::current_dir()
|
||||
.unwrap()
|
||||
.join(&path)
|
||||
.display()
|
||||
.to_string()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,7 +70,7 @@ pub fn span_for_last_ident(&self, span: Span) -> Option<Span> {
|
||||
loop {
|
||||
let ts = toks.real_token();
|
||||
if ts.tok == token::Eof {
|
||||
return result
|
||||
return result;
|
||||
}
|
||||
if bracket_count == 0 && (ts.tok.is_ident() || ts.tok.is_keyword(keywords::SelfValue)) {
|
||||
result = Some(ts.sp);
|
||||
@@ -122,10 +126,9 @@ pub fn sub_span_for_type_name(&self, span: Span) -> Option<Span> {
|
||||
loop {
|
||||
let next = toks.real_token();
|
||||
|
||||
if (next.tok == token::Lt || next.tok == token::Colon) &&
|
||||
angle_count == 0 &&
|
||||
bracket_count == 0 &&
|
||||
prev.tok.is_ident() {
|
||||
if (next.tok == token::Lt || next.tok == token::Colon) && angle_count == 0
|
||||
&& bracket_count == 0 && prev.tok.is_ident()
|
||||
{
|
||||
result = Some(prev.sp);
|
||||
}
|
||||
|
||||
@@ -152,12 +155,14 @@ pub fn sub_span_for_type_name(&self, span: Span) -> Option<Span> {
|
||||
}
|
||||
if angle_count != 0 || bracket_count != 0 {
|
||||
let loc = self.sess.codemap().lookup_char_pos(span.lo());
|
||||
span_bug!(span,
|
||||
"Mis-counted brackets when breaking path? Parsing '{}' \
|
||||
in {}, line {}",
|
||||
self.snippet(span),
|
||||
loc.file.name,
|
||||
loc.line);
|
||||
span_bug!(
|
||||
span,
|
||||
"Mis-counted brackets when breaking path? Parsing '{}' \
|
||||
in {}, line {}",
|
||||
self.snippet(span),
|
||||
loc.file.name,
|
||||
loc.line
|
||||
);
|
||||
}
|
||||
if result.is_none() && prev.tok.is_ident() && angle_count == 0 {
|
||||
return Some(prev.sp);
|
||||
@@ -211,7 +216,7 @@ fn sub_span_after<F: Fn(Token) -> bool>(&self, span: Span, f: F) -> Option<Span>
|
||||
if f(ts.tok) {
|
||||
let ts = toks.real_token();
|
||||
if ts.tok == token::Eof {
|
||||
return None
|
||||
return None;
|
||||
} else {
|
||||
return Some(ts.sp);
|
||||
}
|
||||
@@ -278,7 +283,12 @@ pub fn filter_generated(&self, sub_span: Option<Span>, parent: Span) -> bool {
|
||||
};
|
||||
|
||||
//If the span comes from a fake filemap, filter it.
|
||||
if !self.sess.codemap().lookup_char_pos(parent.lo()).file.is_real_file() {
|
||||
if !self.sess
|
||||
.codemap()
|
||||
.lookup_char_pos(parent.lo())
|
||||
.file
|
||||
.is_real_file()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user