1 use rustc_span::LocalExpnId;
4 rustc_index::newtype_index! {
5 /// Identifies an AST node.
7 /// This identifies top-level definitions, expressions, and everything in between.
8 /// This is later turned into [`DefId`] and `HirId` for the HIR.
10 /// [`DefId`]: rustc_span::def_id::DefId
12 DEBUG_FORMAT = "NodeId({})"
16 rustc_data_structures::define_id_collections!(NodeMap, NodeSet, NodeId);
18 /// The [`NodeId`] used to represent the root of the crate.
19 pub const CRATE_NODE_ID: NodeId = NodeId::from_u32(0);
21 /// When parsing and at the beginning of doing expansions, we initially give all AST nodes
22 /// this dummy AST [`NodeId`]. Then, during a later phase of expansion, we renumber them
23 /// to have small, positive IDs.
24 pub const DUMMY_NODE_ID: NodeId = NodeId::MAX;
27 pub fn placeholder_from_expn_id(expn_id: LocalExpnId) -> Self {
28 NodeId::from_u32(expn_id.as_u32())
31 pub fn placeholder_to_expn_id(self) -> LocalExpnId {
32 LocalExpnId::from_u32(self.as_u32())
36 impl fmt::Display for NodeId {
37 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
38 fmt::Display::fmt(&self.as_u32(), f)