Implement indexed_vec::Idx for ast::NodeId

This commit is contained in:
Michael Woerister
2017-03-14 15:50:04 +01:00
parent 9e0589a52b
commit 559127b451
+11
View File
@@ -23,6 +23,7 @@
use ext::hygiene::SyntaxContext;
use print::pprust;
use ptr::P;
use rustc_data_structures::indexed_vec;
use symbol::{Symbol, keywords};
use tokenstream::{ThinTokenStream, TokenStream};
@@ -275,6 +276,16 @@ fn default_decode<D: Decoder>(d: &mut D) -> Result<NodeId, D::Error> {
}
}
impl indexed_vec::Idx for NodeId {
fn new(idx: usize) -> Self {
NodeId::new(idx)
}
fn index(self) -> usize {
self.as_usize()
}
}
/// Node id used to represent the root of the crate.
pub const CRATE_NODE_ID: NodeId = NodeId(0);