Skip to content

Commit d19faea

Browse files
committed
Make DefIndex use newtype_index macro
1 parent f9bc8e7 commit d19faea

File tree

8 files changed

+16
-26
lines changed

8 files changed

+16
-26
lines changed

src/Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/librustc/hir/def_id.rs

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -86,20 +86,17 @@ impl serialize::UseSpecializedDecodable for CrateNum {
8686
///
8787
/// Since the DefIndex is mostly treated as an opaque ID, you probably
8888
/// don't have to care about these ranges.
89-
#[derive(Clone, Eq, Ord, PartialOrd, PartialEq, RustcEncodable,
90-
RustcDecodable, Hash, Copy)]
91-
pub struct DefIndex(u32);
89+
newtype_index!(DefIndex
90+
{
91+
DEBUG_FORMAT = custom,
9292

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

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

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

113110
impl DefIndex {
114-
#[inline]
115-
pub fn new(x: usize) -> DefIndex {
116-
assert!(x < (u32::MAX as usize));
117-
DefIndex(x as u32)
118-
}
119-
120111
#[inline]
121112
pub fn from_u32(x: u32) -> DefIndex {
122113
DefIndex(x)
@@ -155,13 +146,6 @@ impl DefIndex {
155146
}
156147
}
157148

158-
/// The start of the "high" range of DefIndexes.
159-
const DEF_INDEX_HI_START: DefIndex = DefIndex(1 << 31);
160-
161-
/// The crate root is always assigned index 0 by the AST Map code,
162-
/// thanks to `NodeCollector::new`.
163-
pub const CRATE_DEF_INDEX: DefIndex = DefIndex(0);
164-
165149
#[derive(Copy, Clone, Eq, PartialEq, Hash)]
166150
pub enum DefIndexAddressSpace {
167151
Low = 0,

src/librustc/hir/map/definitions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use hir::def_id::{CrateNum, DefId, DefIndex, LOCAL_CRATE, DefIndexAddressSpace,
1919
CRATE_DEF_INDEX};
2020
use ich::Fingerprint;
2121
use rustc_data_structures::fx::FxHashMap;
22-
use rustc_data_structures::indexed_vec::IndexVec;
22+
use rustc_data_structures::indexed_vec::{IndexVec, Idx};
2323
use rustc_data_structures::stable_hasher::StableHasher;
2424
use serialize::{Encodable, Decodable, Encoder, Decoder};
2525
use session::CrateDisambiguator;

src/librustc/infer/region_inference/graphviz.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use graphviz as dot;
2020

2121
use hir::def_id::DefIndex;
22+
use rustc_data_structures::indexed_vec::Idx;
2223
use ty;
2324
use middle::free_region::RegionRelations;
2425
use middle::region;

src/librustc_metadata/decoder.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ use std::str;
4141
use std::u32;
4242

4343
use rustc_serialize::{Decodable, Decoder, SpecializedDecoder, opaque};
44+
use rustc_data_structures::indexed_vec::Idx;
4445
use syntax::attr;
4546
use syntax::ast::{self, Ident};
4647
use syntax::codemap;

src/librustc_resolve/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ rustc = { path = "../librustc" }
1616
arena = { path = "../libarena" }
1717
rustc_errors = { path = "../librustc_errors" }
1818
syntax_pos = { path = "../libsyntax_pos" }
19+
rustc_data_structures = { path = "../librustc_data_structures" }

src/librustc_resolve/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ extern crate rustc_errors as errors;
2424
extern crate arena;
2525
#[macro_use]
2626
extern crate rustc;
27+
extern crate rustc_data_structures;
2728

2829
use self::Namespace::*;
2930
use self::TypeParameters::*;

src/librustc_resolve/macros.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use {Module, ModuleKind, NameBinding, NameBindingKind, PathResult};
1313
use Namespace::{self, MacroNS};
1414
use build_reduced_graph::BuildReducedGraphVisitor;
1515
use resolve_imports::ImportResolver;
16+
use rustc_data_structures::indexed_vec::Idx;
1617
use rustc::hir::def_id::{DefId, BUILTIN_MACROS_CRATE, CRATE_DEF_INDEX, DefIndex};
1718
use rustc::hir::def::{Def, Export};
1819
use rustc::hir::map::{self, DefCollector};

0 commit comments

Comments
 (0)