Auto merge of #28698 - nrc:fmt8, r=brson
This commit is contained in:
commit
3729b126e2
@ -28,6 +28,8 @@
|
||||
#![feature(box_patterns)]
|
||||
#![feature(box_syntax)]
|
||||
#![feature(const_fn)]
|
||||
#![feature(custom_attribute)]
|
||||
#![allow(unused_attributes)]
|
||||
#![feature(iter_cmp)]
|
||||
#![feature(iter_arith)]
|
||||
#![feature(libc)]
|
||||
|
@ -86,7 +86,10 @@ pub fn new(tcx: &'l ty::ctxt<'tcx>,
|
||||
save_ctxt: SaveContext::from_span_utils(tcx, span_utils.clone()),
|
||||
analysis: analysis,
|
||||
span: span_utils.clone(),
|
||||
fmt: FmtStrs::new(box Recorder { out: output_file, dump_spans: false },
|
||||
fmt: FmtStrs::new(box Recorder {
|
||||
out: output_file,
|
||||
dump_spans: false,
|
||||
},
|
||||
span_utils),
|
||||
cur_scope: 0,
|
||||
}
|
||||
@ -123,13 +126,16 @@ fn process_path_prefixes(&self, path: &ast::Path) -> Vec<(Span, String)> {
|
||||
// always using the first ones. So, only error out if we don't have enough spans.
|
||||
// What could go wrong...?
|
||||
if spans.len() < path.segments.len() {
|
||||
error!("Mis-calculated spans for path '{}'. \
|
||||
Found {} spans, expected {}. Found spans:",
|
||||
path_to_string(path), spans.len(), path.segments.len());
|
||||
error!("Mis-calculated spans for path '{}'. Found {} spans, expected {}. Found spans:",
|
||||
path_to_string(path),
|
||||
spans.len(),
|
||||
path.segments.len());
|
||||
for s in &spans {
|
||||
let loc = self.sess.codemap().lookup_char_pos(s.lo);
|
||||
error!(" '{}' in {}, line {}",
|
||||
self.span.snippet(*s), loc.file.name, loc.line);
|
||||
self.span.snippet(*s),
|
||||
loc.file.name,
|
||||
loc.line);
|
||||
}
|
||||
return vec!();
|
||||
}
|
||||
@ -168,10 +174,7 @@ fn write_sub_paths(&mut self, path: &ast::Path, global: bool) {
|
||||
} else {
|
||||
qualname.clone()
|
||||
};
|
||||
self.fmt.sub_mod_ref_str(path.span,
|
||||
*span,
|
||||
&qualname,
|
||||
self.cur_scope);
|
||||
self.fmt.sub_mod_ref_str(path.span, *span, &qualname, self.cur_scope);
|
||||
}
|
||||
}
|
||||
|
||||
@ -191,10 +194,7 @@ fn write_sub_paths_truncated(&mut self, path: &ast::Path, global: bool) {
|
||||
} else {
|
||||
qualname.clone()
|
||||
};
|
||||
self.fmt.sub_mod_ref_str(path.span,
|
||||
*span,
|
||||
&qualname,
|
||||
self.cur_scope);
|
||||
self.fmt.sub_mod_ref_str(path.span, *span, &qualname, self.cur_scope);
|
||||
}
|
||||
}
|
||||
|
||||
@ -210,9 +210,7 @@ fn write_sub_path_trait_truncated(&mut self, path: &ast::Path) {
|
||||
|
||||
// write the trait part of the sub-path
|
||||
let (ref span, ref qualname) = sub_paths[len-2];
|
||||
self.fmt.sub_type_ref_str(path.span,
|
||||
*span,
|
||||
&qualname);
|
||||
self.fmt.sub_type_ref_str(path.span, *span, &qualname);
|
||||
|
||||
// write the other sub-paths
|
||||
if len <= 2 {
|
||||
@ -220,10 +218,7 @@ fn write_sub_path_trait_truncated(&mut self, path: &ast::Path) {
|
||||
}
|
||||
let sub_paths = &sub_paths[..len-2];
|
||||
for &(ref span, ref qualname) in sub_paths {
|
||||
self.fmt.sub_mod_ref_str(path.span,
|
||||
*span,
|
||||
&qualname,
|
||||
self.cur_scope);
|
||||
self.fmt.sub_mod_ref_str(path.span, *span, &qualname, self.cur_scope);
|
||||
}
|
||||
}
|
||||
|
||||
@ -231,7 +226,7 @@ fn write_sub_path_trait_truncated(&mut self, path: &ast::Path) {
|
||||
fn lookup_type_ref(&self, ref_id: NodeId) -> Option<DefId> {
|
||||
if !self.tcx.def_map.borrow().contains_key(&ref_id) {
|
||||
self.sess.bug(&format!("def_map has no key for {} in lookup_type_ref",
|
||||
ref_id));
|
||||
ref_id));
|
||||
}
|
||||
let def = self.tcx.def_map.borrow().get(&ref_id).unwrap().full_def();
|
||||
match def {
|
||||
@ -244,8 +239,9 @@ fn lookup_type_ref(&self, ref_id: NodeId) -> Option<DefId> {
|
||||
fn lookup_def_kind(&self, ref_id: NodeId, span: Span) -> Option<recorder::Row> {
|
||||
let def_map = self.tcx.def_map.borrow();
|
||||
if !def_map.contains_key(&ref_id) {
|
||||
self.sess.span_bug(span, &format!("def_map has no key for {} in lookup_def_kind",
|
||||
ref_id));
|
||||
self.sess.span_bug(span,
|
||||
&format!("def_map has no key for {} in lookup_def_kind",
|
||||
ref_id));
|
||||
}
|
||||
let def = def_map.get(&ref_id).unwrap().full_def();
|
||||
match def {
|
||||
@ -270,8 +266,8 @@ fn lookup_def_kind(&self, ref_id: NodeId, span: Span) -> Option<recorder::Row> {
|
||||
def::DefUse(_) |
|
||||
def::DefMethod(..) |
|
||||
def::DefPrimTy(_) => {
|
||||
self.sess.span_bug(span, &format!("lookup_def_kind for unexpected item: {:?}",
|
||||
def));
|
||||
self.sess.span_bug(span,
|
||||
&format!("lookup_def_kind for unexpected item: {:?}", def));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -340,10 +336,7 @@ fn process_method(&mut self,
|
||||
self.nest(id, |v| v.visit_block(body));
|
||||
}
|
||||
|
||||
self.process_generic_params(&sig.generics,
|
||||
span,
|
||||
&method_data.qualname,
|
||||
id);
|
||||
self.process_generic_params(&sig.generics, span, &method_data.qualname, id);
|
||||
}
|
||||
|
||||
fn process_trait_ref(&mut self, trait_ref: &ast::TraitRef) {
|
||||
@ -382,18 +375,14 @@ fn process_generic_params(&mut self,
|
||||
// However full span is the entire enum/fn/struct block, so we only want
|
||||
// the first few to match the number of generics we're looking for.
|
||||
let param_sub_spans = self.span.spans_for_ty_params(full_span,
|
||||
(generics.ty_params.len() as isize));
|
||||
(generics.ty_params.len() as isize));
|
||||
for (param, param_ss) in generics.ty_params.iter().zip(param_sub_spans) {
|
||||
// Append $id to name to make sure each one is unique
|
||||
let name = format!("{}::{}${}",
|
||||
prefix,
|
||||
escape(self.span.snippet(param_ss)),
|
||||
id);
|
||||
self.fmt.typedef_str(full_span,
|
||||
Some(param_ss),
|
||||
param.id,
|
||||
&name,
|
||||
"");
|
||||
self.fmt.typedef_str(full_span, Some(param_ss), param.id, &name, "");
|
||||
}
|
||||
self.visit_generics(generics);
|
||||
}
|
||||
@ -450,8 +439,7 @@ fn process_const(&mut self,
|
||||
expr: &ast::Expr) {
|
||||
let qualname = format!("::{}", self.tcx.map.path_to_string(id));
|
||||
|
||||
let sub_span = self.span.sub_span_after_keyword(span,
|
||||
keywords::Const);
|
||||
let sub_span = self.span.sub_span_after_keyword(span, keywords::Const);
|
||||
|
||||
self.fmt.static_str(span,
|
||||
sub_span,
|
||||
@ -631,10 +619,7 @@ fn process_trait(&mut self,
|
||||
sub_span,
|
||||
id,
|
||||
self.cur_scope);
|
||||
self.fmt.inherit_str(trait_ref.path.span,
|
||||
sub_span,
|
||||
id,
|
||||
item.id);
|
||||
self.fmt.inherit_str(trait_ref.path.span, sub_span, id, item.id);
|
||||
}
|
||||
None => (),
|
||||
}
|
||||
@ -669,18 +654,18 @@ fn process_path(&mut self, id: NodeId, path: &ast::Path, ref_kind: Option<record
|
||||
Some(pd) => pd,
|
||||
None => {
|
||||
self.tcx.sess.span_bug(path.span,
|
||||
&format!("Unexpected def kind while looking \
|
||||
up path in `{}`",
|
||||
&format!("Unexpected def kind while looking up path in \
|
||||
`{}`",
|
||||
self.span.snippet(path.span)))
|
||||
}
|
||||
};
|
||||
match path_data {
|
||||
Data::VariableRefData(ref vrd) => {
|
||||
self.fmt.ref_str(ref_kind.unwrap_or(recorder::VarRef),
|
||||
path.span,
|
||||
Some(vrd.span),
|
||||
vrd.ref_id,
|
||||
vrd.scope);
|
||||
path.span,
|
||||
Some(vrd.span),
|
||||
vrd.ref_id,
|
||||
vrd.scope);
|
||||
|
||||
}
|
||||
Data::TypeRefData(ref trd) => {
|
||||
@ -698,10 +683,7 @@ fn process_path(&mut self, id: NodeId, path: &ast::Path, ref_kind: Option<record
|
||||
mcd.scope);
|
||||
}
|
||||
Data::FunctionCallData(fcd) => {
|
||||
self.fmt.fn_call_str(path.span,
|
||||
Some(fcd.span),
|
||||
fcd.ref_id,
|
||||
fcd.scope);
|
||||
self.fmt.fn_call_str(path.span, Some(fcd.span), fcd.ref_id, fcd.scope);
|
||||
}
|
||||
_ => {
|
||||
self.sess.span_bug(path.span,
|
||||
@ -758,9 +740,7 @@ fn process_struct_lit(&mut self,
|
||||
continue;
|
||||
}
|
||||
|
||||
let field_data = self.save_ctxt.get_field_ref_data(field,
|
||||
variant,
|
||||
scope);
|
||||
let field_data = self.save_ctxt.get_field_ref_data(field, variant, scope);
|
||||
self.fmt.ref_str(recorder::VarRef,
|
||||
field.ident.span,
|
||||
Some(field_data.span),
|
||||
@ -807,11 +787,7 @@ fn process_pat(&mut self, p: &ast::Pat) {
|
||||
|
||||
let sub_span = self.span.span_for_first_ident(span);
|
||||
if let Some(f) = variant.find_field_named(field.ident.name) {
|
||||
self.fmt.ref_str(recorder::VarRef,
|
||||
span,
|
||||
sub_span,
|
||||
f.did,
|
||||
self.cur_scope);
|
||||
self.fmt.ref_str(recorder::VarRef, span, sub_span, f.did, self.cur_scope);
|
||||
}
|
||||
self.visit_pat(&field.pat);
|
||||
}
|
||||
@ -849,11 +825,11 @@ fn visit_item(&mut self, item: &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) {
|
||||
Some(sub_span) => Some(sub_span),
|
||||
None => sub_span,
|
||||
};
|
||||
let sub_span = match self.span.sub_span_after_keyword(use_item.span,
|
||||
keywords::As) {
|
||||
Some(sub_span) => Some(sub_span),
|
||||
None => sub_span,
|
||||
};
|
||||
|
||||
self.fmt.use_alias_str(path.span,
|
||||
sub_span,
|
||||
@ -877,8 +853,8 @@ fn visit_item(&mut self, item: &ast::Item) {
|
||||
}
|
||||
}
|
||||
|
||||
let sub_span = self.span.sub_span_of_token(path.span,
|
||||
token::BinOp(token::Star));
|
||||
let sub_span = self.span
|
||||
.sub_span_of_token(path.span, token::BinOp(token::Star));
|
||||
self.fmt.use_glob_str(path.span,
|
||||
sub_span,
|
||||
item.id,
|
||||
@ -893,10 +869,11 @@ fn visit_item(&mut self, item: &ast::Item) {
|
||||
match self.lookup_type_ref(id) {
|
||||
Some(def_id) => match self.lookup_def_kind(id, plid.span) {
|
||||
Some(kind) => {
|
||||
self.fmt.ref_str(
|
||||
kind, plid.span,
|
||||
Some(plid.span),
|
||||
def_id, self.cur_scope);
|
||||
self.fmt.ref_str(kind,
|
||||
plid.span,
|
||||
Some(plid.span),
|
||||
def_id,
|
||||
self.cur_scope);
|
||||
}
|
||||
None => (),
|
||||
},
|
||||
@ -942,11 +919,7 @@ fn visit_item(&mut self, item: &ast::Item) {
|
||||
ref trait_ref,
|
||||
ref typ,
|
||||
ref impl_items) => {
|
||||
self.process_impl(item,
|
||||
ty_params,
|
||||
trait_ref,
|
||||
&typ,
|
||||
impl_items)
|
||||
self.process_impl(item, ty_params, trait_ref, &typ, impl_items)
|
||||
}
|
||||
ast::ItemTrait(_, ref generics, ref trait_refs, ref methods) =>
|
||||
self.process_trait(item, generics, trait_refs, methods),
|
||||
@ -958,11 +931,7 @@ fn visit_item(&mut self, item: &ast::Item) {
|
||||
let qualname = format!("::{}", self.tcx.map.path_to_string(item.id));
|
||||
let value = ty_to_string(&**ty);
|
||||
let sub_span = self.span.sub_span_after_keyword(item.span, keywords::Type);
|
||||
self.fmt.typedef_str(item.span,
|
||||
sub_span,
|
||||
item.id,
|
||||
&qualname,
|
||||
&value);
|
||||
self.fmt.typedef_str(item.span, sub_span, item.id, &qualname, &value);
|
||||
|
||||
self.visit_ty(&**ty);
|
||||
self.process_generic_params(ty_params, item.span, &qualname, item.id);
|
||||
@ -988,8 +957,11 @@ fn visit_generics(&mut self, generics: &ast::Generics) {
|
||||
fn visit_trait_item(&mut self, trait_item: &ast::TraitItem) {
|
||||
match trait_item.node {
|
||||
ast::ConstTraitItem(ref ty, Some(ref expr)) => {
|
||||
self.process_const(trait_item.id, trait_item.ident.name,
|
||||
trait_item.span, &*ty, &*expr);
|
||||
self.process_const(trait_item.id,
|
||||
trait_item.ident.name,
|
||||
trait_item.span,
|
||||
&*ty,
|
||||
&*expr);
|
||||
}
|
||||
ast::MethodTraitItem(ref sig, ref body) => {
|
||||
self.process_method(sig,
|
||||
@ -1006,8 +978,11 @@ fn visit_trait_item(&mut self, trait_item: &ast::TraitItem) {
|
||||
fn visit_impl_item(&mut self, impl_item: &ast::ImplItem) {
|
||||
match impl_item.node {
|
||||
ast::ConstImplItem(ref ty, ref expr) => {
|
||||
self.process_const(impl_item.id, impl_item.ident.name,
|
||||
impl_item.span, &ty, &expr);
|
||||
self.process_const(impl_item.id,
|
||||
impl_item.ident.name,
|
||||
impl_item.span,
|
||||
&ty,
|
||||
&expr);
|
||||
}
|
||||
ast::MethodImplItem(ref sig, ref body) => {
|
||||
self.process_method(sig,
|
||||
@ -1031,11 +1006,7 @@ fn visit_ty(&mut self, t: &ast::Ty) {
|
||||
match self.lookup_type_ref(t.id) {
|
||||
Some(id) => {
|
||||
let sub_span = self.span.sub_span_for_type_name(t.span);
|
||||
self.fmt.ref_str(recorder::TypeRef,
|
||||
t.span,
|
||||
sub_span,
|
||||
id,
|
||||
self.cur_scope);
|
||||
self.fmt.ref_str(recorder::TypeRef, t.span, sub_span, id, self.cur_scope);
|
||||
}
|
||||
None => (),
|
||||
}
|
||||
@ -1067,11 +1038,7 @@ fn visit_expr(&mut self, ex: &ast::Expr) {
|
||||
let hir_expr = lower_expr(ex);
|
||||
let adt = self.tcx.expr_ty(&hir_expr).ty_adt_def().unwrap();
|
||||
let def = self.tcx.resolve_expr(&hir_expr);
|
||||
self.process_struct_lit(ex,
|
||||
path,
|
||||
fields,
|
||||
adt.variant_of_def(def),
|
||||
base)
|
||||
self.process_struct_lit(ex, path, fields, adt.variant_of_def(def), base)
|
||||
}
|
||||
ast::ExprMethodCall(_, _, ref args) => self.process_method_call(ex, args),
|
||||
ast::ExprField(ref sub_ex, _) => {
|
||||
@ -1110,8 +1077,8 @@ fn visit_expr(&mut self, ex: &ast::Expr) {
|
||||
}
|
||||
ty::TyTuple(_) => {}
|
||||
_ => self.sess.span_bug(ex.span,
|
||||
&format!("Expected struct or tuple \
|
||||
type, found {:?}", ty)),
|
||||
&format!("Expected struct or tuple type, found {:?}",
|
||||
ty)),
|
||||
}
|
||||
}
|
||||
ast::ExprClosure(_, ref decl, ref body) => {
|
||||
@ -1165,8 +1132,7 @@ fn visit_arm(&mut self, arm: &ast::Arm) {
|
||||
let def_map = self.tcx.def_map.borrow();
|
||||
if !def_map.contains_key(&id) {
|
||||
self.sess.span_bug(p.span,
|
||||
&format!("def_map has no key for {} in visit_arm",
|
||||
id));
|
||||
&format!("def_map has no key for {} in visit_arm", id));
|
||||
}
|
||||
let def = def_map.get(&id).unwrap().full_def();
|
||||
match def {
|
||||
@ -1177,13 +1143,9 @@ fn visit_arm(&mut self, arm: &ast::Arm) {
|
||||
"<mutable>".to_string()
|
||||
};
|
||||
|
||||
assert!(p.segments.len() == 1, "qualified path for local variable def in arm");
|
||||
self.fmt.variable_str(p.span,
|
||||
Some(p.span),
|
||||
id,
|
||||
&path_to_string(p),
|
||||
&value,
|
||||
"")
|
||||
assert!(p.segments.len() == 1,
|
||||
"qualified path for local variable def in arm");
|
||||
self.fmt.variable_str(p.span, Some(p.span), id, &path_to_string(p), &value, "")
|
||||
}
|
||||
def::DefVariant(..) | def::DefTy(..) | def::DefStruct(..) => {
|
||||
paths_to_process.push((id, p.clone(), Some(ref_kind)))
|
||||
@ -1237,12 +1199,7 @@ fn visit_local(&mut self, l: &ast::Local) {
|
||||
// is only ever a variable name, but who knows?).
|
||||
let sub_span = self.span.span_for_last_ident(p.span);
|
||||
// Rust uses the id of the pattern for var lookups, so we'll use it too.
|
||||
self.fmt.variable_str(p.span,
|
||||
sub_span,
|
||||
id,
|
||||
&path_to_string(p),
|
||||
&value,
|
||||
&typ);
|
||||
self.fmt.variable_str(p.span, sub_span, id, &path_to_string(p), &value, &typ);
|
||||
}
|
||||
|
||||
// Just walk the initialiser and type (don't want to walk the pattern again).
|
||||
|
@ -184,7 +184,10 @@ pub fn new(tcx: &'l ty::ctxt<'tcx>) -> SaveContext<'l, 'tcx> {
|
||||
pub fn from_span_utils(tcx: &'l ty::ctxt<'tcx>,
|
||||
span_utils: SpanUtils<'l>)
|
||||
-> SaveContext<'l, 'tcx> {
|
||||
SaveContext { tcx: tcx, span_utils: span_utils }
|
||||
SaveContext {
|
||||
tcx: tcx,
|
||||
span_utils: span_utils,
|
||||
}
|
||||
}
|
||||
|
||||
// List external crates used by the current crate.
|
||||
@ -192,7 +195,10 @@ pub fn get_external_crates(&self) -> Vec<CrateData> {
|
||||
let mut result = Vec::new();
|
||||
|
||||
self.tcx.sess.cstore.iter_crate_data(|n, cmd| {
|
||||
result.push(CrateData { name: cmd.name.clone(), number: n });
|
||||
result.push(CrateData {
|
||||
name: cmd.name.clone(),
|
||||
number: n,
|
||||
});
|
||||
});
|
||||
|
||||
result
|
||||
@ -289,10 +295,12 @@ pub fn get_item_data(&self, item: &ast::Item) -> Data {
|
||||
// Common case impl for a struct or something basic.
|
||||
ast::TyPath(None, ref path) => {
|
||||
sub_span = self.span_utils.sub_span_for_type_name(path.span).unwrap();
|
||||
type_data = self.lookup_ref_id(typ.id).map(|id| TypeRefData {
|
||||
span: sub_span,
|
||||
scope: parent,
|
||||
ref_id: id,
|
||||
type_data = self.lookup_ref_id(typ.id).map(|id| {
|
||||
TypeRefData {
|
||||
span: sub_span,
|
||||
scope: parent,
|
||||
ref_id: id,
|
||||
}
|
||||
});
|
||||
}
|
||||
_ => {
|
||||
@ -302,8 +310,8 @@ pub fn get_item_data(&self, item: &ast::Item) -> Data {
|
||||
}
|
||||
}
|
||||
|
||||
let trait_data =
|
||||
trait_ref.as_ref().and_then(|tr| self.get_trait_ref_data(tr, parent));
|
||||
let trait_data = trait_ref.as_ref()
|
||||
.and_then(|tr| self.get_trait_ref_data(tr, parent));
|
||||
|
||||
Data::ImplData(ImplData {
|
||||
id: item.id,
|
||||
@ -323,11 +331,8 @@ pub fn get_item_data(&self, item: &ast::Item) -> Data {
|
||||
pub fn get_field_data(&self, field: &ast::StructField, scope: NodeId) -> Option<VariableData> {
|
||||
match field.node.kind {
|
||||
ast::NamedField(ident, _) => {
|
||||
let qualname = format!("::{}::{}",
|
||||
self.tcx.map.path_to_string(scope),
|
||||
ident);
|
||||
let typ = self.tcx.node_types().get(&field.node.id).unwrap()
|
||||
.to_string();
|
||||
let qualname = format!("::{}::{}", self.tcx.map.path_to_string(scope), ident);
|
||||
let typ = self.tcx.node_types().get(&field.node.id).unwrap().to_string();
|
||||
let sub_span = self.span_utils.sub_span_before_token(field.span, token::Colon);
|
||||
Some(VariableData {
|
||||
id: field.node.id,
|
||||
@ -359,8 +364,7 @@ pub fn get_method_data(&self, id: ast::NodeId, name: ast::Name, span: Span) -> F
|
||||
match self.tcx.trait_of_item(self.tcx.map.local_def_id(id)) {
|
||||
Some(def_id) => {
|
||||
result.push_str(" as ");
|
||||
result.push_str(
|
||||
&self.tcx.item_path_str(def_id));
|
||||
result.push_str(&self.tcx.item_path_str(def_id));
|
||||
}
|
||||
None => {}
|
||||
}
|
||||
@ -369,16 +373,21 @@ pub fn get_method_data(&self, id: ast::NodeId, name: ast::Name, span: Span) -> F
|
||||
}
|
||||
_ => {
|
||||
self.tcx.sess.span_bug(span,
|
||||
&format!("Container {:?} for method {} not an impl?",
|
||||
impl_id, id));
|
||||
&format!("Container {:?} for method {} not \
|
||||
an impl?",
|
||||
impl_id,
|
||||
id));
|
||||
}
|
||||
}
|
||||
}
|
||||
r => {
|
||||
self.tcx.sess.span_bug(span,
|
||||
&format!("Container {:?} for method {} is not a node item {:?}",
|
||||
impl_id, id, r));
|
||||
},
|
||||
&format!("Container {:?} for method {} is not a node \
|
||||
item {:?}",
|
||||
impl_id,
|
||||
id,
|
||||
r));
|
||||
}
|
||||
},
|
||||
None => match self.tcx.trait_of_item(self.tcx.map.local_def_id(id)) {
|
||||
Some(def_id) => {
|
||||
@ -388,14 +397,17 @@ pub fn get_method_data(&self, id: ast::NodeId, name: ast::Name, span: Span) -> F
|
||||
}
|
||||
r => {
|
||||
self.tcx.sess.span_bug(span,
|
||||
&format!("Could not find container {:?} for method {}, got {:?}",
|
||||
def_id, id, r));
|
||||
&format!("Could not find container {:?} for \
|
||||
method {}, got {:?}",
|
||||
def_id,
|
||||
id,
|
||||
r));
|
||||
}
|
||||
}
|
||||
}
|
||||
None => {
|
||||
self.tcx.sess.span_bug(span,
|
||||
&format!("Could not find container for method {}", id));
|
||||
&format!("Could not find container for method {}", id));
|
||||
}
|
||||
},
|
||||
};
|
||||
@ -403,16 +415,14 @@ pub fn get_method_data(&self, id: ast::NodeId, name: ast::Name, span: Span) -> F
|
||||
let qualname = format!("{}::{}", qualname, name);
|
||||
|
||||
let def_id = self.tcx.map.local_def_id(id);
|
||||
let decl_id =
|
||||
self.tcx.trait_item_of_item(def_id)
|
||||
.and_then(|new_id| {
|
||||
let new_def_id = new_id.def_id();
|
||||
if new_def_id != def_id {
|
||||
Some(new_def_id)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
});
|
||||
let decl_id = self.tcx.trait_item_of_item(def_id).and_then(|new_id| {
|
||||
let new_def_id = new_id.def_id();
|
||||
if new_def_id != def_id {
|
||||
Some(new_def_id)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
});
|
||||
|
||||
let sub_span = self.span_utils.sub_span_after_keyword(span, keywords::Fn);
|
||||
|
||||
@ -547,11 +557,10 @@ pub fn get_path_data(&self, id: NodeId, path: &ast::Path) -> Option<Data> {
|
||||
let ti = self.tcx.impl_or_trait_item(decl_id);
|
||||
match ti.container() {
|
||||
ty::TraitContainer(def_id) => {
|
||||
self.tcx.trait_items(def_id)
|
||||
self.tcx
|
||||
.trait_items(def_id)
|
||||
.iter()
|
||||
.find(|mr| {
|
||||
mr.name() == ti.name() && self.trait_method_has_body(mr)
|
||||
})
|
||||
.find(|mr| mr.name() == ti.name() && self.trait_method_has_body(mr))
|
||||
.map(|mr| mr.def_id())
|
||||
}
|
||||
ty::ImplContainer(def_id) => {
|
||||
@ -560,9 +569,9 @@ pub fn get_path_data(&self, id: NodeId, path: &ast::Path) -> Option<Data> {
|
||||
.unwrap()
|
||||
.iter()
|
||||
.find(|mr| {
|
||||
self.tcx.impl_or_trait_item(mr.def_id()).name()
|
||||
== ti.name()
|
||||
})
|
||||
self.tcx.impl_or_trait_item(mr.def_id()).name() ==
|
||||
ti.name()
|
||||
})
|
||||
.unwrap()
|
||||
.def_id())
|
||||
}
|
||||
@ -668,10 +677,7 @@ fn visit_pat(&mut self, p: &ast::Pat) {
|
||||
|
||||
match p.node {
|
||||
ast::PatStruct(ref path, _, _) => {
|
||||
self.collected_paths.push((p.id,
|
||||
path.clone(),
|
||||
ast::MutMutable,
|
||||
recorder::TypeRef));
|
||||
self.collected_paths.push((p.id, path.clone(), ast::MutMutable, recorder::TypeRef));
|
||||
}
|
||||
ast::PatEnum(ref path, _) |
|
||||
ast::PatQPath(_, ref path) => {
|
||||
@ -729,7 +735,8 @@ pub fn process_crate(tcx: &ty::ctxt,
|
||||
|
||||
if let Err(e) = fs::create_dir_all(&root_path) {
|
||||
tcx.sess.err(&format!("Could not create directory {}: {}",
|
||||
root_path.display(), e));
|
||||
root_path.display(),
|
||||
e));
|
||||
}
|
||||
|
||||
{
|
||||
|
@ -22,7 +22,10 @@
|
||||
use syntax::ast::NodeId;
|
||||
use syntax::codemap::*;
|
||||
|
||||
const CRATE_ROOT_DEF_ID: DefId = DefId { krate: LOCAL_CRATE, index: CRATE_DEF_INDEX };
|
||||
const CRATE_ROOT_DEF_ID: DefId = DefId {
|
||||
krate: LOCAL_CRATE,
|
||||
index: CRATE_DEF_INDEX,
|
||||
};
|
||||
|
||||
pub struct Recorder {
|
||||
// output file
|
||||
@ -41,7 +44,9 @@ pub fn record(&mut self, info: &str) {
|
||||
pub fn dump_span(&mut self, su: SpanUtils, kind: &str, span: Span, _sub_span: Option<Span>) {
|
||||
assert!(self.dump_spans);
|
||||
let result = format!("span,kind,{},{},text,\"{}\"\n",
|
||||
kind, su.extent_str(span), escape(su.snippet(span)));
|
||||
kind,
|
||||
su.extent_str(span),
|
||||
escape(su.snippet(span)));
|
||||
self.record(&result[..]);
|
||||
}
|
||||
}
|
||||
@ -93,7 +98,10 @@ pub enum Row {
|
||||
|
||||
impl<'a> FmtStrs<'a> {
|
||||
pub fn new(rec: Box<Recorder>, span: SpanUtils<'a>) -> FmtStrs<'a> {
|
||||
FmtStrs { recorder: rec, span: span }
|
||||
FmtStrs {
|
||||
recorder: rec,
|
||||
span: span,
|
||||
}
|
||||
}
|
||||
|
||||
// A map from kind of item to a tuple of
|
||||
@ -104,52 +112,93 @@ pub fn new(rec: Box<Recorder>, span: SpanUtils<'a>) -> FmtStrs<'a> {
|
||||
fn lookup_row(r: Row) -> (&'static str, Vec<&'static str>, bool, bool) {
|
||||
match r {
|
||||
Variable => ("variable",
|
||||
vec!("id","name","qualname","value","type","scopeid"),
|
||||
vec!("id", "name", "qualname", "value", "type", "scopeid"),
|
||||
true,
|
||||
true),
|
||||
Enum => ("enum", vec!("id","qualname","scopeid","value"), true, true),
|
||||
Enum => ("enum",
|
||||
vec!("id", "qualname", "scopeid", "value"),
|
||||
true,
|
||||
true),
|
||||
Variant => ("variant",
|
||||
vec!("id","name","qualname","type","value","scopeid"),
|
||||
vec!("id", "name", "qualname", "type", "value", "scopeid"),
|
||||
true,
|
||||
true),
|
||||
VariantStruct => ("variant_struct",
|
||||
vec!("id","ctor_id","qualname","type","value","scopeid"),
|
||||
vec!("id", "ctor_id", "qualname", "type", "value", "scopeid"),
|
||||
true,
|
||||
true),
|
||||
Function => ("function",
|
||||
vec!("id","qualname","declid","declidcrate","scopeid"),
|
||||
vec!("id", "qualname", "declid", "declidcrate", "scopeid"),
|
||||
true,
|
||||
true),
|
||||
MethodDecl => ("method_decl", vec!("id","qualname","scopeid"), true, true),
|
||||
Struct => ("struct", vec!("id","ctor_id","qualname","scopeid","value"), true, true),
|
||||
Trait => ("trait", vec!("id","qualname","scopeid","value"), true, true),
|
||||
MethodDecl => ("method_decl",
|
||||
vec!("id", "qualname", "scopeid"),
|
||||
true,
|
||||
true),
|
||||
Struct => ("struct",
|
||||
vec!("id", "ctor_id", "qualname", "scopeid", "value"),
|
||||
true,
|
||||
true),
|
||||
Trait => ("trait",
|
||||
vec!("id", "qualname", "scopeid", "value"),
|
||||
true,
|
||||
true),
|
||||
Impl => ("impl",
|
||||
vec!("id","refid","refidcrate","traitid","traitidcrate","scopeid"),
|
||||
vec!("id",
|
||||
"refid",
|
||||
"refidcrate",
|
||||
"traitid",
|
||||
"traitidcrate",
|
||||
"scopeid"),
|
||||
true,
|
||||
true),
|
||||
Module => ("module", vec!("id","qualname","scopeid","def_file"), true, false),
|
||||
UseAlias => ("use_alias", vec!("id","refid","refidcrate","name","scopeid"), true, true),
|
||||
UseGlob => ("use_glob", vec!("id","value","scopeid"), true, true),
|
||||
Module => ("module",
|
||||
vec!("id", "qualname", "scopeid", "def_file"),
|
||||
true,
|
||||
false),
|
||||
UseAlias => ("use_alias",
|
||||
vec!("id", "refid", "refidcrate", "name", "scopeid"),
|
||||
true,
|
||||
true),
|
||||
UseGlob => ("use_glob", vec!("id", "value", "scopeid"), true, true),
|
||||
ExternCrate => ("extern_crate",
|
||||
vec!("id","name","location","crate","scopeid"),
|
||||
vec!("id", "name", "location", "crate", "scopeid"),
|
||||
true,
|
||||
true),
|
||||
Inheritance => ("inheritance",
|
||||
vec!("base","basecrate","derived","derivedcrate"),
|
||||
vec!("base", "basecrate", "derived", "derivedcrate"),
|
||||
true,
|
||||
false),
|
||||
MethodCall => ("method_call",
|
||||
vec!("refid","refidcrate","declid","declidcrate","scopeid"),
|
||||
vec!("refid", "refidcrate", "declid", "declidcrate", "scopeid"),
|
||||
true,
|
||||
true),
|
||||
Typedef => ("typedef", vec!("id","qualname","value"), true, true),
|
||||
ExternalCrate => ("external_crate", vec!("name","crate","file_name"), false, false),
|
||||
Typedef => ("typedef", vec!("id", "qualname", "value"), true, true),
|
||||
ExternalCrate => ("external_crate",
|
||||
vec!("name", "crate", "file_name"),
|
||||
false,
|
||||
false),
|
||||
Crate => ("crate", vec!("name"), true, false),
|
||||
FnCall => ("fn_call", vec!("refid","refidcrate","qualname","scopeid"), true, true),
|
||||
ModRef => ("mod_ref", vec!("refid","refidcrate","qualname","scopeid"), true, true),
|
||||
VarRef => ("var_ref", vec!("refid","refidcrate","qualname","scopeid"), true, true),
|
||||
TypeRef => ("type_ref", vec!("refid","refidcrate","qualname","scopeid"), true, true),
|
||||
FnRef => ("fn_ref", vec!("refid","refidcrate","qualname","scopeid"), true, true),
|
||||
FnCall => ("fn_call",
|
||||
vec!("refid", "refidcrate", "qualname", "scopeid"),
|
||||
true,
|
||||
true),
|
||||
ModRef => ("mod_ref",
|
||||
vec!("refid", "refidcrate", "qualname", "scopeid"),
|
||||
true,
|
||||
true),
|
||||
VarRef => ("var_ref",
|
||||
vec!("refid", "refidcrate", "qualname", "scopeid"),
|
||||
true,
|
||||
true),
|
||||
TypeRef => ("type_ref",
|
||||
vec!("refid", "refidcrate", "qualname", "scopeid"),
|
||||
true,
|
||||
true),
|
||||
FnRef => ("fn_ref",
|
||||
vec!("refid", "refidcrate", "qualname", "scopeid"),
|
||||
true,
|
||||
true),
|
||||
}
|
||||
}
|
||||
|
||||
@ -160,9 +209,12 @@ pub fn make_values_str(&self,
|
||||
span: Span)
|
||||
-> Option<String> {
|
||||
if values.len() != fields.len() {
|
||||
self.span.sess.span_bug(span, &format!(
|
||||
"Mismatch between length of fields for '{}', expected '{}', found '{}'",
|
||||
kind, fields.len(), values.len()));
|
||||
self.span.sess.span_bug(span,
|
||||
&format!("Mismatch between length of fields for '{}', \
|
||||
expected '{}', found '{}'",
|
||||
kind,
|
||||
fields.len(),
|
||||
values.len()));
|
||||
}
|
||||
|
||||
let values = values.iter().map(|s| {
|
||||
@ -176,19 +228,21 @@ pub fn make_values_str(&self,
|
||||
|
||||
let pairs = fields.iter().zip(values);
|
||||
let strs = pairs.map(|(f, v)| format!(",{},\"{}\"", f, escape(String::from(v))));
|
||||
Some(strs.fold(String::new(), |mut s, ss| {
|
||||
s.push_str(&ss[..]);
|
||||
s
|
||||
}))
|
||||
Some(strs.fold(String::new(),
|
||||
|mut s, ss| {
|
||||
s.push_str(&ss[..]);
|
||||
s
|
||||
}))
|
||||
}
|
||||
|
||||
pub fn record_without_span(&mut self, kind: Row, values: Vec<String>, span: Span) {
|
||||
let (label, ref fields, needs_span, dump_spans) = FmtStrs::lookup_row(kind);
|
||||
|
||||
if needs_span {
|
||||
self.span.sess.span_bug(span, &format!(
|
||||
"Called record_without_span for '{}' which does requires a span",
|
||||
label));
|
||||
self.span.sess.span_bug(span,
|
||||
&format!("Called record_without_span for '{}' which does \
|
||||
requires a span",
|
||||
label));
|
||||
}
|
||||
assert!(!dump_spans);
|
||||
|
||||
@ -216,25 +270,26 @@ pub fn record_with_span(&mut self,
|
||||
|
||||
if self.recorder.dump_spans {
|
||||
if dump_spans {
|
||||
self.recorder.dump_span(self.span.clone(),
|
||||
label,
|
||||
span,
|
||||
Some(sub_span));
|
||||
self.recorder.dump_span(self.span.clone(), label, span, Some(sub_span));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if !needs_span {
|
||||
self.span.sess.span_bug(span,
|
||||
&format!("Called record_with_span for '{}' \
|
||||
which does not require a span", label));
|
||||
&format!("Called record_with_span for '{}' which does not \
|
||||
require a span",
|
||||
label));
|
||||
}
|
||||
|
||||
let values_str = match self.make_values_str(label, fields, values, span) {
|
||||
Some(vs) => vs,
|
||||
None => return,
|
||||
};
|
||||
let result = format!("{},{}{}\n", label, self.span.extent_str(sub_span), values_str);
|
||||
let result = format!("{},{}{}\n",
|
||||
label,
|
||||
self.span.extent_str(sub_span),
|
||||
values_str);
|
||||
self.recorder.record(&result[..]);
|
||||
}
|
||||
|
||||
@ -326,10 +381,7 @@ pub fn enum_str(&mut self,
|
||||
name: &str,
|
||||
scope_id: NodeId,
|
||||
value: &str) {
|
||||
self.check_and_record(Enum,
|
||||
span,
|
||||
sub_span,
|
||||
svec!(id, name, scope_id, value));
|
||||
self.check_and_record(Enum, span, sub_span, svec!(id, name, scope_id, value));
|
||||
}
|
||||
|
||||
pub fn tuple_variant_str(&mut self,
|
||||
@ -382,13 +434,14 @@ pub fn method_str(&mut self,
|
||||
decl_id: Option<DefId>,
|
||||
scope_id: NodeId) {
|
||||
let values = match decl_id {
|
||||
Some(decl_id) => svec!(id, name, decl_id.index.as_usize(), decl_id.krate, scope_id),
|
||||
Some(decl_id) => svec!(id,
|
||||
name,
|
||||
decl_id.index.as_usize(),
|
||||
decl_id.krate,
|
||||
scope_id),
|
||||
None => svec!(id, name, "", "", scope_id),
|
||||
};
|
||||
self.check_and_record(Function,
|
||||
span,
|
||||
sub_span,
|
||||
values);
|
||||
self.check_and_record(Function, span, sub_span, values);
|
||||
}
|
||||
|
||||
pub fn method_decl_str(&mut self,
|
||||
@ -397,10 +450,7 @@ pub fn method_decl_str(&mut self,
|
||||
id: NodeId,
|
||||
name: &str,
|
||||
scope_id: NodeId) {
|
||||
self.check_and_record(MethodDecl,
|
||||
span,
|
||||
sub_span,
|
||||
svec!(id, name, scope_id));
|
||||
self.check_and_record(MethodDecl, span, sub_span, svec!(id, name, scope_id));
|
||||
}
|
||||
|
||||
pub fn struct_str(&mut self,
|
||||
@ -424,10 +474,7 @@ pub fn trait_str(&mut self,
|
||||
name: &str,
|
||||
scope_id: NodeId,
|
||||
value: &str) {
|
||||
self.check_and_record(Trait,
|
||||
span,
|
||||
sub_span,
|
||||
svec!(id, name, scope_id, value));
|
||||
self.check_and_record(Trait, span, sub_span, svec!(id, name, scope_id, value));
|
||||
}
|
||||
|
||||
pub fn impl_str(&mut self,
|
||||
@ -483,10 +530,7 @@ pub fn use_glob_str(&mut self,
|
||||
id: NodeId,
|
||||
values: &str,
|
||||
parent: NodeId) {
|
||||
self.check_and_record(UseGlob,
|
||||
span,
|
||||
sub_span,
|
||||
svec!(id, values, parent));
|
||||
self.check_and_record(UseGlob, span, sub_span, svec!(id, values, parent));
|
||||
}
|
||||
|
||||
pub fn extern_crate_str(&mut self,
|
||||
@ -511,10 +555,7 @@ pub fn inherit_str(&mut self,
|
||||
self.check_and_record(Inheritance,
|
||||
span,
|
||||
sub_span,
|
||||
svec!(base_id.index.as_usize(),
|
||||
base_id.krate,
|
||||
deriv_id,
|
||||
0));
|
||||
svec!(base_id.index.as_usize(), base_id.krate, deriv_id, 0));
|
||||
}
|
||||
|
||||
pub fn fn_call_str(&mut self,
|
||||
@ -546,10 +587,7 @@ pub fn meth_call_str(&mut self,
|
||||
}
|
||||
|
||||
pub fn sub_mod_ref_str(&mut self, span: Span, sub_span: Span, qualname: &str, parent: NodeId) {
|
||||
self.record_with_span(ModRef,
|
||||
span,
|
||||
sub_span,
|
||||
svec!(0, 0, qualname, parent));
|
||||
self.record_with_span(ModRef, span, sub_span, svec!(0, 0, qualname, parent));
|
||||
}
|
||||
|
||||
pub fn typedef_str(&mut self,
|
||||
@ -558,17 +596,11 @@ pub fn typedef_str(&mut self,
|
||||
id: NodeId,
|
||||
qualname: &str,
|
||||
value: &str) {
|
||||
self.check_and_record(Typedef,
|
||||
span,
|
||||
sub_span,
|
||||
svec!(id, qualname, value));
|
||||
self.check_and_record(Typedef, span, sub_span, svec!(id, qualname, value));
|
||||
}
|
||||
|
||||
pub fn crate_str(&mut self, span: Span, name: &str) {
|
||||
self.record_with_span(Crate,
|
||||
span,
|
||||
span,
|
||||
svec!(name));
|
||||
self.record_with_span(Crate, span, span, svec!(name));
|
||||
}
|
||||
|
||||
pub fn external_crate_str(&mut self, span: Span, name: &str, num: ast::CrateNum) {
|
||||
@ -579,10 +611,7 @@ pub fn external_crate_str(&mut self, span: Span, name: &str, num: ast::CrateNum)
|
||||
}
|
||||
|
||||
pub fn sub_type_ref_str(&mut self, span: Span, sub_span: Span, qualname: &str) {
|
||||
self.record_with_span(TypeRef,
|
||||
span,
|
||||
sub_span,
|
||||
svec!(0, 0, qualname, 0));
|
||||
self.record_with_span(TypeRef, span, sub_span, svec!(0, 0, qualname, 0));
|
||||
}
|
||||
|
||||
// A slightly generic function for a reference to an item of any kind.
|
||||
|
@ -29,10 +29,14 @@ pub struct SpanUtils<'a> {
|
||||
|
||||
impl<'a> SpanUtils<'a> {
|
||||
pub fn new(sess: &'a Session) -> SpanUtils<'a> {
|
||||
SpanUtils { sess: sess, err_count: Cell::new(0) }
|
||||
SpanUtils {
|
||||
sess: sess,
|
||||
err_count: Cell::new(0),
|
||||
}
|
||||
}
|
||||
|
||||
// Standard string for extents/location.
|
||||
#[rustfmt_skip]
|
||||
pub fn extent_str(&self, span: Span) -> String {
|
||||
let lo_loc = self.sess.codemap().lookup_char_pos(span.lo);
|
||||
let hi_loc = self.sess.codemap().lookup_char_pos(span.hi);
|
||||
@ -54,7 +58,9 @@ pub fn make_sub_span(&self, span: Span, sub_span: Option<Span>) -> Option<Span>
|
||||
let loc = self.sess.codemap().lookup_char_pos(span.lo);
|
||||
assert!(!generated_code(span),
|
||||
"generated code; we should not be processing this `{}` in {}, line {}",
|
||||
self.snippet(span), loc.file.name, loc.line);
|
||||
self.snippet(span),
|
||||
loc.file.name,
|
||||
loc.line);
|
||||
|
||||
match sub_span {
|
||||
None => None,
|
||||
@ -86,8 +92,9 @@ pub fn retokenise_span(&self, span: Span) -> StringReader<'a> {
|
||||
// the codemap as a new filemap. This is mostly OK, but means we should
|
||||
// not iterate over the codemap. Also, any spans over the new filemap
|
||||
// are incompatible with spans over other filemaps.
|
||||
let filemap = self.sess.codemap().new_filemap(String::from("<anon-dxr>"),
|
||||
self.snippet(span));
|
||||
let filemap = self.sess
|
||||
.codemap()
|
||||
.new_filemap(String::from("<anon-dxr>"), self.snippet(span));
|
||||
let s = self.sess;
|
||||
lexer::StringReader::new(s.diagnostic(), filemap)
|
||||
}
|
||||
@ -213,8 +220,11 @@ pub fn sub_span_for_type_name(&self, span: Span) -> Option<Span> {
|
||||
if bracket_count != 0 {
|
||||
let loc = self.sess.codemap().lookup_char_pos(span.lo);
|
||||
self.sess.span_bug(span,
|
||||
&format!("Mis-counted brackets when breaking path? Parsing '{}' in {}, line {}",
|
||||
self.snippet(span), loc.file.name, loc.line));
|
||||
&format!("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() && bracket_count == 0 {
|
||||
return self.make_sub_span(span, Some(prev.sp));
|
||||
@ -239,9 +249,12 @@ pub fn spans_with_brackets(&self, span: Span, nesting: isize, limit: isize) -> V
|
||||
if ts.tok == token::Eof {
|
||||
if bracket_count != 0 {
|
||||
let loc = self.sess.codemap().lookup_char_pos(span.lo);
|
||||
self.sess.span_bug(span, &format!(
|
||||
"Mis-counted brackets when breaking path? Parsing '{}' in {}, line {}",
|
||||
self.snippet(span), loc.file.name, loc.line));
|
||||
self.sess.span_bug(span,
|
||||
&format!("Mis-counted brackets when breaking path? \
|
||||
Parsing '{}' in {}, line {}",
|
||||
self.snippet(span),
|
||||
loc.file.name,
|
||||
loc.line));
|
||||
}
|
||||
return result
|
||||
}
|
||||
@ -355,8 +368,11 @@ pub fn spans_for_ty_params(&self, span: Span, number: isize) -> Vec<Span> {
|
||||
pub fn report_span_err(&self, kind: &str, span: Span) {
|
||||
let loc = self.sess.codemap().lookup_char_pos(span.lo);
|
||||
info!("({}) Could not find sub_span in `{}` in {}, line {}",
|
||||
kind, self.snippet(span), loc.file.name, loc.line);
|
||||
self.err_count.set(self.err_count.get()+1);
|
||||
kind,
|
||||
self.snippet(span),
|
||||
loc.file.name,
|
||||
loc.line);
|
||||
self.err_count.set(self.err_count.get() + 1);
|
||||
if self.err_count.get() > 1000 {
|
||||
self.sess.bug("span errors reached 1000, giving up");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user