hir: more HirId methods
This commit is contained in:
parent
4314dbaa76
commit
927614ff3e
@ -401,6 +401,12 @@ impl<'hir> Map<'hir> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME(@ljedrz): replace the NodeId variant
|
||||||
|
pub fn describe_def_by_hir_id(&self, hir_id: HirId) -> Option<Def> {
|
||||||
|
let node_id = self.hir_to_node_id(hir_id);
|
||||||
|
self.describe_def(node_id)
|
||||||
|
}
|
||||||
|
|
||||||
fn entry_count(&self) -> usize {
|
fn entry_count(&self) -> usize {
|
||||||
self.map.len()
|
self.map.len()
|
||||||
}
|
}
|
||||||
@ -445,6 +451,12 @@ impl<'hir> Map<'hir> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME(@ljedrz): replace the NodeId variant
|
||||||
|
pub fn fn_decl_by_hir_id(&self, hir_id: HirId) -> Option<FnDecl> {
|
||||||
|
let node_id = self.hir_to_node_id(hir_id);
|
||||||
|
self.fn_decl(node_id)
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns the `NodeId` that corresponds to the definition of
|
/// Returns the `NodeId` that corresponds to the definition of
|
||||||
/// which this is the body of, i.e., a `fn`, `const` or `static`
|
/// which this is the body of, i.e., a `fn`, `const` or `static`
|
||||||
/// item (possibly associated), a closure, or a `hir::AnonConst`.
|
/// item (possibly associated), a closure, or a `hir::AnonConst`.
|
||||||
@ -855,6 +867,12 @@ impl<'hir> Map<'hir> {
|
|||||||
self.local_def_id(self.get_parent(id))
|
self.local_def_id(self.get_parent(id))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME(@ljedrz): replace the NodeId variant
|
||||||
|
pub fn get_parent_did_by_hir_id(&self, id: HirId) -> DefId {
|
||||||
|
let node_id = self.hir_to_node_id(id);
|
||||||
|
self.get_parent_did(node_id)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn get_foreign_abi(&self, id: NodeId) -> Abi {
|
pub fn get_foreign_abi(&self, id: NodeId) -> Abi {
|
||||||
let parent = self.get_parent(id);
|
let parent = self.get_parent(id);
|
||||||
if let Some(entry) = self.find_entry(parent) {
|
if let Some(entry) = self.find_entry(parent) {
|
||||||
@ -868,6 +886,12 @@ impl<'hir> Map<'hir> {
|
|||||||
bug!("expected foreign mod or inlined parent, found {}", self.node_to_string(parent))
|
bug!("expected foreign mod or inlined parent, found {}", self.node_to_string(parent))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME(@ljedrz): replace the NodeId variant
|
||||||
|
pub fn get_foreign_abi_by_hir_id(&self, id: HirId) -> Abi {
|
||||||
|
let node_id = self.hir_to_node_id(id);
|
||||||
|
self.get_foreign_abi(node_id)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn expect_item(&self, id: NodeId) -> &'hir Item {
|
pub fn expect_item(&self, id: NodeId) -> &'hir Item {
|
||||||
match self.find(id) { // read recorded by `find`
|
match self.find(id) { // read recorded by `find`
|
||||||
Some(Node::Item(item)) => item,
|
Some(Node::Item(item)) => item,
|
||||||
@ -888,6 +912,18 @@ impl<'hir> Map<'hir> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME(@ljedrz): replace the NodeId variant
|
||||||
|
pub fn expect_impl_item_by_hir_id(&self, id: HirId) -> &'hir ImplItem {
|
||||||
|
let node_id = self.hir_to_node_id(id);
|
||||||
|
self.expect_impl_item(node_id)
|
||||||
|
}
|
||||||
|
|
||||||
|
// FIXME(@ljedrz): replace the NodeId variant
|
||||||
|
pub fn expect_trait_item_by_hir_id(&self, id: HirId) -> &'hir TraitItem {
|
||||||
|
let node_id = self.hir_to_node_id(id);
|
||||||
|
self.expect_trait_item(node_id)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn expect_trait_item(&self, id: NodeId) -> &'hir TraitItem {
|
pub fn expect_trait_item(&self, id: NodeId) -> &'hir TraitItem {
|
||||||
match self.find(id) {
|
match self.find(id) {
|
||||||
Some(Node::TraitItem(item)) => item,
|
Some(Node::TraitItem(item)) => item,
|
||||||
@ -931,6 +967,12 @@ impl<'hir> Map<'hir> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME(@ljedrz): replace the NodeId variant
|
||||||
|
pub fn expect_expr_by_hir_id(&self, id: HirId) -> &'hir Expr {
|
||||||
|
let node_id = self.hir_to_node_id(id);
|
||||||
|
self.expect_expr(node_id)
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns the name associated with the given NodeId's AST.
|
/// Returns the name associated with the given NodeId's AST.
|
||||||
pub fn name(&self, id: NodeId) -> Name {
|
pub fn name(&self, id: NodeId) -> Name {
|
||||||
match self.get(id) {
|
match self.get(id) {
|
||||||
@ -948,6 +990,12 @@ impl<'hir> Map<'hir> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME(@ljedrz): replace the NodeId variant
|
||||||
|
pub fn name_by_hir_id(&self, id: HirId) -> Name {
|
||||||
|
let node_id = self.hir_to_node_id(id);
|
||||||
|
self.name(node_id)
|
||||||
|
}
|
||||||
|
|
||||||
/// Given a node ID, get a list of attributes associated with the AST
|
/// Given a node ID, get a list of attributes associated with the AST
|
||||||
/// corresponding to the Node ID
|
/// corresponding to the Node ID
|
||||||
pub fn attrs(&self, id: NodeId) -> &'hir [ast::Attribute] {
|
pub fn attrs(&self, id: NodeId) -> &'hir [ast::Attribute] {
|
||||||
@ -970,6 +1018,12 @@ impl<'hir> Map<'hir> {
|
|||||||
attrs.unwrap_or(&[])
|
attrs.unwrap_or(&[])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME(@ljedrz): replace the NodeId variant
|
||||||
|
pub fn attrs_by_hir_id(&self, id: HirId) -> &'hir [ast::Attribute] {
|
||||||
|
let node_id = self.hir_to_node_id(id);
|
||||||
|
self.attrs(node_id)
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns an iterator that yields the node id's with paths that
|
/// Returns an iterator that yields the node id's with paths that
|
||||||
/// match `parts`. (Requires `parts` is non-empty.)
|
/// match `parts`. (Requires `parts` is non-empty.)
|
||||||
///
|
///
|
||||||
@ -1019,6 +1073,12 @@ impl<'hir> Map<'hir> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME(@ljedrz): replace the NodeId variant
|
||||||
|
pub fn span_by_hir_id(&self, id: HirId) -> Span {
|
||||||
|
let node_id = self.hir_to_node_id(id);
|
||||||
|
self.span(node_id)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn span_if_local(&self, id: DefId) -> Option<Span> {
|
pub fn span_if_local(&self, id: DefId) -> Option<Span> {
|
||||||
self.as_local_node_id(id).map(|id| self.span(id))
|
self.as_local_node_id(id).map(|id| self.span(id))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user