mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-06 06:57:42 +00:00

Originally, there has been a dedicated pass for renumbering AST NodeIds to have actual values. This pass had been added by commita5ad4c3794
. Then, later, this step was moved to where it resides now, macro expansion. See commitc86c8d41a2
or PR #36438. The comment snippet, added by the original commit, has survived the times without any change, becoming outdated at removal of the dedicated pass. Nowadays, grepping for the next_node_id function will show up multiple places in the compiler that call it, but the main rewriting that the comment talks about is still done in the expansion step, inside an innocious looking visit_id function that's called during macro invocation collection.
35 lines
921 B
Rust
35 lines
921 B
Rust
use rustc_span::ExpnId;
|
|
use std::fmt;
|
|
|
|
rustc_index::newtype_index! {
|
|
pub struct NodeId {
|
|
DEBUG_FORMAT = "NodeId({})"
|
|
}
|
|
}
|
|
|
|
rustc_data_structures::define_id_collections!(NodeMap, NodeSet, NodeId);
|
|
|
|
/// `NodeId` used to represent the root of the crate.
|
|
pub const CRATE_NODE_ID: NodeId = NodeId::from_u32(0);
|
|
|
|
/// When parsing and doing expansions, we initially give all AST nodes this AST
|
|
/// node value. Then later, during expansion, we renumber them to have small,
|
|
/// positive ids.
|
|
pub const DUMMY_NODE_ID: NodeId = NodeId::MAX;
|
|
|
|
impl NodeId {
|
|
pub fn placeholder_from_expn_id(expn_id: ExpnId) -> Self {
|
|
NodeId::from_u32(expn_id.as_u32())
|
|
}
|
|
|
|
pub fn placeholder_to_expn_id(self) -> ExpnId {
|
|
ExpnId::from_u32(self.as_u32())
|
|
}
|
|
}
|
|
|
|
impl fmt::Display for NodeId {
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
fmt::Display::fmt(&self.as_u32(), f)
|
|
}
|
|
}
|