-
-
Save spastorino/4c9c55df5f28293bc131b9bfb576c41e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/librustc/hir/def_id.rs b/src/librustc/hir/def_id.rs | |
index 8e48352007..6552b3d450 100644 | |
--- a/src/librustc/hir/def_id.rs | |
+++ b/src/librustc/hir/def_id.rs | |
@@ -16,37 +16,20 @@ use serialize::{self, Encoder, Decoder}; | |
use std::fmt; | |
use std::u32; | |
-#[derive(Clone, Copy, Eq, Ord, PartialOrd, PartialEq, Hash, Debug)] | |
-pub struct CrateNum(u32); | |
- | |
-impl Idx for CrateNum { | |
- fn new(value: usize) -> Self { | |
- assert!(value < (u32::MAX) as usize); | |
- CrateNum(value as u32) | |
- } | |
- | |
- fn index(self) -> usize { | |
- self.0 as usize | |
- } | |
-} | |
+newtype_index!(CrateNum); | |
/// Item definitions in the currently-compiled crate would have the CrateNum | |
/// LOCAL_CRATE in their DefId. | |
-pub const LOCAL_CRATE: CrateNum = CrateNum(0); | |
+pub const LOCAL_CRATE: CrateNum = CrateNum::const_new(0); | |
/// Virtual crate for builtin macros | |
// FIXME(jseyfried): this is also used for custom derives until proc-macro crates get `CrateNum`s. | |
-pub const BUILTIN_MACROS_CRATE: CrateNum = CrateNum(u32::MAX); | |
+pub const BUILTIN_MACROS_CRATE: CrateNum = CrateNum::const_new(u32::MAX); | |
/// A CrateNum value that indicates that something is wrong. | |
-pub const INVALID_CRATE: CrateNum = CrateNum(u32::MAX - 1); | |
+pub const INVALID_CRATE: CrateNum = CrateNum::const_new(u32::MAX - 1); | |
impl CrateNum { | |
- pub fn new(x: usize) -> CrateNum { | |
- assert!(x < (u32::MAX as usize)); | |
- CrateNum(x as u32) | |
- } | |
- | |
pub fn from_u32(x: u32) -> CrateNum { | |
CrateNum(x) | |
} | |
diff --git a/src/librustc/middle/dependency_format.rs b/src/librustc/middle/dependency_format.rs | |
index db0ecb6aa5..6548d8d3ac 100644 | |
--- a/src/librustc/middle/dependency_format.rs | |
+++ b/src/librustc/middle/dependency_format.rs | |
@@ -70,6 +70,7 @@ use middle::cstore::{self, DepKind}; | |
use middle::cstore::LinkagePreference::{self, RequireStatic, RequireDynamic}; | |
use util::nodemap::FxHashMap; | |
use rustc_back::PanicStrategy; | |
+use rustc_data_structures::indexed_vec::Idx; | |
/// A list of dependencies for a certain crate type. | |
/// | |
diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs | |
index bc5a056dd3..a7426ba3db 100644 | |
--- a/src/librustc/ty/mod.rs | |
+++ b/src/librustc/ty/mod.rs | |
@@ -2334,9 +2334,10 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { | |
} | |
pub fn adjust_ident(self, mut ident: Ident, scope: DefId, block: NodeId) -> (Ident, DefId) { | |
- let expansion = match scope.krate { | |
- LOCAL_CRATE => self.hir.definitions().expansion(scope.index), | |
- _ => Mark::root(), | |
+ let expansion = if scope.is_local() { | |
+ self.hir.definitions().expansion(scope.index) | |
+ } else { | |
+ Mark::root() | |
}; | |
let scope = match ident.ctxt.adjust(expansion) { | |
Some(macro_def) => self.hir.definitions().macro_def_scope(macro_def), | |
diff --git a/src/librustc_metadata/cstore.rs b/src/librustc_metadata/cstore.rs | |
index 9e47e96aee..24d0003ea7 100644 | |
--- a/src/librustc_metadata/cstore.rs | |
+++ b/src/librustc_metadata/cstore.rs | |
@@ -18,7 +18,7 @@ use rustc::hir::map::definitions::DefPathTable; | |
use rustc::hir::svh::Svh; | |
use rustc::middle::cstore::{DepKind, ExternCrate, MetadataLoader}; | |
use rustc_back::PanicStrategy; | |
-use rustc_data_structures::indexed_vec::IndexVec; | |
+use rustc_data_structures::indexed_vec::{IndexVec, Idx}; | |
use rustc::util::nodemap::{FxHashMap, FxHashSet, NodeMap}; | |
use std::cell::{RefCell, Cell}; | |
diff --git a/src/librustc_metadata/decoder.rs b/src/librustc_metadata/decoder.rs | |
index 65cf15e5a0..87a899661c 100644 | |
--- a/src/librustc_metadata/decoder.rs | |
+++ b/src/librustc_metadata/decoder.rs | |
@@ -40,6 +40,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; | |
diff --git a/src/librustc_metadata/encoder.rs b/src/librustc_metadata/encoder.rs | |
index 6b49be3e12..72eb9ddc2e 100644 | |
--- a/src/librustc_metadata/encoder.rs | |
+++ b/src/librustc_metadata/encoder.rs | |
@@ -29,6 +29,7 @@ use rustc::ty::{self, Ty, TyCtxt, ReprOptions}; | |
use rustc::session::config::{self, CrateTypeProcMacro}; | |
use rustc::util::nodemap::{FxHashMap, NodeSet}; | |
+use rustc_data_structures::indexed_vec::Idx; | |
use rustc_serialize::{Encodable, Encoder, SpecializedEncoder, opaque}; | |
use std::hash::Hash; | |
diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs | |
index 36cd69f91b..4e9d530380 100644 | |
--- a/src/librustc_resolve/lib.rs | |
+++ b/src/librustc_resolve/lib.rs | |
@@ -35,7 +35,7 @@ use rustc::middle::cstore::{CrateStore, CrateLoader}; | |
use rustc::session::Session; | |
use rustc::lint; | |
use rustc::hir::def::*; | |
-use rustc::hir::def_id::{CRATE_DEF_INDEX, LOCAL_CRATE, DefId}; | |
+use rustc::hir::def_id::{CRATE_DEF_INDEX, DefId}; | |
use rustc::ty; | |
use rustc::hir::{Freevar, FreevarMap, TraitCandidate, TraitMap, GlobMap}; | |
use rustc::util::nodemap::{NodeMap, NodeSet, FxHashMap, FxHashSet, DefIdMap}; | |
@@ -1353,9 +1353,10 @@ impl<'a> ResolverArenas<'a> { | |
impl<'a, 'b: 'a> ty::DefIdTree for &'a Resolver<'b> { | |
fn parent(self, id: DefId) -> Option<DefId> { | |
- match id.krate { | |
- LOCAL_CRATE => self.definitions.def_key(id.index).parent, | |
- _ => self.cstore.def_key(id).parent, | |
+ if id.is_local() { | |
+ self.definitions.def_key(id.index).parent | |
+ } else { | |
+ self.cstore.def_key(id).parent | |
}.map(|index| DefId { index: index, ..id }) | |
} | |
} | |
diff --git a/src/librustc_trans/back/linker.rs b/src/librustc_trans/back/linker.rs | |
index 99422bf8c9..bda7afdbeb 100644 | |
--- a/src/librustc_trans/back/linker.rs | |
+++ b/src/librustc_trans/back/linker.rs | |
@@ -24,6 +24,7 @@ use rustc::session::Session; | |
use rustc::session::config::{self, CrateType, OptLevel, DebugInfoLevel}; | |
use rustc::ty::TyCtxt; | |
use rustc_back::LinkerFlavor; | |
+use rustc_data_structures::indexed_vec::Idx; | |
use serialize::{json, Encoder}; | |
/// For all the linkers we support, and information they might |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment