Auto merge of #28161 - nrc:fmt, r=brson

This commit is contained in:
bors 2015-09-04 23:32:35 +00:00
commit 779b2a9847
4 changed files with 119 additions and 177 deletions

View File

@ -71,13 +71,14 @@ pub struct DumpCsvVisitor<'l, 'tcx: 'l> {
span: SpanUtils<'l>,
fmt: FmtStrs<'l>,
cur_scope: NodeId
cur_scope: NodeId,
}
impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> {
pub fn new(tcx: &'l ty::ctxt<'tcx>,
analysis: &'l ty::CrateAnalysis,
output_file: Box<File>) -> DumpCsvVisitor<'l, 'tcx> {
output_file: Box<File>)
-> DumpCsvVisitor<'l, 'tcx> {
let span_utils = SpanUtils::new(&tcx.sess);
DumpCsvVisitor {
sess: &tcx.sess,
@ -85,16 +86,14 @@ impl <'l, 'tcx> DumpCsvVisitor<'l, '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,
}, span_utils),
cur_scope: 0
fmt: FmtStrs::new(box Recorder { out: output_file, dump_spans: false },
span_utils),
cur_scope: 0,
}
}
fn nest<F>(&mut self, scope_id: NodeId, f: F) where
F: FnOnce(&mut DumpCsvVisitor<'l, 'tcx>),
fn nest<F>(&mut self, scope_id: NodeId, f: F)
where F: FnOnce(&mut DumpCsvVisitor<'l, 'tcx>)
{
let parent_scope = self.cur_scope;
self.cur_scope = scope_id;
@ -140,9 +139,11 @@ impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> {
let mut segs = vec!();
for (i, (seg, span)) in path.segments.iter().zip(&spans).enumerate() {
segs.push(seg.clone());
let sub_path = ast::Path{span: *span, // span for the last segment
global: path.global,
segments: segs};
let sub_path = ast::Path {
span: *span, // span for the last segment
global: path.global,
segments: segs,
};
let qualname = if i == 0 && path.global {
format!("::{}", path_to_string(&sub_path))
} else {
@ -271,7 +272,7 @@ impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> {
def::DefPrimTy(_) => {
self.sess.span_bug(span, &format!("lookup_def_kind for unexpected item: {:?}",
def));
},
}
}
}
@ -357,9 +358,7 @@ impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> {
}
}
fn process_struct_field_def(&mut self,
field: &ast::StructField,
parent_id: NodeId) {
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.fmt.field_str(field.span,
@ -374,7 +373,7 @@ impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> {
// Dump generic params bindings, then visit_generics
fn process_generic_params(&mut self,
generics:&ast::Generics,
generics: &ast::Generics,
full_span: Span,
prefix: &str,
id: NodeId) {
@ -427,11 +426,7 @@ impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> {
self.nest(item.id, |v| v.visit_block(&body));
}
fn process_static_or_const_item(&mut self,
item: &ast::Item,
typ: &ast::Ty,
expr: &ast::Expr)
{
fn process_static_or_const_item(&mut self, item: &ast::Item, typ: &ast::Ty, expr: &ast::Expr) {
let var_data = self.save_ctxt.get_item_data(item);
down_cast_data!(var_data, VariableData, self, item.span);
self.fmt.static_str(item.span,
@ -452,8 +447,7 @@ impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> {
ident: &ast::Ident,
span: Span,
typ: &ast::Ty,
expr: &ast::Expr)
{
expr: &ast::Expr) {
let qualname = format!("::{}", self.tcx.map.path_to_string(id));
let sub_span = self.span.sub_span_after_keyword(span,
@ -641,8 +635,8 @@ impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> {
sub_span,
id,
item.id);
},
None => ()
}
None => (),
}
}
@ -653,8 +647,8 @@ impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> {
}
}
fn process_mod(&mut self,
item: &ast::Item) { // The module in question, represented as an item.
// `item` is the module in question, represented as an item.
fn process_mod(&mut self, item: &ast::Item) {
let mod_data = self.save_ctxt.get_item_data(item);
down_cast_data!(mod_data, ModData, self, item.span);
self.fmt.mod_str(item.span,
@ -665,10 +659,7 @@ impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> {
&mod_data.filename);
}
fn process_path(&mut self,
id: NodeId,
path: &ast::Path,
ref_kind: Option<recorder::Row>) {
fn process_path(&mut self, id: NodeId, path: &ast::Path, ref_kind: Option<recorder::Row>) {
if generated_code(path.span) {
return;
}
@ -737,7 +728,7 @@ impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> {
def::DefStruct(_) |
def::DefVariant(..) |
def::DefFn(..) => self.write_sub_paths_truncated(path, false),
_ => {},
_ => {}
}
}
@ -783,9 +774,7 @@ impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> {
visit::walk_expr_opt(self, base)
}
fn process_method_call(&mut self,
ex: &ast::Expr,
args: &Vec<P<ast::Expr>>) {
fn process_method_call(&mut self, ex: &ast::Expr, args: &Vec<P<ast::Expr>>) {
if let Some(call_data) = self.save_ctxt.get_expr_data(ex) {
down_cast_data!(call_data, MethodCallData, self, ex.span);
self.fmt.meth_call_str(ex.span,
@ -799,7 +788,7 @@ impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> {
visit::walk_exprs(self, &args);
}
fn process_pat(&mut self, p:&ast::Pat) {
fn process_pat(&mut self, p: &ast::Pat) {
if generated_code(p.span) {
return;
}
@ -827,7 +816,7 @@ impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> {
self.visit_pat(&field.pat);
}
}
_ => visit::walk_pat(self, p)
_ => visit::walk_pat(self, p),
}
}
}
@ -851,10 +840,10 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DumpCsvVisitor<'l, 'tcx> {
sub_span,
def_id,
self.cur_scope),
None => {},
None => {}
}
Some(def_id)
},
}
None => None,
};
@ -902,20 +891,19 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DumpCsvVisitor<'l, 'tcx> {
match plid.node {
ast::PathListIdent { id, .. } => {
match self.lookup_type_ref(id) {
Some(def_id) =>
match self.lookup_def_kind(id, plid.span) {
Some(kind) => {
self.fmt.ref_str(
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);
}
None => ()
},
None => ()
}
None => (),
},
None => (),
}
},
ast::PathListMod { .. } => ()
}
ast::PathListMod { .. } => (),
}
}
@ -978,7 +966,7 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DumpCsvVisitor<'l, 'tcx> {
self.visit_ty(&**ty);
self.process_generic_params(ty_params, item.span, &qualname, item.id);
},
}
ast::ItemMac(_) => (),
_ => visit::walk_item(self, item),
}
@ -1048,14 +1036,14 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DumpCsvVisitor<'l, 'tcx> {
sub_span,
id,
self.cur_scope);
},
None => ()
}
None => (),
}
self.write_sub_paths_truncated(path, false);
visit::walk_path(self, path);
},
}
_ => visit::walk_ty(self, t),
}
}
@ -1101,7 +1089,7 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DumpCsvVisitor<'l, 'tcx> {
field_data.ref_id,
field_data.scope);
}
},
}
ast::ExprTupField(ref sub_ex, idx) => {
if generated_code(sub_ex.span) {
return
@ -1125,7 +1113,7 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DumpCsvVisitor<'l, 'tcx> {
&format!("Expected struct or tuple \
type, found {:?}", ty)),
}
},
}
ast::ExprClosure(_, ref decl, ref body) => {
if generated_code(body.span) {
return
@ -1146,7 +1134,7 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DumpCsvVisitor<'l, 'tcx> {
// walk the body
self.nest(ex.id, |v| v.visit_block(&**body));
},
}
_ => {
visit::walk_expr(self, ex)
}
@ -1182,7 +1170,7 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DumpCsvVisitor<'l, 'tcx> {
}
let def = def_map.get(&id).unwrap().full_def();
match def {
def::DefLocal(id) => {
def::DefLocal(id) => {
let value = if immut == ast::MutImmutable {
self.span.snippet(p.span).to_string()
} else {
@ -1205,7 +1193,7 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DumpCsvVisitor<'l, 'tcx> {
def::DefConst(..) |
def::DefAssociatedConst(..) => {}
_ => error!("unexpected definition kind when processing collected paths: {:?}",
def)
def),
}
}

View File

@ -176,7 +176,7 @@ pub struct MethodCallData {
impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
pub fn new(tcx: &'l ty::ctxt<'tcx>) -> SaveContext <'l, 'tcx> {
pub fn new(tcx: &'l ty::ctxt<'tcx>) -> SaveContext<'l, 'tcx> {
let span_utils = SpanUtils::new(&tcx.sess);
SaveContext::from_span_utils(tcx, span_utils)
}
@ -184,10 +184,7 @@ impl<'l, 'tcx: 'l> 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.
@ -268,7 +265,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
scope: self.enclosing_scope(item.id),
filename: filename,
})
},
}
ast::ItemEnum(..) => {
let enum_name = format!("::{}", self.tcx.map.path_to_string(item.id));
let val = self.span_utils.snippet(item.span);
@ -281,7 +278,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
qualname: enum_name,
scope: self.enclosing_scope(item.id),
})
},
}
ast::ItemImpl(_, _, _, ref trait_ref, ref typ, _) => {
let mut type_data = None;
let sub_span;
@ -297,7 +294,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
scope: parent,
ref_id: id,
});
},
}
_ => {
// Less useful case, impl for a compound type.
let span = typ.span;
@ -341,17 +338,14 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
value: "".to_owned(),
type_value: typ,
})
},
}
_ => None,
}
}
// 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) -> FunctionData {
pub fn get_method_data(&self, id: ast::NodeId, name: ast::Name, span: Span) -> FunctionData {
// 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 = match self.tcx.impl_of_method(DefId::local(id)) {
@ -367,7 +361,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
result.push_str(" as ");
result.push_str(
&self.tcx.item_path_str(def_id));
},
}
None => {}
}
result.push_str(">");
@ -377,14 +371,14 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
self.tcx.sess.span_bug(span,
&format!("Container {} for method {} not an impl?",
impl_id.node, id));
},
}
}
},
}
_ => {
self.tcx.sess.span_bug(span,
&format!("Container {} for method {} is not a node item {:?}",
impl_id.node, id, self.tcx.map.get(impl_id.node)));
},
}
},
None => match self.tcx.trait_of_item(DefId::local(id)) {
Some(def_id) => {
@ -398,11 +392,11 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
def_id.node, id));
}
}
},
}
None => {
self.tcx.sess.span_bug(span,
&format!("Could not find container for method {}", id));
},
}
},
};
@ -492,7 +486,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
let method_id = self.tcx.tables.borrow().method_map[&method_call].def_id;
let (def_id, decl_id) = match self.tcx.impl_or_trait_item(method_id).container() {
ty::ImplContainer(_) => (Some(method_id), None),
ty::TraitContainer(_) => (None, Some(method_id))
ty::TraitContainer(_) => (None, Some(method_id)),
};
let sub_span = self.span_utils.sub_span_for_meth_name(expr.span);
let parent = self.enclosing_scope(expr.id);
@ -513,10 +507,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
}
}
pub fn get_path_data(&self,
id: NodeId,
path: &ast::Path)
-> Option<Data> {
pub fn get_path_data(&self, id: NodeId, path: &ast::Path) -> Option<Data> {
let def_map = self.tcx.def_map.borrow();
if !def_map.contains_key(&id) {
self.tcx.sess.span_bug(path.span,
@ -583,7 +574,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
ref_id: def_id,
decl_id: Some(decl_id),
}))
},
}
def::DefFn(def_id, _) => {
Some(Data::FunctionCallData(FunctionCallData {
ref_id: def_id,
@ -663,9 +654,7 @@ struct PathCollector {
impl PathCollector {
fn new() -> PathCollector {
PathCollector {
collected_paths: vec![],
}
PathCollector { collected_paths: vec![] }
}
}
@ -722,7 +711,7 @@ pub fn process_crate(tcx: &ty::ctxt,
None => {
info!("Could not find crate name, using 'unknown_crate'");
String::from("unknown_crate")
},
}
};
info!("Dumping crate {}", cratename);
@ -775,5 +764,5 @@ fn escape(s: String) -> String {
// If the expression is a macro expansion or other generated code, run screaming
// and don't index.
pub fn generated_code(span: Span) -> bool {
span.expn_id != NO_EXPANSION || span == DUMMY_SP
span.expn_id != NO_EXPANSION || span == DUMMY_SP
}

View File

@ -18,14 +18,14 @@ use middle::def_id::DefId;
use std::io::Write;
use syntax::ast;
use syntax::ast::{NodeId};
use syntax::ast::NodeId;
use syntax::codemap::*;
const ZERO_DEF_ID: DefId = DefId { node: 0, krate: 0 };
pub struct Recorder {
// output file
pub out: Box<Write+'static>,
pub out: Box<Write + 'static>,
pub dump_spans: bool,
}
@ -37,11 +37,7 @@ impl Recorder {
}
}
pub fn dump_span(&mut self,
su: SpanUtils,
kind: &str,
span: Span,
_sub_span: Option<Span>) {
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)));
@ -96,10 +92,7 @@ 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
@ -111,47 +104,51 @@ impl<'a> FmtStrs<'a> {
match r {
Variable => ("variable",
vec!("id","name","qualname","value","type","scopeid"),
true, true),
true,
true),
Enum => ("enum", vec!("id","qualname","scopeid","value"), true, true),
Variant => ("variant",
vec!("id","name","qualname","type","value","scopeid"),
true, true),
true,
true),
VariantStruct => ("variant_struct",
vec!("id","ctor_id","qualname","type","value","scopeid"),
true, true),
true,
true),
Function => ("function",
vec!("id","qualname","declid","declidcrate","scopeid"),
true, true),
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"),
true, true),
true,
true),
Module => ("module", vec!("id","qualname","scopeid","def_file"), true, false),
UseAlias => ("use_alias",
vec!("id","refid","refidcrate","name","scopeid"),
true, true),
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"),
true, true),
true,
true),
Inheritance => ("inheritance",
vec!("base","basecrate","derived","derivedcrate"),
true, false),
true,
false),
MethodCall => ("method_call",
vec!("refid","refidcrate","declid","declidcrate","scopeid"),
true, true),
true,
true),
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)
TypeRef => ("type_ref", vec!("refid","refidcrate","qualname","scopeid"), true, true),
FnRef => ("fn_ref", vec!("refid","refidcrate","qualname","scopeid"), true, true),
}
}
@ -159,7 +156,8 @@ impl<'a> FmtStrs<'a> {
kind: &'static str,
fields: &Vec<&'static str>,
values: Vec<String>,
span: Span) -> Option<String> {
span: Span)
-> Option<String> {
if values.len() != fields.len() {
self.span.sess.span_bug(span, &format!(
"Mismatch between length of fields for '{}', expected '{}', found '{}'",
@ -183,10 +181,7 @@ impl<'a> FmtStrs<'a> {
}))
}
pub fn record_without_span(&mut self,
kind: Row,
values: Vec<String>,
span: Span) {
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 {
@ -387,7 +382,7 @@ impl<'a> FmtStrs<'a> {
scope_id: NodeId) {
let values = match decl_id {
Some(decl_id) => svec!(id, name, decl_id.node, decl_id.krate, scope_id),
None => svec!(id, name, "", "", scope_id)
None => svec!(id, name, "", "", scope_id),
};
self.check_and_record(Function,
span,
@ -476,7 +471,7 @@ impl<'a> FmtStrs<'a> {
parent: NodeId) {
let (mod_node, mod_crate) = match mod_id {
Some(mod_id) => (mod_id.node, mod_id.krate),
None => (0, 0)
None => (0, 0),
};
self.check_and_record(UseAlias,
span,
@ -528,7 +523,7 @@ impl<'a> FmtStrs<'a> {
span: Span,
sub_span: Option<Span>,
id: DefId,
scope_id:NodeId) {
scope_id: NodeId) {
self.check_and_record(FnCall,
span,
sub_span,
@ -543,11 +538,11 @@ impl<'a> FmtStrs<'a> {
scope_id: NodeId) {
let (dfn, dfk) = match defid {
Some(defid) => (defid.node, defid.krate),
None => (0, 0)
None => (0, 0),
};
let (dcn, dck) = match declid {
Some(declid) => (s!(declid.node), s!(declid.krate)),
None => ("".to_string(), "".to_string())
None => ("".to_string(), "".to_string()),
};
self.check_and_record(MethodCall,
span,
@ -555,11 +550,7 @@ impl<'a> FmtStrs<'a> {
svec!(dfn, dfk, dcn, dck, scope_id));
}
pub fn sub_mod_ref_str(&mut self,
span: Span,
sub_span: Span,
qualname: &str,
parent:NodeId) {
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,
@ -578,29 +569,21 @@ impl<'a> FmtStrs<'a> {
svec!(id, qualname, value));
}
pub fn crate_str(&mut self,
span: Span,
name: &str) {
pub fn crate_str(&mut self, span: Span, name: &str) {
self.record_with_span(Crate,
span,
span,
svec!(name));
}
pub fn external_crate_str(&mut self,
span: Span,
name: &str,
num: ast::CrateNum) {
pub fn external_crate_str(&mut self, span: Span, name: &str, num: ast::CrateNum) {
let lo_loc = self.span.sess.codemap().lookup_char_pos(span.lo);
self.record_without_span(ExternalCrate,
svec!(name, num, lo_loc.file.name),
span);
}
pub fn sub_type_ref_str(&mut self,
span: Span,
sub_span: Span,
qualname: &str) {
pub fn sub_type_ref_str(&mut self, span: Span, sub_span: Span, qualname: &str) {
self.record_with_span(TypeRef,
span,
sub_span,

View File

@ -17,7 +17,7 @@ use std::cell::Cell;
use syntax::ast;
use syntax::codemap::*;
use syntax::parse::lexer;
use syntax::parse::lexer::{Reader,StringReader};
use syntax::parse::lexer::{Reader, StringReader};
use syntax::parse::token;
use syntax::parse::token::{keywords, Token};
@ -29,10 +29,7 @@ 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.
@ -62,8 +59,7 @@ impl<'a> SpanUtils<'a> {
match sub_span {
None => None,
Some(sub) => {
let FileMapAndBytePos {fm, pos} =
self.sess.codemap().lookup_byte_offset(span.lo);
let FileMapAndBytePos {fm, pos} = self.sess.codemap().lookup_byte_offset(span.lo);
let base = pos + fm.start_pos;
Some(Span {
lo: base + self.sess.codemap().lookup_byte_offset(sub.lo).pos,
@ -107,8 +103,7 @@ impl<'a> SpanUtils<'a> {
if ts.tok == token::Eof {
return self.make_sub_span(span, result)
}
if bracket_count == 0 &&
(ts.tok.is_ident() || ts.tok.is_keyword(keywords::SelfValue)) {
if bracket_count == 0 && (ts.tok.is_ident() || ts.tok.is_keyword(keywords::SelfValue)) {
result = Some(ts.sp);
}
@ -116,7 +111,7 @@ impl<'a> SpanUtils<'a> {
token::Lt => 1,
token::Gt => -1,
token::BinOp(token::Shr) => -2,
_ => 0
_ => 0,
}
}
}
@ -130,8 +125,7 @@ impl<'a> SpanUtils<'a> {
if ts.tok == token::Eof {
return None;
}
if bracket_count == 0 &&
(ts.tok.is_ident() || ts.tok.is_keyword(keywords::SelfValue)) {
if bracket_count == 0 && (ts.tok.is_ident() || ts.tok.is_keyword(keywords::SelfValue)) {
return self.make_sub_span(span, Some(ts.sp));
}
@ -139,7 +133,7 @@ impl<'a> SpanUtils<'a> {
token::Lt => 1,
token::Gt => -1,
token::BinOp(token::Shr) => -2,
_ => 0
_ => 0,
}
}
}
@ -156,20 +150,16 @@ impl<'a> SpanUtils<'a> {
last_span = None;
let mut next = toks.real_token();
if (next.tok == token::OpenDelim(token::Paren) ||
next.tok == token::Lt) &&
bracket_count == 0 &&
prev.tok.is_ident() {
if (next.tok == token::OpenDelim(token::Paren) || next.tok == token::Lt) &&
bracket_count == 0 && prev.tok.is_ident() {
result = Some(prev.sp);
}
if bracket_count == 0 &&
next.tok == token::ModSep {
if bracket_count == 0 && next.tok == token::ModSep {
let old = prev;
prev = next;
next = toks.real_token();
if next.tok == token::Lt &&
old.tok.is_ident() {
if next.tok == token::Lt && old.tok.is_ident() {
result = Some(old.sp);
}
}
@ -178,7 +168,7 @@ impl<'a> SpanUtils<'a> {
token::OpenDelim(token::Paren) | token::Lt => 1,
token::CloseDelim(token::Paren) | token::Gt => -1,
token::BinOp(token::Shr) => -2,
_ => 0
_ => 0,
};
if prev.tok.is_ident() && bracket_count == 0 {
@ -202,9 +192,7 @@ impl<'a> SpanUtils<'a> {
loop {
let next = toks.real_token();
if (next.tok == token::Lt ||
next.tok == token::Colon) &&
bracket_count == 0 &&
if (next.tok == token::Lt || next.tok == token::Colon) && bracket_count == 0 &&
prev.tok.is_ident() {
result = Some(prev.sp);
}
@ -214,7 +202,7 @@ impl<'a> SpanUtils<'a> {
token::Gt => -1,
token::BinOp(token::Shl) => 2,
token::BinOp(token::Shr) => -2,
_ => 0
_ => 0,
};
if next.tok == token::Eof {
@ -265,7 +253,7 @@ impl<'a> SpanUtils<'a> {
token::Gt => -1,
token::BinOp(token::Shl) => 2,
token::BinOp(token::Shr) => -2,
_ => 0
_ => 0,
};
// Ignore the `>::` in `<Type as Trait>::AssocTy`.
@ -316,21 +304,15 @@ impl<'a> SpanUtils<'a> {
}
}
pub fn sub_span_after_keyword(&self,
span: Span,
keyword: keywords::Keyword) -> Option<Span> {
pub fn sub_span_after_keyword(&self, span: Span, keyword: keywords::Keyword) -> Option<Span> {
self.sub_span_after(span, |t| t.is_keyword(keyword))
}
pub fn sub_span_after_token(&self,
span: Span,
tok: Token) -> Option<Span> {
pub fn sub_span_after_token(&self, span: Span, tok: Token) -> Option<Span> {
self.sub_span_after(span, |t| t == tok)
}
fn sub_span_after<F: Fn(Token) -> bool>(&self,
span: Span,
f: F) -> Option<Span> {
fn sub_span_after<F: Fn(Token) -> bool>(&self, span: Span, f: F) -> Option<Span> {
let mut toks = self.retokenise_span(span);
loop {
let ts = toks.real_token();