1 use rustc_serialize::{Decoder, Encoder};
2 use rustc_span::ExpnId;
5 rustc_index::newtype_index! {
8 DEBUG_FORMAT = "NodeId({})"
12 rustc_data_structures::define_id_collections!(NodeMap, NodeSet, NodeId);
14 /// `NodeId` used to represent the root of the crate.
15 pub const CRATE_NODE_ID: NodeId = NodeId::from_u32(0);
17 /// When parsing and doing expansions, we initially give all AST nodes this AST
18 /// node value. Then later, in the renumber pass, we renumber them to have
19 /// small, positive ids.
20 pub const DUMMY_NODE_ID: NodeId = NodeId::MAX;
23 pub fn placeholder_from_expn_id(expn_id: ExpnId) -> Self {
24 NodeId::from_u32(expn_id.as_u32())
27 pub fn placeholder_to_expn_id(self) -> ExpnId {
28 ExpnId::from_u32(self.as_u32())
32 impl fmt::Display for NodeId {
33 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
34 fmt::Display::fmt(&self.as_u32(), f)
38 impl rustc_serialize::UseSpecializedEncodable for NodeId {
39 fn default_encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
40 s.emit_u32(self.as_u32())
44 impl rustc_serialize::UseSpecializedDecodable for NodeId {
45 fn default_decode<D: Decoder>(d: &mut D) -> Result<NodeId, D::Error> {
46 d.read_u32().map(NodeId::from_u32)