Skip to content

Commit c0de23d

Browse files
committed
convert to use is_local instead of == LOCAL_CRATE
1 parent e91bef2 commit c0de23d

File tree

31 files changed

+61
-63
lines changed

31 files changed

+61
-63
lines changed

src/librustc/ast_map/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use self::MapEntry::*;
1414

1515
use metadata::inline::InlinedItem;
1616
use metadata::inline::InlinedItem as II;
17-
use middle::def_id::{DefId, LOCAL_CRATE};
17+
use middle::def_id::DefId;
1818
use syntax::abi;
1919
use syntax::ast::*;
2020
use syntax::ast_util;
@@ -592,7 +592,7 @@ impl<'ast> Map<'ast> {
592592
}
593593

594594
pub fn def_id_span(&self, def_id: DefId, fallback: Span) -> Span {
595-
if def_id.krate == LOCAL_CRATE {
595+
if def_id.is_local() {
596596
self.opt_span(def_id.node).unwrap_or(fallback)
597597
} else {
598598
fallback

src/librustc/metadata/decoder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1260,7 +1260,7 @@ pub fn list_crate_metadata(bytes: &[u8], out: &mut io::Write) -> io::Result<()>
12601260
// then we must translate the crate number from that encoded in the external
12611261
// crate to the correct local crate number.
12621262
pub fn translate_def_id(cdata: Cmd, did: DefId) -> DefId {
1263-
if did.krate == LOCAL_CRATE {
1263+
if did.is_local() {
12641264
return DefId { krate: cdata.cnum, node: did.node };
12651265
}
12661266

src/librustc/metadata/encoder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1781,7 +1781,7 @@ fn encode_lang_items(ecx: &EncodeContext, rbml_w: &mut Encoder) {
17811781

17821782
for (i, &def_id) in ecx.tcx.lang_items.items() {
17831783
if let Some(id) = def_id {
1784-
if id.krate == LOCAL_CRATE {
1784+
if id.is_local() {
17851785
rbml_w.start_tag(tag_lang_items_item);
17861786
rbml_w.wr_tagged_u32(tag_lang_items_item_id, i as u32);
17871787
rbml_w.wr_tagged_u32(tag_lang_items_item_node_id, id.node as u32);

src/librustc/middle/intrinsicck.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// except according to those terms.
1010

1111
use middle::def::DefFn;
12-
use middle::def_id::{DefId, LOCAL_CRATE};
12+
use middle::def_id::DefId;
1313
use middle::subst::{Subst, Substs, EnumeratedItems};
1414
use middle::ty::{TransmuteRestriction, ctxt, TyBareFn};
1515
use middle::ty::{self, Ty, HasTypeFlags};

src/librustc/middle/reachable.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> {
203203
// Check the impl. If the generics on the self
204204
// type of the impl require inlining, this method
205205
// does too.
206-
assert!(impl_did.krate == LOCAL_CRATE);
206+
assert!(impl_did.is_local());
207207
match self.tcx
208208
.map
209209
.expect_item(impl_did.node)
@@ -356,7 +356,7 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> {
356356
// reachability, which might result in a compile time loss.
357357
fn mark_destructors_reachable(&mut self) {
358358
for (_, destructor_def_id) in self.tcx.destructor_for_type.borrow().iter() {
359-
if destructor_def_id.krate == LOCAL_CRATE {
359+
if destructor_def_id.is_local() {
360360
self.reachable_symbols.insert(destructor_def_id.node);
361361
}
362362
}

src/librustc/middle/traits/coherence.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ pub fn orphan_check<'tcx>(tcx: &ty::ctxt<'tcx>,
186186
debug!("orphan_check: trait_ref={:?}", trait_ref);
187187

188188
// If the *trait* is local to the crate, ok.
189-
if trait_ref.def_id.krate == LOCAL_CRATE {
189+
if trait_ref.def_id.is_local() {
190190
debug!("trait {:?} is local to current crate",
191191
trait_ref.def_id);
192192
return Ok(());
@@ -318,7 +318,7 @@ fn ty_is_local_constructor<'tcx>(tcx: &ty::ctxt<'tcx>,
318318

319319
ty::TyEnum(def, _) |
320320
ty::TyStruct(def, _) => {
321-
def.did.krate == LOCAL_CRATE
321+
def.did.is_local()
322322
}
323323

324324
ty::TyBox(_) => { // Box<T>
@@ -327,7 +327,7 @@ fn ty_is_local_constructor<'tcx>(tcx: &ty::ctxt<'tcx>,
327327
}
328328

329329
ty::TyTrait(ref tt) => {
330-
tt.principal_def_id().krate == LOCAL_CRATE
330+
tt.principal_def_id().is_local()
331331
}
332332

333333
ty::TyClosure(..) |

src/librustc/middle/ty.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5468,7 +5468,7 @@ fn lookup_locally_or_in_crate_store<V, F>(descr: &str,
54685468
None => { }
54695469
}
54705470

5471-
if def_id.krate == LOCAL_CRATE {
5471+
if def_id.is_local() {
54725472
panic!("No def'n found for {:?} in tcx.{}", def_id, descr);
54735473
}
54745474
let v = load_external();
@@ -5776,7 +5776,7 @@ impl<'tcx> ctxt<'tcx> {
57765776
expected.ty,
57775777
found.ty));
57785778

5779-
match (expected.def_id.krate == LOCAL_CRATE,
5779+
match (expected.def_id.is_local(),
57805780
self.map.opt_span(expected.def_id.node)) {
57815781
(true, Some(span)) => {
57825782
self.sess.span_note(span,
@@ -5793,7 +5793,7 @@ impl<'tcx> ctxt<'tcx> {
57935793
expected.origin_span,
57945794
&format!("...that was applied to an unconstrained type variable here"));
57955795

5796-
match (found.def_id.krate == LOCAL_CRATE,
5796+
match (found.def_id.is_local(),
57975797
self.map.opt_span(found.def_id.node)) {
57985798
(true, Some(span)) => {
57995799
self.sess.span_note(span,
@@ -5905,7 +5905,7 @@ impl<'tcx> ctxt<'tcx> {
59055905
}
59065906

59075907
pub fn trait_impl_polarity(&self, id: DefId) -> Option<ast::ImplPolarity> {
5908-
if id.krate == LOCAL_CRATE {
5908+
if id.is_local() {
59095909
match self.map.find(id.node) {
59105910
Some(ast_map::NodeItem(item)) => {
59115911
match item.node {
@@ -5961,7 +5961,7 @@ impl<'tcx> ctxt<'tcx> {
59615961

59625962
/// Returns whether this DefId refers to an impl
59635963
pub fn is_impl(&self, id: DefId) -> bool {
5964-
if id.krate == LOCAL_CRATE {
5964+
if id.is_local() {
59655965
if let Some(ast_map::NodeItem(
59665966
&ast::Item { node: ast::ItemImpl(..), .. })) = self.map.find(id.node) {
59675967
true
@@ -6012,7 +6012,7 @@ impl<'tcx> ctxt<'tcx> {
60126012
pub fn with_path<T, F>(&self, id: DefId, f: F) -> T where
60136013
F: FnOnce(ast_map::PathElems) -> T,
60146014
{
6015-
if id.krate == LOCAL_CRATE {
6015+
if id.is_local() {
60166016
self.map.with_path(id.node, f)
60176017
} else {
60186018
f(csearch::get_item_path(self, id).iter().cloned().chain(LinkedPath::empty()))
@@ -6135,7 +6135,7 @@ impl<'tcx> ctxt<'tcx> {
61356135
/// Obtain the representation annotation for a struct definition.
61366136
pub fn lookup_repr_hints(&self, did: DefId) -> Rc<Vec<attr::ReprAttr>> {
61376137
memoized(&self.repr_hint_cache, did, |did: DefId| {
6138-
Rc::new(if did.krate == LOCAL_CRATE {
6138+
Rc::new(if did.is_local() {
61396139
self.get_attrs(did).iter().flat_map(|meta| {
61406140
attr::find_repr_attrs(self.sess.diagnostic(), meta).into_iter()
61416141
}).collect()
@@ -6315,7 +6315,7 @@ impl<'tcx> ctxt<'tcx> {
63156315
/// Load primitive inherent implementations if necessary
63166316
pub fn populate_implementations_for_primitive_if_necessary(&self,
63176317
primitive_def_id: DefId) {
6318-
if primitive_def_id.krate == LOCAL_CRATE {
6318+
if primitive_def_id.is_local() {
63196319
return
63206320
}
63216321

@@ -6337,7 +6337,7 @@ impl<'tcx> ctxt<'tcx> {
63376337
/// the given type if necessary.
63386338
pub fn populate_inherent_implementations_for_type_if_necessary(&self,
63396339
type_id: DefId) {
6340-
if type_id.krate == LOCAL_CRATE {
6340+
if type_id.is_local() {
63416341
return
63426342
}
63436343

@@ -6365,7 +6365,7 @@ impl<'tcx> ctxt<'tcx> {
63656365
/// Populates the type context with all the implementations for the given
63666366
/// trait if necessary.
63676367
pub fn populate_implementations_for_trait_if_necessary(&self, trait_id: DefId) {
6368-
if trait_id.krate == LOCAL_CRATE {
6368+
if trait_id.is_local() {
63696369
return
63706370
}
63716371

src/librustc/util/ppaux.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// except according to those terms.
1010

1111

12-
use middle::def_id::{DefId, LOCAL_CRATE};
12+
use middle::def_id::DefId;
1313
use middle::subst::{self, Subst};
1414
use middle::ty::{BoundRegion, BrAnon, BrNamed};
1515
use middle::ty::{ReEarlyBound, BrFresh, ctxt};
@@ -659,7 +659,7 @@ impl<'tcx> fmt::Display for ty::TypeVariants<'tcx> {
659659
TyParam(ref param_ty) => write!(f, "{}", param_ty),
660660
TyEnum(def, substs) | TyStruct(def, substs) => {
661661
ty::tls::with(|tcx| {
662-
if def.did.krate == LOCAL_CRATE &&
662+
if def.did.is_local() &&
663663
!tcx.tcache.borrow().contains_key(&def.did) {
664664
write!(f, "{}<..>", tcx.item_path_str(def.did))
665665
} else {
@@ -674,7 +674,7 @@ impl<'tcx> fmt::Display for ty::TypeVariants<'tcx> {
674674
TyClosure(ref did, ref substs) => ty::tls::with(|tcx| {
675675
try!(write!(f, "[closure"));
676676

677-
if did.krate == LOCAL_CRATE {
677+
if did.is_local() {
678678
try!(write!(f, "@{:?}", tcx.map.span(did.node)));
679679
let mut sep = " ";
680680
try!(tcx.with_freevars(did.node, |freevars| {

src/librustc_borrowck/borrowck/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use rustc::middle::dataflow::DataFlowContext;
2727
use rustc::middle::dataflow::BitwiseOperator;
2828
use rustc::middle::dataflow::DataFlowOperator;
2929
use rustc::middle::dataflow::KillFrom;
30-
use rustc::middle::def_id::{DefId, LOCAL_CRATE};
30+
use rustc::middle::def_id::DefId;
3131
use rustc::middle::expr_use_visitor as euv;
3232
use rustc::middle::free_region::FreeRegionMap;
3333
use rustc::middle::mem_categorization as mc;
@@ -1193,7 +1193,7 @@ impl<'tcx> fmt::Debug for LoanPath<'tcx> {
11931193
}
11941194

11951195
LpDowncast(ref lp, variant_def_id) => {
1196-
let variant_str = if variant_def_id.krate == LOCAL_CRATE {
1196+
let variant_str = if variant_def_id.is_local() {
11971197
ty::tls::with(|tcx| tcx.item_path_str(variant_def_id))
11981198
} else {
11991199
format!("{:?}", variant_def_id)
@@ -1225,7 +1225,7 @@ impl<'tcx> fmt::Display for LoanPath<'tcx> {
12251225
}
12261226

12271227
LpDowncast(ref lp, variant_def_id) => {
1228-
let variant_str = if variant_def_id.krate == LOCAL_CRATE {
1228+
let variant_str = if variant_def_id.is_local() {
12291229
ty::tls::with(|tcx| tcx.item_path_str(variant_def_id))
12301230
} else {
12311231
format!("{:?}", variant_def_id)

src/librustc_lint/builtin.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
3131
use metadata::{csearch, decoder};
3232
use middle::{cfg, def, infer, pat_util, stability, traits};
33-
use middle::def_id::{DefId, LOCAL_CRATE};
33+
use middle::def_id::DefId;
3434
use middle::subst::Substs;
3535
use middle::ty::{self, Ty};
3636
use middle::const_eval::{eval_const_expr_partial, ConstVal};
@@ -2029,7 +2029,7 @@ impl LintPass for MissingDebugImplementations {
20292029
let debug_def = cx.tcx.lookup_trait_def(debug);
20302030
let mut impls = NodeSet();
20312031
debug_def.for_each_impl(cx.tcx, |d| {
2032-
if d.krate == LOCAL_CRATE {
2032+
if d.is_local() {
20332033
if let Some(ty_def) = cx.tcx.node_id_to_type(d.node).ty_to_def_id() {
20342034
impls.insert(ty_def.node);
20352035
}
@@ -2569,7 +2569,7 @@ impl LintPass for DropWithReprExtern {
25692569
fn check_crate(&mut self, ctx: &Context, _: &ast::Crate) {
25702570
for dtor_did in ctx.tcx.destructors.borrow().iter() {
25712571
let (drop_impl_did, dtor_self_type) =
2572-
if dtor_did.krate == LOCAL_CRATE {
2572+
if dtor_did.is_local() {
25732573
let impl_did = ctx.tcx.map.get_parent_did(dtor_did.node);
25742574
let ty = ctx.tcx.lookup_item_type(impl_did).ty;
25752575
(impl_did, ty)

src/librustc_resolve/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ use rustc::lint;
5656
use rustc::metadata::csearch;
5757
use rustc::metadata::decoder::{DefLike, DlDef, DlField, DlImpl};
5858
use rustc::middle::def::*;
59-
use rustc::middle::def_id::{DefId, LOCAL_CRATE};
59+
use rustc::middle::def_id::DefId;
6060
use rustc::middle::pat_util::pat_bindings;
6161
use rustc::middle::privacy::*;
6262
use rustc::middle::subst::{ParamSpace, FnSpace, TypeSpace};
@@ -1256,7 +1256,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
12561256
}
12571257

12581258
fn get_trait_name(&self, did: DefId) -> Name {
1259-
if did.krate == LOCAL_CRATE {
1259+
if did.is_local() {
12601260
self.ast_map.expect_item(did.node).ident.name
12611261
} else {
12621262
csearch::get_trait_name(&self.session.cstore, did)
@@ -3467,7 +3467,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
34673467
}
34683468

34693469
fn is_static_method(this: &Resolver, did: DefId) -> bool {
3470-
if did.krate == LOCAL_CRATE {
3470+
if did.is_local() {
34713471
let sig = match this.ast_map.get(did.node) {
34723472
ast_map::NodeTraitItem(trait_item) => match trait_item.node {
34733473
ast::MethodTraitItem(ref sig, _) => sig,

src/librustc_resolve/record_exports.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ use build_reduced_graph;
2525
use module_to_string;
2626

2727
use rustc::middle::def::Export;
28-
use rustc::middle::def_id::LOCAL_CRATE;
2928
use syntax::ast;
3029

3130
use std::ops::{Deref, DerefMut};
@@ -57,7 +56,7 @@ impl<'a, 'b, 'tcx> ExportRecorder<'a, 'b, 'tcx> {
5756
// exports for nonlocal crates.
5857

5958
match module_.def_id.get() {
60-
Some(def_id) if def_id.krate == LOCAL_CRATE => {
59+
Some(def_id) if def_id.is_local() => {
6160
// OK. Continue.
6261
debug!("(recording exports for module subtree) recording \
6362
exports for local module `{}`",

src/librustc_trans/save/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
546546
}
547547
def::DefMethod(decl_id) => {
548548
let sub_span = self.span_utils.sub_span_for_meth_name(path.span);
549-
let def_id = if decl_id.krate == LOCAL_CRATE {
549+
let def_id = if decl_id.is_local() {
550550
let ti = self.tcx.impl_or_trait_item(decl_id);
551551
match ti.container() {
552552
ty::TraitContainer(def_id) => {

src/librustc_trans/trans/base.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2247,7 +2247,7 @@ pub fn create_entry_wrapper(ccx: &CrateContext,
22472247
Ok(id) => id,
22482248
Err(s) => { ccx.sess().fatal(&s[..]); }
22492249
};
2250-
let start_fn = if start_def_id.krate == LOCAL_CRATE {
2250+
let start_fn = if start_def_id.is_local() {
22512251
get_item_val(ccx, start_def_id.node)
22522252
} else {
22532253
let start_fn_type = csearch::get_type(ccx.tcx(),

src/librustc_trans/trans/callee.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ pub fn trans_fn_ref_with_substs<'a, 'tcx>(
464464
// or is a named tuple constructor.
465465
let must_monomorphise = if !substs.types.is_empty() || is_default {
466466
true
467-
} else if def_id.krate == LOCAL_CRATE {
467+
} else if def_id.is_local() {
468468
let map_node = session::expect(
469469
ccx.sess(),
470470
tcx.map.find(def_id.node),
@@ -524,7 +524,7 @@ pub fn trans_fn_ref_with_substs<'a, 'tcx>(
524524

525525
// Find the actual function pointer.
526526
let mut val = {
527-
if def_id.krate == LOCAL_CRATE {
527+
if def_id.is_local() {
528528
// Internal reference.
529529
get_item_val(ccx, def_id.node)
530530
} else {

src/librustc_trans/trans/debuginfo/metadata.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use super::{declare_local, VariableKind, VariableAccess};
2323
use llvm::{self, ValueRef};
2424
use llvm::debuginfo::{DIType, DIFile, DIScope, DIDescriptor, DICompositeType};
2525

26-
use middle::def_id::{DefId, LOCAL_CRATE};
26+
use middle::def_id::DefId;
2727
use middle::pat_util;
2828
use middle::subst::{self, Substs};
2929
use rustc::ast_map;
@@ -322,7 +322,7 @@ impl<'tcx> TypeMap<'tcx> {
322322
output: &mut String) {
323323
// First, find out the 'real' def_id of the type. Items inlined from
324324
// other crates have to be mapped back to their source.
325-
let source_def_id = if def_id.krate == LOCAL_CRATE {
325+
let source_def_id = if def_id.is_local() {
326326
match cx.external_srcs().borrow().get(&def_id.node).cloned() {
327327
Some(source_def_id) => {
328328
// The given def_id identifies the inlined copy of a
@@ -336,7 +336,7 @@ impl<'tcx> TypeMap<'tcx> {
336336
};
337337

338338
// Get the crate hash as first part of the identifier.
339-
let crate_hash = if source_def_id.krate == LOCAL_CRATE {
339+
let crate_hash = if source_def_id.is_local() {
340340
cx.link_meta().crate_hash.clone()
341341
} else {
342342
cx.sess().cstore.get_crate_hash(source_def_id.krate)

src/librustc_trans/trans/debuginfo/namespace.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use super::utils::{DIB, debug_context};
1515
use llvm;
1616
use llvm::debuginfo::DIScope;
1717
use rustc::ast_map;
18-
use rustc::middle::def_id::{DefId, LOCAL_CRATE};
18+
use rustc::middle::def_id::DefId;
1919
use trans::common::CrateContext;
2020

2121
use std::ffi::CString;
@@ -58,7 +58,7 @@ pub fn crate_root_namespace<'a>(cx: &'a CrateContext) -> &'a str {
5858
pub fn namespace_for_item(cx: &CrateContext, def_id: DefId) -> Rc<NamespaceTreeNode> {
5959
cx.tcx().with_path(def_id, |path| {
6060
// prepend crate name if not already present
61-
let krate = if def_id.krate == LOCAL_CRATE {
61+
let krate = if def_id.is_local() {
6262
let crate_namespace_name = token::intern(crate_root_namespace(cx));
6363
Some(ast_map::PathMod(crate_namespace_name))
6464
} else {

0 commit comments

Comments
 (0)