sub_span,
def_id,
self.cur_scope),
- def::DefStaticMethod(declid, provenence) => {
+ def::DefTy(def_id, _) => self.fmt.ref_str(recorder::TypeRef,
+ span,
+ sub_span,
+ def_id,
+ self.cur_scope),
+ def::DefStaticMethod(declid, provenence) |
+ def::DefMethod(declid, _, provenence) => {
let sub_span = self.span.sub_span_for_meth_name(span);
let defid = if declid.krate == ast::LOCAL_CRATE {
let ti = ty::impl_or_trait_item(&self.analysis.ty_cx,
Some(declid),
self.cur_scope);
},
- def::DefFn(def_id, _) => self.fmt.fn_call_str(span,
- sub_span,
- def_id,
- self.cur_scope),
+ def::DefFn(def_id, _) => {
+ self.fmt.fn_call_str(span,
+ sub_span,
+ def_id,
+ self.cur_scope)
+ }
_ => self.sess.span_bug(span,
- &format!("Unexpected def kind while looking up path in '{}'",
- self.span.snippet(span))[]),
+ &format!("Unexpected def kind while looking \
+ up path in `{}`: `{:?}`",
+ self.span.snippet(span),
+ *def)[]),
}
// modules or types in the path prefix
match *def {
return
}
- let mut struct_def: Option<DefId> = None;
- match self.lookup_type_ref(ex.id) {
- Some(id) => {
- struct_def = Some(id);
+ self.write_sub_paths_truncated(path, false);
+
+ let ty = &ty::expr_ty_adjusted(&self.analysis.ty_cx, ex).sty;
+ let struct_def = match *ty {
+ ty::ty_struct(def_id, _) => {
let sub_span = self.span.span_for_last_ident(path.span);
self.fmt.ref_str(recorder::StructRef,
path.span,
sub_span,
- id,
+ def_id,
self.cur_scope);
- },
- None => ()
- }
-
- self.write_sub_paths_truncated(path, false);
+ Some(def_id)
+ }
+ _ => None
+ };
for field in fields.iter() {
match struct_def {
}
self.visit_expr(&**sub_ex);
-
- match ty::expr_ty_adjusted(&self.analysis.ty_cx, &**sub_ex).sty {
+ let ty = &ty::expr_ty_adjusted(&self.analysis.ty_cx, &**sub_ex).sty;
+ match *ty {
ty::ty_struct(def_id, _) => {
let fields = ty::lookup_struct_fields(&self.analysis.ty_cx, def_id);
for f in fields.iter() {
break;
}
}
- },
+ }
_ => self.sess.span_bug(ex.span,
- "Expected struct type, but not ty_struct"),
+ &format!("Expected struct type, found {:?}", ty)[]),
}
},
ast::ExprTupField(ref sub_ex, idx) => {
self.visit_expr(&**sub_ex);
- match ty::expr_ty_adjusted(&self.analysis.ty_cx, &**sub_ex).sty {
+ let ty = &ty::expr_ty_adjusted(&self.analysis.ty_cx, &**sub_ex).sty;
+ match *ty {
ty::ty_struct(def_id, _) => {
let fields = ty::lookup_struct_fields(&self.analysis.ty_cx, def_id);
for (i, f) in fields.iter().enumerate() {
if i == idx.node {
- let sub_span = self.span.span_for_last_ident(ex.span);
+ let sub_span = self.span.sub_span_after_token(ex.span, token::Dot);
self.fmt.ref_str(recorder::VarRef,
ex.span,
sub_span,
break;
}
}
- },
+ }
+ ty::ty_tup(_) => {}
_ => self.sess.span_bug(ex.span,
- "Expected struct type, but not ty_struct"),
+ &format!("Expected struct or tuple \
+ type, found {:?}", ty)[]),
}
},
ast::ExprClosure(_, _, ref decl, ref body) => {
&value[],
"")
}
- def::DefVariant(..) => {
+ def::DefVariant(..) | def::DefTy(..) | def::DefStruct(..) => {
paths_to_process.push((id, p.clone(), Some(ref_kind)))
}
// FIXME(nrc) what are these doing here?
let lo_pos_byte = self.sess.codemap().lookup_byte_offset(span.lo).pos;
let hi_pos_byte = self.sess.codemap().lookup_byte_offset(span.hi).pos;
- format!("file_name,{},file_line,{},file_col,{},extent_start,{},extent_start_bytes,{},\
+ format!("file_name,\"{}\",file_line,{},file_col,{},extent_start,{},extent_start_bytes,{},\
file_line_end,{},file_col_end,{},extent_end,{},extent_end_bytes,{}",
lo_loc.file.name,
lo_loc.line, lo_loc.col.to_usize(), lo_pos.to_usize(), lo_pos_byte.to_usize(),
bracket_count += match prev.tok {
token::Lt => 1,
token::Gt => -1,
+ token::BinOp(token::Shl) => 2,
token::BinOp(token::Shr) => -2,
_ => 0
};
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> {
+ self.sub_span_after(span, |t| t == tok)
+ }
+
+ 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();
if ts.tok == token::Eof {
return None;
}
- if ts.tok.is_keyword(keyword) {
+ if f(ts.tok) {
let ts = toks.real_token();
if ts.tok == token::Eof {
return None
}
}
+
// Returns a list of the spans of idents in a patch.
// E.g., For foo::bar<x,t>::baz, we return [foo, bar, baz] (well, their spans)
pub fn spans_for_path_segments(&self, path: &ast::Path) -> Vec<Span> {