Skip to content

Commit

Permalink
Make DefIndex use newtype_index macro
Browse files Browse the repository at this point in the history
  • Loading branch information
spastorino committed Nov 4, 2017
1 parent f9bc8e7 commit d19faea
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 26 deletions.
1 change: 1 addition & 0 deletions src/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 9 additions & 25 deletions src/librustc/hir/def_id.rs
Expand Up @@ -86,20 +86,17 @@ impl serialize::UseSpecializedDecodable for CrateNum {
///
/// Since the DefIndex is mostly treated as an opaque ID, you probably
/// don't have to care about these ranges.
#[derive(Clone, Eq, Ord, PartialOrd, PartialEq, RustcEncodable,
RustcDecodable, Hash, Copy)]
pub struct DefIndex(u32);
newtype_index!(DefIndex
{
DEBUG_FORMAT = custom,

impl Idx for DefIndex {
fn new(value: usize) -> Self {
assert!(value < (u32::MAX) as usize);
DefIndex(value as u32)
}
/// The start of the "high" range of DefIndexes.
const DEF_INDEX_HI_START = 1 << 31,

fn index(self) -> usize {
self.0 as usize
}
}
/// The crate root is always assigned index 0 by the AST Map code,
/// thanks to `NodeCollector::new`.
const CRATE_DEF_INDEX = 0,
});

impl fmt::Debug for DefIndex {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
Expand All @@ -111,12 +108,6 @@ impl fmt::Debug for DefIndex {
}

impl DefIndex {
#[inline]
pub fn new(x: usize) -> DefIndex {
assert!(x < (u32::MAX as usize));
DefIndex(x as u32)
}

#[inline]
pub fn from_u32(x: u32) -> DefIndex {
DefIndex(x)
Expand Down Expand Up @@ -155,13 +146,6 @@ impl DefIndex {
}
}

/// The start of the "high" range of DefIndexes.
const DEF_INDEX_HI_START: DefIndex = DefIndex(1 << 31);

/// The crate root is always assigned index 0 by the AST Map code,
/// thanks to `NodeCollector::new`.
pub const CRATE_DEF_INDEX: DefIndex = DefIndex(0);

#[derive(Copy, Clone, Eq, PartialEq, Hash)]
pub enum DefIndexAddressSpace {
Low = 0,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/hir/map/definitions.rs
Expand Up @@ -19,7 +19,7 @@ use hir::def_id::{CrateNum, DefId, DefIndex, LOCAL_CRATE, DefIndexAddressSpace,
CRATE_DEF_INDEX};
use ich::Fingerprint;
use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::indexed_vec::IndexVec;
use rustc_data_structures::indexed_vec::{IndexVec, Idx};
use rustc_data_structures::stable_hasher::StableHasher;
use serialize::{Encodable, Decodable, Encoder, Decoder};
use session::CrateDisambiguator;
Expand Down
1 change: 1 addition & 0 deletions src/librustc/infer/region_inference/graphviz.rs
Expand Up @@ -19,6 +19,7 @@
use graphviz as dot;

use hir::def_id::DefIndex;
use rustc_data_structures::indexed_vec::Idx;
use ty;
use middle::free_region::RegionRelations;
use middle::region;
Expand Down
1 change: 1 addition & 0 deletions src/librustc_metadata/decoder.rs
Expand Up @@ -41,6 +41,7 @@ use std::str;
use std::u32;

use rustc_serialize::{Decodable, Decoder, SpecializedDecoder, opaque};
use rustc_data_structures::indexed_vec::Idx;
use syntax::attr;
use syntax::ast::{self, Ident};
use syntax::codemap;
Expand Down
1 change: 1 addition & 0 deletions src/librustc_resolve/Cargo.toml
Expand Up @@ -16,3 +16,4 @@ rustc = { path = "../librustc" }
arena = { path = "../libarena" }
rustc_errors = { path = "../librustc_errors" }
syntax_pos = { path = "../libsyntax_pos" }
rustc_data_structures = { path = "../librustc_data_structures" }
1 change: 1 addition & 0 deletions src/librustc_resolve/lib.rs
Expand Up @@ -24,6 +24,7 @@ extern crate rustc_errors as errors;
extern crate arena;
#[macro_use]
extern crate rustc;
extern crate rustc_data_structures;

use self::Namespace::*;
use self::TypeParameters::*;
Expand Down
1 change: 1 addition & 0 deletions src/librustc_resolve/macros.rs
Expand Up @@ -13,6 +13,7 @@ use {Module, ModuleKind, NameBinding, NameBindingKind, PathResult};
use Namespace::{self, MacroNS};
use build_reduced_graph::BuildReducedGraphVisitor;
use resolve_imports::ImportResolver;
use rustc_data_structures::indexed_vec::Idx;
use rustc::hir::def_id::{DefId, BUILTIN_MACROS_CRATE, CRATE_DEF_INDEX, DefIndex};
use rustc::hir::def::{Def, Export};
use rustc::hir::map::{self, DefCollector};
Expand Down

0 comments on commit d19faea

Please sign in to comment.