Skip to content

Generalize item_span into node_span, which works on more types. #11070

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 19, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/librustc/middle/typeck/variance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -916,7 +916,7 @@ impl<'a> SolveContext<'a> {
// 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,
Expand Down
19 changes: 14 additions & 5 deletions src/libsyntax/ast_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
}