Generalize item_span into node_span, which works on more types.

Signed-off-by: Edward Z. Yang <ezyang@cs.stanford.edu>
This commit is contained in:
Edward Z. Yang 2013-12-19 14:41:59 +08:00
parent dc65762d79
commit 6ad1c8e044
2 changed files with 15 additions and 6 deletions

View File

@ -916,7 +916,7 @@ fn write(&self) {
// attribute and report an error with various results if found.
if ty::has_attr(tcx, item_def_id, "rustc_variance") {
let found = item_variances.repr(tcx);
tcx.sess.span_err(ast_map::item_span(tcx.items, item_id), found);
tcx.sess.span_err(ast_map::node_span(tcx.items, item_id), found);
}
let newly_added = item_variance_map.insert(item_def_id,

View File

@ -490,14 +490,23 @@ pub fn node_item_query<Result>(items: map, id: NodeId, query: |@item| -> Result,
}
}
pub fn item_span(items: map,
pub fn node_span(items: map,
id: ast::NodeId)
-> Span {
match items.find(&id) {
Some(&node_item(item, _)) => item.span,
r => {
fail!(format!("item_span: expected item with id {} but found {:?}",
id, r))
}
Some(&node_foreign_item(foreign_item, _, _, _)) => foreign_item.span,
Some(&node_trait_method(@required(ref type_method), _, _)) => type_method.span,
Some(&node_trait_method(@provided(ref method), _, _)) => method.span,
Some(&node_method(method, _, _)) => method.span,
Some(&node_variant(variant, _, _)) => variant.span,
Some(&node_expr(expr)) => expr.span,
Some(&node_stmt(stmt)) => stmt.span,
Some(&node_arg(pat)) => pat.span,
Some(&node_local(_)) => fail!("node_span: cannot get span from node_local"),
Some(&node_block(block)) => block.span,
Some(&node_struct_ctor(_, item, _)) => item.span,
Some(&node_callee_scope(expr)) => expr.span,
None => fail!("node_span: could not find id {}", id),
}
}