Skip to content

Commit 6ad1c8e

Browse files
committed
Generalize item_span into node_span, which works on more types.
Signed-off-by: Edward Z. Yang <[email protected]>
1 parent dc65762 commit 6ad1c8e

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

src/librustc/middle/typeck/variance.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -916,7 +916,7 @@ impl<'a> SolveContext<'a> {
916916
// attribute and report an error with various results if found.
917917
if ty::has_attr(tcx, item_def_id, "rustc_variance") {
918918
let found = item_variances.repr(tcx);
919-
tcx.sess.span_err(ast_map::item_span(tcx.items, item_id), found);
919+
tcx.sess.span_err(ast_map::node_span(tcx.items, item_id), found);
920920
}
921921

922922
let newly_added = item_variance_map.insert(item_def_id,

src/libsyntax/ast_map.rs

+14-5
Original file line numberDiff line numberDiff line change
@@ -490,14 +490,23 @@ pub fn node_item_query<Result>(items: map, id: NodeId, query: |@item| -> Result,
490490
}
491491
}
492492

493-
pub fn item_span(items: map,
493+
pub fn node_span(items: map,
494494
id: ast::NodeId)
495495
-> Span {
496496
match items.find(&id) {
497497
Some(&node_item(item, _)) => item.span,
498-
r => {
499-
fail!(format!("item_span: expected item with id {} but found {:?}",
500-
id, r))
501-
}
498+
Some(&node_foreign_item(foreign_item, _, _, _)) => foreign_item.span,
499+
Some(&node_trait_method(@required(ref type_method), _, _)) => type_method.span,
500+
Some(&node_trait_method(@provided(ref method), _, _)) => method.span,
501+
Some(&node_method(method, _, _)) => method.span,
502+
Some(&node_variant(variant, _, _)) => variant.span,
503+
Some(&node_expr(expr)) => expr.span,
504+
Some(&node_stmt(stmt)) => stmt.span,
505+
Some(&node_arg(pat)) => pat.span,
506+
Some(&node_local(_)) => fail!("node_span: cannot get span from node_local"),
507+
Some(&node_block(block)) => block.span,
508+
Some(&node_struct_ctor(_, item, _)) => item.span,
509+
Some(&node_callee_scope(expr)) => expr.span,
510+
None => fail!("node_span: could not find id {}", id),
502511
}
503512
}

0 commit comments

Comments
 (0)