Struct rustc::hir::map::Map
[−]
[src]
pub struct Map<'hir> { pub forest: &'hir Forest, pub dep_graph: DepGraph, // some fields omitted }
rustc_private
)Represents a mapping from Node IDs to AST elements and their parent Node IDs
Fields
forest: &'hir Forest
rustc_private
)The backing storage for all the AST nodes.
dep_graph: DepGraph
rustc_private
)Same as the dep_graph in forest, just available with one fewer deref. This is a gratuitious micro-optimization.
Methods
impl<'hir> Map<'hir>
[src]
fn read(&self, id: NodeId)
rustc_private
)Registers a read in the dependency graph of the AST node with
the given id
. This needs to be called each time a public
function returns the HIR for a node -- in other words, when it
"reveals" the content of a node to the caller (who might not
otherwise have had access to those contents, and hence needs a
read recorded). If the function just returns a DefId or
NodeId, no actual content was returned, so no read is needed.
fn num_local_def_ids(&self) -> usize
rustc_private
)fn definitions(&self) -> &Definitions
rustc_private
)fn def_key(&self, def_id: DefId) -> DefKey
rustc_private
)fn def_path_from_id(&self, id: NodeId) -> Option<DefPath>
rustc_private
)fn def_path(&self, def_id: DefId) -> DefPath
rustc_private
)fn def_index_for_def_key(&self, def_key: DefKey) -> Option<DefIndex>
rustc_private
)fn local_def_id(&self, node: NodeId) -> DefId
rustc_private
)fn opt_local_def_id(&self, node: NodeId) -> Option<DefId>
rustc_private
)fn as_local_node_id(&self, def_id: DefId) -> Option<NodeId>
rustc_private
)fn krate(&self) -> &'hir Crate
rustc_private
)fn trait_item(&self, id: TraitItemId) -> &'hir TraitItem
rustc_private
)fn impl_item(&self, id: ImplItemId) -> &'hir ImplItem
rustc_private
)fn body(&self, id: BodyId) -> &'hir Body
rustc_private
)fn body_owner(&self, BodyId { node_id: node_id }: BodyId) -> NodeId
rustc_private
)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), or a closure, or the body itself
for embedded constant expressions (e.g. N
in [T; N]
).
fn body_owner_def_id(&self, id: BodyId) -> DefId
rustc_private
)fn ty_param_owner(&self, id: NodeId) -> NodeId
rustc_private
)fn ty_param_name(&self, id: NodeId) -> Name
rustc_private
)fn trait_impls(&self, trait_did: DefId) -> &'hir [NodeId]
rustc_private
)fn trait_default_impl(&self, trait_did: DefId) -> Option<NodeId>
rustc_private
)fn trait_is_auto(&self, trait_did: DefId) -> bool
rustc_private
)fn krate_attrs(&self) -> &'hir [Attribute]
rustc_private
)Get the attributes on the krate. This is preferable to
invoking krate.attrs
because it registers a tighter
dep-graph access.
fn get(&self, id: NodeId) -> Node<'hir>
rustc_private
)Retrieve the Node corresponding to id
, panicking if it cannot
be found.
fn get_if_local(&self, id: DefId) -> Option<Node<'hir>>
rustc_private
)fn find(&self, id: NodeId) -> Option<Node<'hir>>
rustc_private
)Retrieve the Node corresponding to id
, returning None if
cannot be found.
fn get_parent_node(&self, id: NodeId) -> NodeId
rustc_private
)Similar to get_parent, returns the parent node id or id if there is no parent. This function returns the immediate parent in the AST, whereas get_parent returns the enclosing item. Note that this might not be the actual parent node in the AST - some kinds of nodes are not in the map and these will never appear as the parent_node. So you can always walk the parent_nodes from a node to the root of the ast (unless you get the same id back here that can happen if the id is not in the map itself or is just weird).
fn is_argument(&self, id: NodeId) -> bool
rustc_private
)Check if the node is an argument. An argument is a local variable whose immediate parent is an item or a closure.
fn get_parent(&self, id: NodeId) -> NodeId
rustc_private
)Retrieve the NodeId for id
's parent item, or id
itself if no
parent item is in this map. The "parent item" is the closest parent node
in the AST which is recorded by the map and is an item, either an item
in a module, trait, or impl.
fn get_module_parent(&self, id: NodeId) -> NodeId
rustc_private
)Returns the NodeId of id
's nearest module parent, or id
itself if no
module parent is in this map.
fn get_enclosing_scope(&self, id: NodeId) -> Option<NodeId>
rustc_private
)Returns the nearest enclosing scope. A scope is an item or block. FIXME it is not clear to me that all items qualify as scopes - statics and associated types probably shouldn't, for example. Behaviour in this regard should be expected to be highly unstable.
fn get_parent_did(&self, id: NodeId) -> DefId
rustc_private
)fn get_foreign_abi(&self, id: NodeId) -> Abi
rustc_private
)fn expect_item(&self, id: NodeId) -> &'hir Item
rustc_private
)fn expect_impl_item(&self, id: NodeId) -> &'hir ImplItem
rustc_private
)fn expect_trait_item(&self, id: NodeId) -> &'hir TraitItem
rustc_private
)fn expect_variant_data(&self, id: NodeId) -> &'hir VariantData
rustc_private
)fn expect_variant(&self, id: NodeId) -> &'hir Variant
rustc_private
)fn expect_foreign_item(&self, id: NodeId) -> &'hir ForeignItem
rustc_private
)fn expect_expr(&self, id: NodeId) -> &'hir Expr
rustc_private
)fn get_inlined_body(&self, def_id: DefId) -> Option<&'hir Body>
rustc_private
)fn intern_inlined_body(&self, def_id: DefId, body: Body) -> &'hir Body
rustc_private
)fn name(&self, id: NodeId) -> Name
rustc_private
)Returns the name associated with the given NodeId's AST.
fn attrs(&self, id: NodeId) -> &'hir [Attribute]
rustc_private
)Given a node ID, get a list of attributes associated with the AST corresponding to the Node ID
fn nodes_matching_suffix<'a>(&'a self,
parts: &'a [String])
-> NodesMatchingSuffix<'a, 'hir>
parts: &'a [String])
-> NodesMatchingSuffix<'a, 'hir>
rustc_private
)Returns an iterator that yields the node id's with paths that
match parts
. (Requires parts
is non-empty.)
For example, if given parts
equal to ["bar", "quux"]
, then
the iterator will produce node id's for items with paths
such as foo::bar::quux
, bar::quux
, other::bar::quux
, and
any other such items it can find in the map.
fn span(&self, id: NodeId) -> Span
rustc_private
)fn span_if_local(&self, id: DefId) -> Option<Span>
rustc_private
)fn node_to_string(&self, id: NodeId) -> String
rustc_private
)fn node_to_user_string(&self, id: NodeId) -> String
rustc_private
)fn node_to_pretty_string(&self, id: NodeId) -> String
rustc_private
)Trait Implementations
impl<'hir> Clone for Map<'hir>
[src]
fn clone(&self) -> Map<'hir>
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more
impl<'hir> PpAnn for Map<'hir>
[src]
Identical to the PpAnn
implementation for hir::Crate
,
except it avoids creating a dependency on the whole crate.
fn nested(&self, state: &mut State, nested: Nested) -> Result<()>
rustc_private
)fn pre(&self, _state: &mut State, _node: AnnNode) -> Result<()>
rustc_private
)fn post(&self, _state: &mut State, _node: AnnNode) -> Result<()>
rustc_private
)