Skip to content

Commit

Permalink
Generalize item_span into node_span, which works on more types.
Browse files Browse the repository at this point in the history
Signed-off-by: Edward Z. Yang <ezyang@cs.stanford.edu>
  • Loading branch information
ezyang committed Dec 19, 2013
1 parent dc65762 commit 6ad1c8e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/librustc/middle/typeck/variance.rs
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
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),
}
}

5 comments on commit 6ad1c8e

@bors
Copy link
Contributor

@bors bors commented on 6ad1c8e Dec 19, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from alexcrichton
at ezyang@6ad1c8e

@bors
Copy link
Contributor

@bors bors commented on 6ad1c8e Dec 19, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging ezyang/rust/better-errors = 6ad1c8e into auto

@bors
Copy link
Contributor

@bors bors commented on 6ad1c8e Dec 19, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ezyang/rust/better-errors = 6ad1c8e merged ok, testing candidate = bc17e4f

@bors
Copy link
Contributor

@bors bors commented on 6ad1c8e Dec 19, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on 6ad1c8e Dec 19, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = bc17e4f

Please sign in to comment.