Skip to content
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

hir: add more HirId methods #58139

Merged
merged 1 commit into from
Feb 5, 2019
Merged
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
60 changes: 60 additions & 0 deletions src/librustc/hir/map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
self.map.len()
}
Expand Down Expand Up @@ -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
/// which this is the body of, i.e., a `fn`, `const` or `static`
/// item (possibly associated), a closure, or a `hir::AnonConst`.
Expand Down Expand Up @@ -855,6 +867,12 @@ impl<'hir> Map<'hir> {
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 {
let parent = self.get_parent(id);
if let Some(entry) = self.find_entry(parent) {
Expand All @@ -868,6 +886,12 @@ impl<'hir> Map<'hir> {
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 {
match self.find(id) { // read recorded by `find`
Some(Node::Item(item)) => item,
Expand All @@ -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 {
match self.find(id) {
Some(Node::TraitItem(item)) => item,
Expand Down Expand Up @@ -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.
pub fn name(&self, id: NodeId) -> Name {
match self.get(id) {
Expand All @@ -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
/// corresponding to the Node ID
pub fn attrs(&self, id: NodeId) -> &'hir [ast::Attribute] {
Expand All @@ -970,6 +1018,12 @@ impl<'hir> Map<'hir> {
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
/// match `parts`. (Requires `parts` is non-empty.)
///
Expand Down Expand Up @@ -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> {
self.as_local_node_id(id).map(|id| self.span(id))
}
Expand Down