Move newtype_index to rustc_data_structures

This commit is contained in:
Santiago Pastorino 2017-09-27 19:47:41 -03:00
parent f5cef21569
commit 3d230af80b
3 changed files with 26 additions and 25 deletions

View File

@ -71,7 +71,7 @@ extern crate graphviz;
extern crate libc;
extern crate owning_ref;
extern crate rustc_back;
extern crate rustc_data_structures;
#[macro_use] extern crate rustc_data_structures;
extern crate serialize;
extern crate rustc_const_math;
extern crate rustc_errors as errors;

View File

@ -43,30 +43,6 @@ pub mod visit;
pub mod transform;
pub mod traversal;
macro_rules! newtype_index {
($name:ident, $debug_name:expr) => (
#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord,
RustcEncodable, RustcDecodable)]
pub struct $name(u32);
impl Idx for $name {
fn new(value: usize) -> Self {
assert!(value < (u32::MAX) as usize);
$name(value as u32)
}
fn index(self) -> usize {
self.0 as usize
}
}
impl Debug for $name {
fn fmt(&self, fmt: &mut Formatter) -> fmt::Result {
write!(fmt, "{}{}", $debug_name, self.0)
}
}
)
}
/// Types for locals
type LocalDecls<'tcx> = IndexVec<Local, LocalDecl<'tcx>>;

View File

@ -38,6 +38,31 @@ impl Idx for u32 {
fn index(self) -> usize { self as usize }
}
#[macro_export]
macro_rules! newtype_index {
($name:ident, $debug_name:expr) => (
#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord,
RustcEncodable, RustcDecodable)]
pub struct $name(u32);
impl Idx for $name {
fn new(value: usize) -> Self {
assert!(value < (u32::MAX) as usize);
$name(value as u32)
}
fn index(self) -> usize {
self.0 as usize
}
}
impl Debug for $name {
fn fmt(&self, fmt: &mut Formatter) -> fmt::Result {
write!(fmt, "{}{}", $debug_name, self.0)
}
}
)
}
#[derive(Clone, PartialEq, Eq)]
pub struct IndexVec<I: Idx, T> {
pub raw: Vec<T>,