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)

0 commit comments

Comments
 (0)