diff options
51 files changed, 414 insertions, 326 deletions
diff --git a/src/librustc/front/map/mod.rs b/src/librustc/front/map/mod.rs index 16c455537b6..8d8932552b7 100644 --- a/src/librustc/front/map/mod.rs +++ b/src/librustc/front/map/mod.rs @@ -12,6 +12,7 @@ pub use self::Node::*; pub use self::PathElem::*; use self::MapEntry::*; +use metadata::cstore::LOCAL_CRATE; use metadata::inline::InlinedItem; use metadata::inline::InlinedItem as II; use middle::def_id::DefId; @@ -267,6 +268,18 @@ pub struct Map<'ast> { } impl<'ast> Map<'ast> { + pub fn local_def_id(&self, node: NodeId) -> DefId { + DefId::xxx_local(node) + } + + pub fn as_local_node_id(&self, def_id: DefId) -> Option<NodeId> { + if def_id.krate == LOCAL_CRATE { + Some(def_id.node) + } else { + None + } + } + fn entry_count(&self) -> usize { self.map.borrow().len() } @@ -383,7 +396,7 @@ impl<'ast> Map<'ast> { match self.find_entry(parent) { Some(RootInlinedParent(&InlinedParent {ii: II::TraitItem(did, _), ..})) => did, Some(RootInlinedParent(&InlinedParent {ii: II::ImplItem(did, _), ..})) => did, - _ => DefId::local(parent) + _ => self.local_def_id(parent) } } @@ -1134,3 +1147,4 @@ fn node_id_to_string(map: &Map, id: NodeId, include_id: bool) -> String { } } } + diff --git a/src/librustc/metadata/encoder.rs b/src/librustc/metadata/encoder.rs index 126626e3a20..b67da4baf5a 100644 --- a/src/librustc/metadata/encoder.rs +++ b/src/librustc/metadata/encoder.rs @@ -119,7 +119,7 @@ pub fn def_to_string(did: DefId) -> String { fn encode_item_variances(rbml_w: &mut Encoder, ecx: &EncodeContext, id: NodeId) { - let v = ecx.tcx.item_variances(DefId::local(id)); + let v = ecx.tcx.item_variances(ecx.tcx.map.local_def_id(id)); rbml_w.start_tag(tag_item_variances); v.encode(rbml_w); rbml_w.end_tag(); @@ -130,8 +130,8 @@ fn encode_bounds_and_type_for_item<'a, 'tcx>(rbml_w: &mut Encoder, id: NodeId) { encode_bounds_and_type(rbml_w, ecx, - &ecx.tcx.lookup_item_type(DefId::local(id)), - &ecx.tcx.lookup_predicates(DefId::local(id))); + &ecx.tcx.lookup_item_type(ecx.tcx.map.local_def_id(id)), + &ecx.tcx.lookup_predicates(ecx.tcx.map.local_def_id(id))); } fn encode_bounds_and_type<'a, 'tcx>(rbml_w: &mut Encoder, @@ -278,7 +278,7 @@ fn encode_enum_variant_info(ecx: &EncodeContext, debug!("encode_enum_variant_info(id={})", id); let mut disr_val = 0; - let def = ecx.tcx.lookup_adt_def(DefId::local(id)); + let def = ecx.tcx.lookup_adt_def(ecx.tcx.map.local_def_id(id)); for variant in &def.variants { let vid = variant.did; assert!(vid.is_local()); @@ -302,7 +302,7 @@ fn encode_enum_variant_info(ecx: &EncodeContext, ty::VariantKind::Dict => 'V' }); encode_name(rbml_w, variant.name); - encode_parent_item(rbml_w, DefId::local(id)); + encode_parent_item(rbml_w, ecx.tcx.map.local_def_id(id)); encode_visibility(rbml_w, vis); let attrs = ecx.tcx.get_attrs(vid); @@ -504,7 +504,7 @@ fn encode_info_for_mod(ecx: &EncodeContext, name: Name, vis: hir::Visibility) { rbml_w.start_tag(tag_items_data_item); - encode_def_id(rbml_w, DefId::local(id)); + encode_def_id(rbml_w, ecx.tcx.map.local_def_id(id)); encode_family(rbml_w, 'm'); encode_name(rbml_w, name); debug!("(encoding info for module) encoding info for module ID {}", id); @@ -512,11 +512,11 @@ fn encode_info_for_mod(ecx: &EncodeContext, // Encode info about all the module children. for item in &md.items { rbml_w.wr_tagged_u64(tag_mod_child, - def_to_u64(DefId::local(item.id))); + def_to_u64(ecx.tcx.map.local_def_id(item.id))); each_auxiliary_node_id(&**item, |auxiliary_node_id| { rbml_w.wr_tagged_u64(tag_mod_child, - def_to_u64(DefId::local(auxiliary_node_id))); + def_to_u64(ecx.tcx.map.local_def_id(auxiliary_node_id))); true }); @@ -526,14 +526,14 @@ fn encode_info_for_mod(ecx: &EncodeContext, name, did, ecx.tcx.map.node_to_string(did)); - rbml_w.wr_tagged_u64(tag_mod_impl, def_to_u64(DefId::local(did))); + rbml_w.wr_tagged_u64(tag_mod_impl, def_to_u64(ecx.tcx.map.local_def_id(did))); } } encode_path(rbml_w, path.clone()); encode_visibility(rbml_w, vis); - let stab = stability::lookup(ecx.tcx, DefId::local(id)); + let stab = stability::lookup(ecx.tcx, ecx.tcx.map.local_def_id(id)); encode_stability(rbml_w, stab); // Encode the reexports of this module, if this module is public. @@ -627,7 +627,7 @@ fn encode_field<'a, 'tcx>(ecx: &EncodeContext<'a, 'tcx>, encode_struct_field_family(rbml_w, field.vis); encode_name(rbml_w, nm); encode_bounds_and_type_for_item(rbml_w, ecx, id); - encode_def_id(rbml_w, DefId::local(id)); + encode_def_id(rbml_w, ecx.tcx.map.local_def_id(id)); let stab = stability::lookup(ecx.tcx, field.did); encode_stability(rbml_w, stab); @@ -647,18 +647,18 @@ fn encode_info_for_struct_ctor(ecx: &EncodeContext, }); rbml_w.start_tag(tag_items_data_item); - encode_def_id(rbml_w, DefId::local(ctor_id)); + encode_def_id(rbml_w, ecx.tcx.map.local_def_id(ctor_id)); encode_family(rbml_w, 'o'); encode_bounds_and_type_for_item(rbml_w, ecx, ctor_id); encode_name(rbml_w, name); ecx.tcx.map.with_path(ctor_id, |path| encode_path(rbml_w, path)); - encode_parent_item(rbml_w, DefId::local(struct_id)); + encode_parent_item(rbml_w, ecx.tcx.map.local_def_id(struct_id)); if ecx.item_symbols.borrow().contains_key(&ctor_id) { encode_symbol(ecx, rbml_w, ctor_id); } - let stab = stability::lookup(ecx.tcx, DefId::local(ctor_id)); + let stab = stability::lookup(ecx.tcx, ecx.tcx.map.local_def_id(ctor_id)); encode_stability(rbml_w, stab); // indicate that this is a tuple struct ctor, because downstream users will normally want @@ -789,7 +789,7 @@ fn encode_info_for_associated_const(ecx: &EncodeContext, encode_visibility(rbml_w, associated_const.vis); encode_family(rbml_w, 'C'); - encode_parent_item(rbml_w, DefId::local(parent_id)); + encode_parent_item(rbml_w, ecx.tcx.map.local_def_id(parent_id)); encode_item_sort(rbml_w, 'C'); encode_bounds_and_type_for_item(rbml_w, ecx, associated_const.def_id.local_id()); @@ -802,7 +802,10 @@ fn encode_info_for_associated_const(ecx: &EncodeContext, if let Some(ii) = impl_item_opt { encode_attributes(rbml_w, &ii.attrs); - encode_inlined_item(ecx, rbml_w, InlinedItemRef::ImplItem(DefId::local(parent_id), ii)); + encode_inlined_item(ecx, + rbml_w, + InlinedItemRef::ImplItem(ecx.tcx.map.local_def_id(parent_id), + ii)); } rbml_w.end_tag(); @@ -821,7 +824,7 @@ fn encode_info_for_method<'a, 'tcx>(ecx: &EncodeContext<'a, 'tcx>, rbml_w.start_tag(tag_items_data_item); encode_method_ty_fields(ecx, rbml_w, m); - encode_parent_item(rbml_w, DefId::local(parent_id)); + encode_parent_item(rbml_w, ecx.tcx.map.local_def_id(parent_id)); encode_item_sort(rbml_w, 'r'); let stab = stability::lookup(ecx.tcx, m.def_id); @@ -840,8 +843,10 @@ fn encode_info_for_method<'a, 'tcx>(ecx: &EncodeContext<'a, 'tcx>, let needs_inline = any_types || is_default_impl || attr::requests_inline(&impl_item.attrs); if needs_inline || sig.constness == hir::Constness::Const { - encode_inlined_item(ecx, rbml_w, InlinedItemRef::ImplItem(DefId::local(parent_id), - impl_item)); + encode_inlined_item(ecx, + rbml_w, + InlinedItemRef::ImplItem(ecx.tcx.map.local_def_id(parent_id), + impl_item)); } encode_constness(rbml_w, sig.constness); if !any_types { @@ -870,7 +875,7 @@ fn encode_info_for_associated_type<'a, 'tcx>(ecx: &EncodeContext<'a, 'tcx>, encode_name(rbml_w, associated_type.name); encode_visibility(rbml_w, associated_type.vis); encode_family(rbml_w, 'y'); - encode_parent_item(rbml_w, DefId::local(parent_id)); + encode_parent_item(rbml_w, ecx.tcx.map.local_def_id(parent_id)); encode_item_sort(rbml_w, 't'); let stab = stability::lookup(ecx.tcx, associated_type.def_id); @@ -991,8 +996,8 @@ fn encode_info_for_item(ecx: &EncodeContext, debug!("encoding info for item at {}", tcx.sess.codemap().span_to_string(item.span)); - let def_id = DefId::local(item.id); - let stab = stability::lookup(tcx, DefId::local(item.id)); + let def_id = ecx.tcx.map.local_def_id(item.id); + let stab = stability::lookup(tcx, ecx.tcx.map.local_def_id(item.id)); match item.node { hir::ItemStatic(_, m, _) => { @@ -1072,7 +1077,7 @@ fn encode_info_for_item(ecx: &EncodeContext, // Encode all the items in this module. for foreign_item in &fm.items { rbml_w.wr_tagged_u64(tag_mod_child, - def_to_u64(DefId::local(foreign_item.id))); + def_to_u64(ecx.tcx.map.local_def_id(foreign_item.id))); } encode_visibility(rbml_w, vis); encode_stability(rbml_w, stab); @@ -1102,7 +1107,7 @@ fn encode_info_for_item(ecx: &EncodeContext, encode_attributes(rbml_w, &item.attrs); encode_repr_attrs(rbml_w, ecx, &item.attrs); for v in &enum_definition.variants { - encode_variant_id(rbml_w, DefId::local(v.node.id)); + encode_variant_id(rbml_w, ecx.tcx.map.local_def_id(v.node.id)); } encode_inlined_item(ecx, rbml_w, InlinedItemRef::Item(item)); encode_path(rbml_w, path); @@ -1174,7 +1179,7 @@ fn encode_info_for_item(ecx: &EncodeContext, encode_name(rbml_w, item.name); encode_unsafety(rbml_w, unsafety); - let trait_ref = tcx.impl_trait_ref(DefId::local(item.id)).unwrap(); + let trait_ref = tcx.impl_trait_ref(ecx.tcx.map.local_def_id(item.id)).unwrap(); encode_trait_ref(rbml_w, ecx, trait_ref, tag_item_trait_ref); rbml_w.end_tag(); } @@ -1194,7 +1199,7 @@ fn encode_info_for_item(ecx: &EncodeContext, encode_unsafety(rbml_w, unsafety); encode_polarity(rbml_w, polarity); - match tcx.custom_coerce_unsized_kinds.borrow().get(&DefId::local(item.id)) { + match tcx.custom_coerce_unsized_kinds.borrow().get(&ecx.tcx.map.local_def_id(item.id)) { Some(&kind) => { rbml_w.start_tag(tag_impl_coerce_unsized_kind); kind.encode(rbml_w); @@ -1228,7 +1233,7 @@ fn encode_info_for_item(ecx: &EncodeContext, } rbml_w.end_tag(); } - if let Some(trait_ref) = tcx.impl_trait_ref(DefId::local(item.id)) { + if let Some(trait_ref) = tcx.impl_trait_ref(ecx.tcx.map.local_def_id(item.id)) { encode_trait_ref(rbml_w, ecx, trait_ref, tag_item_trait_ref); } encode_path(rbml_w, path.clone()); @@ -1472,7 +1477,7 @@ fn encode_info_for_foreign_item(ecx: &EncodeContext, }); rbml_w.start_tag(tag_items_data_item); - encode_def_id(rbml_w, DefId::local(nitem.id)); + encode_def_id(rbml_w, ecx.tcx.map.local_def_id(nitem.id)); encode_visibility(rbml_w, nitem.vis); match nitem.node { hir::ForeignItemFn(ref fndecl, _) => { @@ -1483,7 +1488,7 @@ fn encode_info_for_foreign_item(ecx: &EncodeContext, encode_inlined_item(ecx, rbml_w, InlinedItemRef::Foreign(nitem)); } encode_attributes(rbml_w, &*nitem.attrs); - let stab = stability::lookup(ecx.tcx, DefId::local(nitem.id)); + let stab = stability::lookup(ecx.tcx, ecx.tcx.map.local_def_id(nitem.id)); encode_stability(rbml_w, stab); encode_symbol(ecx, rbml_w, nitem.id); encode_method_argument_names(rbml_w, &*fndecl); @@ -1496,7 +1501,7 @@ fn encode_info_for_foreign_item(ecx: &EncodeContext, } encode_bounds_and_type_for_item(rbml_w, ecx, nitem.id); encode_attributes(rbml_w, &*nitem.attrs); - let stab = stability::lookup(ecx.tcx, DefId::local(nitem.id)); + let stab = stability::lookup(ecx.tcx, ecx.tcx.map.local_def_id(nitem.id)); encode_stability(rbml_w, stab); encode_symbol(ecx, rbml_w, nitem.id); encode_name(rbml_w, nitem.name); @@ -1831,7 +1836,7 @@ impl<'a, 'b, 'c, 'tcx, 'v> Visitor<'v> for ImplVisitor<'a, 'b, 'c, 'tcx> { if Some(def_id) == self.ecx.tcx.lang_items.drop_trait() || def_id.krate != LOCAL_CRATE { self.rbml_w.start_tag(tag_impls_impl); - encode_def_id(self.rbml_w, DefId::local(item.id)); + encode_def_id(self.rbml_w, self.ecx.tcx.map.local_def_id(item.id)); self.rbml_w.wr_tagged_u64(tag_impls_impl_trait_def_id, def_to_u64(def_id)); self.rbml_w.end_tag(); } @@ -1873,11 +1878,11 @@ fn encode_misc_info(ecx: &EncodeContext, rbml_w.start_tag(tag_misc_info_crate_items); for item in &krate.module.items { rbml_w.wr_tagged_u64(tag_mod_child, - def_to_u64(DefId::local(item.id))); + def_to_u64(ecx.tcx.map.local_def_id(item.id))); each_auxiliary_node_id(&**item, |auxiliary_node_id| { rbml_w.wr_tagged_u64(tag_mod_child, - def_to_u64(DefId::local(auxiliary_node_id))); + def_to_u64(ecx.tcx.map.local_def_id(auxiliary_node_id))); true }); } diff --git a/src/librustc/metadata/tydecode.rs b/src/librustc/metadata/tydecode.rs index abc0429e7d2..75afe11839c 100644 --- a/src/librustc/metadata/tydecode.rs +++ b/src/librustc/metadata/tydecode.rs @@ -213,15 +213,14 @@ impl<'a,'tcx> TyDecoder<'a,'tcx> { // by the receiver-matching code in collect, which won't // be going down this code path, and anyway I will kill it // the moment wfcheck becomes the standard. - let node_id = self.parse_uint() as ast::NodeId; - assert_eq!(self.next(), '|'); + let def_id = self.parse_def(NominalType); let space = self.parse_param_space(); assert_eq!(self.next(), '|'); let index = self.parse_u32(); assert_eq!(self.next(), '|'); let name = token::intern(&self.parse_str(']')); ty::ReEarlyBound(ty::EarlyBoundRegion { - param_id: node_id, + param_id: def_id, space: space, index: index, name: name diff --git a/src/librustc/metadata/tyencode.rs b/src/librustc/metadata/tyencode.rs index 3176f5c9cc4..c085f0e5825 100644 --- a/src/librustc/metadata/tyencode.rs +++ b/src/librustc/metadata/tyencode.rs @@ -250,7 +250,7 @@ pub fn enc_region(w: &mut Encoder, cx: &ctxt, r: ty::Region) { } ty::ReEarlyBound(ref data) => { mywrite!(w, "B[{}|{}|{}|{}]", - data.param_id, + (cx.ds)(data.param_id), data.space.to_uint(), data.index, data.name); diff --git a/src/librustc/middle/astencode.rs b/src/librustc/middle/astencode.rs index 96fb649dd45..a137d295bd1 100644 --- a/src/librustc/middle/astencode.rs +++ b/src/librustc/middle/astencode.rs @@ -934,7 +934,7 @@ fn encode_side_tables_for_id(ecx: &e::EncodeContext, rbml_w.tag(c::tag_table_upvar_capture_map, |rbml_w| { rbml_w.id(id); - let var_id = freevar.def.def_id().node; + let var_id = freevar.def.node_id(); let upvar_id = ty::UpvarId { var_id: var_id, closure_expr_id: id @@ -997,14 +997,14 @@ fn encode_side_tables_for_id(ecx: &e::EncodeContext, }) } - if let Some(closure_type) = tcx.tables.borrow().closure_tys.get(&DefId::local(id)) { + if let Some(closure_type) = tcx.tables.borrow().closure_tys.get(&tcx.map.local_def_id(id)) { rbml_w.tag(c::tag_table_closure_tys, |rbml_w| { rbml_w.id(id); rbml_w.emit_closure_type(ecx, closure_type); }) } - if let Some(closure_kind) = tcx.tables.borrow().closure_kinds.get(&DefId::local(id)) { + if let Some(closure_kind) = tcx.tables.borrow().closure_kinds.get(&tcx.map.local_def_id(id)) { rbml_w.tag(c::tag_table_closure_kinds, |rbml_w| { rbml_w.id(id); encode_closure_kind(rbml_w, *closure_kind) @@ -1476,14 +1476,16 @@ fn decode_side_tables(dcx: &DecodeContext, c::tag_table_closure_tys => { let closure_ty = val_dsr.read_closure_ty(dcx); - dcx.tcx.tables.borrow_mut().closure_tys.insert(DefId::local(id), - closure_ty); + dcx.tcx.tables.borrow_mut().closure_tys.insert( + dcx.tcx.map.local_def_id(id), + closure_ty); } c::tag_table_closure_kinds => { let closure_kind = val_dsr.read_closure_kind(dcx); - dcx.tcx.tables.borrow_mut().closure_kinds.insert(DefId::local(id), - closure_kind); + dcx.tcx.tables.borrow_mut().closure_kinds.insert( + dcx.tcx.map.local_def_id(id), + closure_kind); } c::tag_table_cast_kinds => { let cast_kind = diff --git a/src/librustc/middle/dead.rs b/src/librustc/middle/dead.rs index 92592f049e0..86dbbb578ff 100644 --- a/src/librustc/middle/dead.rs +++ b/src/librustc/middle/dead.rs @@ -88,7 +88,7 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> { self.tcx.def_map.borrow().get(id).map(|def| { match def.full_def() { def::DefConst(_) | def::DefAssociatedConst(..) => { - self.check_def_id(def.def_id()) + self.check_def_id(def.def_id()); } _ if self.ignore_non_const_paths => (), def::DefPrimTy(_) => (), @@ -481,7 +481,7 @@ impl<'a, 'tcx> DeadVisitor<'a, 'tcx> { // method of a private type is used, but the type itself is never // called directly. let impl_items = self.tcx.impl_items.borrow(); - match self.tcx.inherent_impls.borrow().get(&DefId::local(id)) { + match self.tcx.inherent_impls.borrow().get(&self.tcx.map.local_def_id(id)) { None => (), Some(impl_list) => { for impl_did in impl_list.iter() { diff --git a/src/librustc/middle/def.rs b/src/librustc/middle/def.rs index abd7ed88275..58d747002c9 100644 --- a/src/librustc/middle/def.rs +++ b/src/librustc/middle/def.rs @@ -10,7 +10,6 @@ pub use self::Def::*; -use metadata::cstore::LOCAL_CRATE; use middle::def_id::DefId; use middle::privacy::LastPrivate; use middle::subst::ParamSpace; @@ -115,10 +114,24 @@ pub struct Export { } impl Def { - pub fn local_node_id(&self) -> ast::NodeId { - let def_id = self.def_id(); - assert_eq!(def_id.krate, LOCAL_CRATE); - def_id.node + pub fn node_id(&self) -> ast::NodeId { + match *self { + DefLocal(id) | + DefUpvar(id, _, _) | + DefRegion(id) | + DefLabel(id) | + DefSelfTy(_, Some((_, id))) => { + id + } + + DefFn(_, _) | DefMod(_) | DefForeignMod(_) | DefStatic(_, _) | + DefVariant(_, _, _) | DefTy(_, _) | DefAssociatedTy(_, _) | + DefTyParam(_, _, _, _) | DefUse(_) | DefStruct(_) | DefTrait(_) | + DefMethod(_) | DefConst(_) | DefAssociatedConst(_) | + DefSelfTy(Some(_), None) | DefPrimTy(_) | DefSelfTy(..) => { + panic!("attempted .def_id() on invalid {:?}", self) + } + } } pub fn def_id(&self) -> DefId { @@ -130,12 +143,13 @@ impl Def { DefSelfTy(Some(id), None)=> { id } + DefLocal(id) | DefUpvar(id, _, _) | DefRegion(id) | DefLabel(id) | DefSelfTy(_, Some((_, id))) => { - DefId::local(id) + DefId::xxx_local(id) // TODO, clearly } DefPrimTy(_) => panic!("attempted .def_id() on DefPrimTy"), diff --git a/src/librustc/middle/def_id.rs b/src/librustc/middle/def_id.rs index 95a593f876f..bbfaffb1112 100644 --- a/src/librustc/middle/def_id.rs +++ b/src/librustc/middle/def_id.rs @@ -41,7 +41,7 @@ impl fmt::Debug for DefId { impl DefId { - pub fn local(id: NodeId) -> DefId { + pub fn xxx_local(id: NodeId) -> DefId { DefId { krate: LOCAL_CRATE, node: id } } diff --git a/src/librustc/middle/expr_use_visitor.rs b/src/librustc/middle/expr_use_visitor.rs index 13e8fddf779..86b321a9455 100644 --- a/src/librustc/middle/expr_use_visitor.rs +++ b/src/librustc/middle/expr_use_visitor.rs @@ -1160,7 +1160,7 @@ impl<'d,'t,'a,'tcx> ExprUseVisitor<'d,'t,'a,'tcx> { self.tcx().with_freevars(closure_expr.id, |freevars| { for freevar in freevars { - let id_var = freevar.def.def_id().node; + let id_var = freevar.def.node_id(); let upvar_id = ty::UpvarId { var_id: id_var, closure_expr_id: closure_expr.id }; let upvar_capture = self.typer.upvar_capture(upvar_id).unwrap(); @@ -1192,7 +1192,7 @@ impl<'d,'t,'a,'tcx> ExprUseVisitor<'d,'t,'a,'tcx> { -> mc::McResult<mc::cmt<'tcx>> { // Create the cmt for the variable being borrowed, from the // caller's perspective - let var_id = upvar_def.def_id().node; + let var_id = upvar_def.node_id(); let var_ty = try!(self.typer.node_ty(var_id)); self.mc.cat_def(closure_id, closure_span, var_ty, upvar_def) } diff --git a/src/librustc/middle/lang_items.rs b/src/librustc/middle/lang_items.rs index 85e51512bca..262c5c1422b 100644 --- a/src/librustc/middle/lang_items.rs +++ b/src/librustc/middle/lang_items.rs @@ -21,6 +21,7 @@ pub use self::LangItem::*; +use front::map as hir_map; use session::Session; use metadata::csearch::each_lang_item; use middle::def_id::DefId; @@ -144,21 +145,23 @@ impl LanguageItems { )* } -struct LanguageItemCollector<'a> { +struct LanguageItemCollector<'a, 'tcx: 'a> { items: LanguageItems, + ast_map: &'a hir_map::Map<'tcx>, + session: &'a Session, item_refs: FnvHashMap<&'static str, usize>, } -impl<'a, 'v> Visitor<'v> for LanguageItemCollector<'a> { +impl<'a, 'v, 'tcx> Visitor<'v> for LanguageItemCollector<'a, 'tcx> { fn visit_item(&mut self, item: &hir::Item) { if let Some(value) = extract(&item.attrs) { let item_index = self.item_refs.get(&value[..]).cloned(); if let Some(item_index) = item_index { - self.collect_item(item_index, DefId::local(item.id), item.span) + self.collect_item(item_index, self.ast_map.local_def_id(item.id), item.span) } } @@ -166,16 +169,18 @@ impl<'a, 'v> Visitor<'v> for LanguageItemCollector<'a> { } } -impl<'a> LanguageItemCollector<'a> { - pub fn new(session: &'a Session) -> LanguageItemCollector<'a> { +impl<'a, 'tcx> LanguageItemCollector<'a, 'tcx> { + pub fn new(session: &'a Session, ast_map: &'a hir_map::Map<'tcx>) + -> LanguageItemCollector<'a, 'tcx> { let mut item_refs = FnvHashMap(); $( item_refs.insert($name, $variant as usize); )* LanguageItemCollector { session: session, + ast_map: ast_map, items: LanguageItems::new(), - item_refs: item_refs + item_refs: item_refs, } } @@ -230,9 +235,11 @@ pub fn extract(attrs: &[ast::Attribute]) -> Option<InternedString> { return None; } -pub fn collect_language_items(krate: &hir::Crate, - session: &Session) -> LanguageItems { - let mut collector = LanguageItemCollector::new(session); +pub fn collect_language_items(session: &Session, + map: &hir_map::Map) + -> LanguageItems { + let krate: &hir::Crate = map.krate(); + let mut collector = LanguageItemCollector::new(session, map); collector.collect(krate); let LanguageItemCollector { mut items, .. } = collector; weak_lang_items::check_crate(krate, session, &mut items); diff --git a/src/librustc/middle/stability.rs b/src/librustc/middle/stability.rs index b9f5ea863ff..b6a4c97b180 100644 --- a/src/librustc/middle/stability.rs +++ b/src/librustc/middle/stability.rs @@ -113,7 +113,8 @@ impl<'a, 'tcx: 'a> Annotator<'a, 'tcx> { "An API can't be stabilized after it is deprecated"); } - self.index.map.insert(DefId::local(id), Some(stab)); + let def_id = self.tcx.map.local_def_id(id); + self.index.map.insert(def_id, Some(stab)); // Don't inherit #[stable(feature = "rust1", since = "1.0.0")] if stab.level != attr::Stable { @@ -129,7 +130,8 @@ impl<'a, 'tcx: 'a> Annotator<'a, 'tcx> { use_parent, self.parent); if use_parent { if let Some(stab) = self.parent { - self.index.map.insert(DefId::local(id), Some(stab)); + let def_id = self.tcx.map.local_def_id(id); + self.index.map.insert(def_id, Some(stab)); } else if self.index.staged_api[&LOCAL_CRATE] && required && self.export_map.contains(&id) && !self.tcx.sess.opts.test { diff --git a/src/librustc/middle/ty/mod.rs b/src/librustc/middle/ty/mod.rs index fdec25a82b1..a48d34281bb 100644 --- a/src/librustc/middle/ty/mod.rs +++ b/src/librustc/middle/ty/mod.rs @@ -618,7 +618,7 @@ pub struct RegionParameterDef { impl RegionParameterDef { pub fn to_early_bound_region(&self) -> ty::Region { ty::ReEarlyBound(ty::EarlyBoundRegion { - param_id: self.def_id.node, + param_id: self.def_id, space: self.space, index: self.index, name: self.name, @@ -1125,7 +1125,7 @@ impl<'a, 'tcx> ParameterEnvironment<'a, 'tcx> { // associated types don't have their own entry (for some reason), // so for now just grab environment for the impl let impl_id = cx.map.get_parent(id); - let impl_def_id = DefId::local(impl_id); + let impl_def_id = cx.map.local_def_id(impl_id); let scheme = cx.lookup_item_type(impl_def_id); let predicates = cx.lookup_predicates(impl_def_id); cx.construct_parameter_environment(impl_item.span, @@ -1134,7 +1134,7 @@ impl<'a, 'tcx> ParameterEnvironment<'a, 'tcx> { id) } hir::ConstImplItem(_, _) => { - let def_id = DefId::local(id); + let def_id = cx.map.local_def_id(id); let scheme = cx.lookup_item_type(def_id); let predicates = cx.lookup_predicates(def_id); cx.construct_parameter_environment(impl_item.span, @@ -1143,7 +1143,7 @@ impl<'a, 'tcx> ParameterEnvironment<'a, 'tcx> { id) } hir::MethodImplItem(_, ref body) => { - let method_def_id = DefId::local(id); + let method_def_id = cx.map.local_def_id(id); match cx.impl_or_trait_item(method_def_id) { MethodTraitItem(ref method_ty) => { let method_generics = &method_ty.generics; @@ -1169,7 +1169,7 @@ impl<'a, 'tcx> ParameterEnvironment<'a, 'tcx> { // associated types don't have their own entry (for some reason), // so for now just grab environment for the trait let trait_id = cx.map.get_parent(id); - let trait_def_id = DefId::local(trait_id); + let trait_def_id = cx.map.local_def_id(trait_id); let trait_def = cx.lookup_trait_def(trait_def_id); let predicates = cx.lookup_predicates(trait_def_id); cx.construct_parameter_environment(trait_item.span, @@ -1178,7 +1178,7 @@ impl<'a, 'tcx> ParameterEnvironment<'a, 'tcx> { id) } hir::ConstTraitItem(..) => { - let def_id = DefId::local(id); + let def_id = cx.map.local_def_id(id); let scheme = cx.lookup_item_type(def_id); let predicates = cx.lookup_predicates(def_id); cx.construct_parameter_environment(trait_item.span, @@ -1191,8 +1191,7 @@ impl<'a, 'tcx> ParameterEnvironment<'a, 'tcx> { // block, unless this is a trait method with // no default, then fallback to the method id. let body_id = body.as_ref().map(|b| b.id).unwrap_or(id); - let method_def_id = DefId::local(id); - + let method_def_id = cx.map.local_def_id(id); match cx.impl_or_trait_item(method_def_id) { MethodTraitItem(ref method_ty) => { let method_generics = &method_ty.generics; @@ -1217,7 +1216,7 @@ impl<'a, 'tcx> ParameterEnvironment<'a, 'tcx> { match item.node { hir::ItemFn(_, _, _, _, _, ref body) => { // We assume this is a function. - let fn_def_id = DefId::local(id); + let fn_def_id = cx.map.local_def_id(id); let fn_scheme = cx.lookup_item_type(fn_def_id); let fn_predicates = cx.lookup_predicates(fn_def_id); @@ -1231,7 +1230,7 @@ impl<'a, 'tcx> ParameterEnvironment<'a, 'tcx> { hir::ItemImpl(..) | hir::ItemConst(..) | hir::ItemStatic(..) => { - let def_id = DefId::local(id); + let def_id = cx.map.local_def_id(id); let scheme = cx.lookup_item_type(def_id); let predicates = cx.lookup_predicates(def_id); cx.construct_parameter_environment(item.span, @@ -1240,7 +1239,7 @@ impl<'a, 'tcx> ParameterEnvironment<'a, 'tcx> { id) } hir::ItemTrait(..) => { - let def_id = DefId::local(id); + let def_id = cx.map.local_def_id(id); let trait_def = cx.lookup_trait_def(def_id); let predicates = cx.lookup_predicates(def_id); cx.construct_parameter_environment(item.span, @@ -2106,7 +2105,7 @@ impl<'tcx> ctxt<'tcx> { if let ItemTrait(_, _, _, ref ms) = self.map.expect_item(id.node).node { ms.iter().filter_map(|ti| { if let hir::MethodTraitItem(_, Some(_)) = ti.node { - match self.impl_or_trait_item(DefId::local(ti.id)) { + match self.impl_or_trait_item(self.map.local_def_id(ti.id)) { MethodTraitItem(m) => Some(m), _ => { self.sess.bug("provided_trait_methods(): \ @@ -2132,7 +2131,7 @@ impl<'tcx> ctxt<'tcx> { ItemTrait(_, _, _, ref tis) => { tis.iter().filter_map(|ti| { if let hir::ConstTraitItem(_, _) = ti.node { - match self.impl_or_trait_item(DefId::local(ti.id)) { + match self.impl_or_trait_item(self.map.local_def_id(ti.id)) { ConstTraitItem(ac) => Some(ac), _ => { self.sess.bug("associated_consts(): \ @@ -2148,7 +2147,7 @@ impl<'tcx> ctxt<'tcx> { ItemImpl(_, _, _, _, _, ref iis) => { iis.iter().filter_map(|ii| { if let hir::ConstImplItem(_, _) = ii.node { - match self.impl_or_trait_item(DefId::local(ii.id)) { + match self.impl_or_trait_item(self.map.local_def_id(ii.id)) { ConstTraitItem(ac) => Some(ac), _ => { self.sess.bug("associated_consts(): \ diff --git a/src/librustc/middle/ty/sty.rs b/src/librustc/middle/ty/sty.rs index 44f97a6b9e3..c553e3ca5b3 100644 --- a/src/librustc/middle/ty/sty.rs +++ b/src/librustc/middle/ty/sty.rs @@ -23,7 +23,7 @@ use std::fmt; use std::ops; use std::mem; use syntax::abi; -use syntax::ast::{self, Name, NodeId}; +use syntax::ast::{self, Name}; use syntax::parse::token::special_idents; use rustc_front::hir; @@ -675,7 +675,7 @@ pub enum Region { #[derive(Copy, Clone, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable, Debug)] pub struct EarlyBoundRegion { - pub param_id: NodeId, + pub param_id: DefId, pub space: subst::ParamSpace, pub index: u32, pub name: Name, diff --git a/src/librustc/util/ppaux.rs b/src/librustc/util/ppaux.rs index 68bfa42f6f6..8daaf1325ea 100644 --- a/src/librustc/util/ppaux.rs +++ b/src/librustc/util/ppaux.rs @@ -232,7 +232,7 @@ fn in_binder<'tcx, T, U>(f: &mut fmt::Formatter, ty::BrEnv => { let name = token::intern("'r"); let _ = write!(f, "{}", name); - ty::BrNamed(DefId::local(DUMMY_NODE_ID), name) + ty::BrNamed(tcx.map.local_def_id(DUMMY_NODE_ID), name) } }) }).0; @@ -466,7 +466,7 @@ impl fmt::Debug for ty::Region { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match *self { ty::ReEarlyBound(ref data) => { - write!(f, "ReEarlyBound({}, {:?}, {}, {})", + write!(f, "ReEarlyBound({:?}, {:?}, {}, {})", data.param_id, data.space, data.index, @@ -896,7 +896,7 @@ impl<'tcx> fmt::Display for ty::TypeVariants<'tcx> { let mut sep = " "; try!(tcx.with_freevars(did.node, |freevars| { for (freevar, upvar_ty) in freevars.iter().zip(&substs.upvar_tys) { - let node_id = freevar.def.local_node_id(); + let node_id = freevar.def.node_id(); try!(write!(f, "{}{}:{}", sep, diff --git a/src/librustc_driver/driver.rs b/src/librustc_driver/driver.rs index ce04a5befd9..d004d557856 100644 --- a/src/librustc_driver/driver.rs +++ b/src/librustc_driver/driver.rs @@ -661,7 +661,7 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: Session, LocalCrateReader::new(&sess, &ast_map).read_crates(krate)); let lang_items = time(time_passes, "language item collection", || - middle::lang_items::collect_language_items(krate, &sess)); + middle::lang_items::collect_language_items(&sess, &ast_map)); let resolve::CrateMap { def_map, diff --git a/src/librustc_driver/test.rs b/src/librustc_driver/test.rs index cf98b1bd8fd..4b3b3a5e848 100644 --- a/src/librustc_driver/test.rs +++ b/src/librustc_driver/test.rs @@ -130,7 +130,7 @@ fn test_env<F>(source_string: &str, let krate = ast_map.krate(); // run just enough stuff to build a tcx: - let lang_items = lang_items::collect_language_items(krate, &sess); + let lang_items = lang_items::collect_language_items(&sess, &ast_map); let resolve::CrateMap { def_map, freevars, .. } = resolve::resolve_crate(&sess, &ast_map, resolve::MakeGlobMap::No); let named_region_map = resolve_lifetime::krate(&sess, krate, &def_map); diff --git a/src/librustc_lint/bad_style.rs b/src/librustc_lint/bad_style.rs index 51b2d58a581..afa736d2220 100644 --- a/src/librustc_lint/bad_style.rs +++ b/src/librustc_lint/bad_style.rs @@ -9,7 +9,6 @@ // except according to those terms. use middle::def; -use middle::def_id::DefId; use middle::ty; use lint::{LateContext, LintContext, LintArray}; use lint::{LintPass, LateLintPass}; @@ -29,7 +28,8 @@ pub enum MethodLateContext { } pub fn method_context(cx: &LateContext, id: ast::NodeId, span: Span) -> MethodLateContext { - match cx.tcx.impl_or_trait_items.borrow().get(&DefId::local(id)) { + let def_id = cx.tcx.map.local_def_id(id); + match cx.tcx.impl_or_trait_items.borrow().get(&def_id) { None => cx.sess().span_bug(span, "missing method descriptor?!"), Some(item) => match item.container() { ty::TraitContainer(..) => MethodLateContext::TraitDefaultImpl, diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs index 90f877b29a1..9d502a31261 100644 --- a/src/librustc_lint/builtin.rs +++ b/src/librustc_lint/builtin.rs @@ -555,7 +555,7 @@ impl LateLintPass for MissingCopyImplementations { if ast_generics.is_parameterized() { return; } - let def = cx.tcx.lookup_adt_def(DefId::local(item.id)); + let def = cx.tcx.lookup_adt_def(cx.tcx.map.local_def_id(item.id)); (def, cx.tcx.mk_struct(def, cx.tcx.mk_substs(Substs::empty()))) } @@ -563,7 +563,7 @@ impl LateLintPass for MissingCopyImplementations { if ast_generics.is_parameterized() { return; } - let def = cx.tcx.lookup_adt_def(DefId::local(item.id)); + let def = cx.tcx.lookup_adt_def(cx.tcx.map.local_def_id(item.id)); (def, cx.tcx.mk_enum(def, cx.tcx.mk_substs(Substs::empty()))) } @@ -764,7 +764,7 @@ impl LateLintPass for UnconditionalRecursion { let method = match fn_kind { FnKind::ItemFn(..) => None, FnKind::Method(..) => { - cx.tcx.impl_or_trait_item(DefId::local(id)).as_opt_method() + cx.tcx.impl_or_trait_item(cx.tcx.map.local_def_id(id)).as_opt_method() } // closures can't recur, so they don't matter. FnKind::Closure => return @@ -877,8 +877,11 @@ impl LateLintPass for UnconditionalRecursion { id: ast::NodeId) -> bool { match tcx.map.get(id) { hir_map::NodeExpr(&hir::Expr { node: hir::ExprCall(ref callee, _), .. }) => { - tcx.def_map.borrow().get(&callee.id) - .map_or(false, |def| def.def_id() == DefId::local(fn_id)) + tcx.def_map + .borrow() + .get(&callee.id) + .map_or(false, + |def| def.def_id() == tcx.map.local_def_id(fn_id)) } _ => false } diff --git a/src/librustc_mir/dump.rs b/src/librustc_mir/dump.rs index 9b3514028af..ebde7e1d097 100644 --- a/src/librustc_mir/dump.rs +++ b/src/librustc_mir/dump.rs @@ -26,7 +26,6 @@ use repr::Mir; use std::fs::File; use tcx::{PatNode, Cx}; -use self::rustc::middle::def_id::DefId; use self::rustc::middle::infer; use self::rustc::middle::region::CodeExtentData; use self::rustc::middle::ty::{self, Ty}; @@ -210,7 +209,7 @@ fn closure_self_ty<'a,'tcx>(tcx: &ty::ctxt<'tcx>, let region = tcx.mk_region(region); - match tcx.closure_kind(DefId::local(closure_expr_id)) { + match tcx.closure_kind(tcx.map.local_def_id(closure_expr_id)) { ty::ClosureKind::FnClosureKind => tcx.mk_ref(region, ty::TypeAndMut { ty: closure_ty, diff --git a/src/librustc_mir/tcx/expr.rs b/src/librustc_mir/tcx/expr.rs index 6c9713b003b..6560f8449c4 100644 --- a/src/librustc_mir/tcx/expr.rs +++ b/src/librustc_mir/tcx/expr.rs @@ -17,7 +17,6 @@ use tcx::block; use tcx::pattern::PatNode; use tcx::rustc::front::map; use tcx::rustc::middle::def; -use tcx::rustc::middle::def_id::DefId; use tcx::rustc::middle::region::CodeExtent; use tcx::rustc::middle::pat_util; use tcx::rustc::middle::ty::{self, Ty}; @@ -612,7 +611,7 @@ fn convert_var<'a,'tcx:'a>(cx: &mut Cx<'a,'tcx>, let region = cx.tcx.mk_region(region); - let self_expr = match cx.tcx.closure_kind(DefId::local(closure_expr_id)) { + let self_expr = match cx.tcx.closure_kind(cx.tcx.map.local_def_id(closure_expr_id)) { ty::ClosureKind::FnClosureKind => { let ref_closure_ty = cx.tcx.mk_ref(region, diff --git a/src/librustc_privacy/lib.rs b/src/librustc_privacy/lib.rs index 2090527ca20..aa41dccc6dc 100644 --- a/src/librustc_privacy/lib.rs +++ b/src/librustc_privacy/lib.rs @@ -272,7 +272,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for EmbargoVisitor<'a, 'tcx> { } _ => true, }; - let tr = self.tcx.impl_trait_ref(DefId::local(item.id)); + let tr = self.tcx.impl_trait_ref(self.tcx.map.local_def_id(item.id)); let public_trait = tr.clone().map_or(false, |tr| { !tr.def_id.is_local() || self.exported_items.contains(&tr.def_id.node) diff --git a/src/librustc_resolve/build_reduced_graph.rs b/src/librustc_resolve/build_reduced_graph.rs index 8a15eabd614..1f850fc9687 100644 --- a/src/librustc_resolve/build_reduced_graph.rs +++ b/src/librustc_resolve/build_reduced_graph.rs @@ -427,18 +427,20 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> { let name_bindings = self.add_child(name, parent, ForbidDuplicateValues, sp); let mutbl = m == hir::MutMutable; - name_bindings.define_value(DefStatic(DefId::local(item.id), mutbl), sp, modifiers); + name_bindings.define_value(DefStatic(self.ast_map.local_def_id(item.id), mutbl), + sp, + modifiers); parent.clone() } ItemConst(_, _) => { self.add_child(name, parent, ForbidDuplicateValues, sp) - .define_value(DefConst(DefId::local(item.id)), sp, modifiers); + .define_value(DefConst(self.ast_map.local_def_id(item.id)), sp, modifiers); parent.clone() } ItemFn(_, _, _, _, _, _) => { let name_bindings = self.add_child(name, parent, ForbidDuplicateValues, sp); - let def = DefFn(DefId::local(item.id), false); + let def = DefFn(self.ast_map.local_def_id(item.id), false); name_bindings.define_value(def, sp, modifiers); parent.clone() } @@ -448,12 +450,12 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> { let name_bindings = self.add_child(name, parent, ForbidDuplicateTypesAndModules, sp); - name_bindings.define_type(DefTy(DefId::local(item.id), false), sp, + name_bindings.define_type(DefTy(self.ast_map.local_def_id(item.id), false), sp, modifiers); let parent_link = self.get_parent_link(parent, name); name_bindings.set_module_kind(parent_link, - Some(DefId::local(item.id)), + Some(self.ast_map.local_def_id(item.id)), TypeModuleKind, false, is_public, @@ -465,11 +467,13 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> { let name_bindings = self.add_child(name, parent, ForbidDuplicateTypesAndModules, sp); - name_bindings.define_type(DefTy(DefId::local(item.id), true), sp, modifiers); + name_bindings.define_type(DefTy(self.ast_map.local_def_id(item.id), true), + sp, + modifiers); let parent_link = self.get_parent_link(parent, name); name_bindings.set_module_kind(parent_link, - Some(DefId::local(item.id)), + Some(self.ast_map.local_def_id(item.id)), EnumModuleKind, false, is_public, @@ -478,9 +482,10 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> { let module = name_bindings.get_module(); for variant in &(*enum_definition).variants { + let item_def_id = self.ast_map.local_def_id(item.id); self.build_reduced_graph_for_variant( &**variant, - DefId::local(item.id), + item_def_id, &module); } parent.clone() @@ -497,12 +502,16 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> { let name_bindings = self.add_child(name, parent, forbid, sp); // Define a name in the type namespace. - name_bindings.define_type(DefTy(DefId::local(item.id), false), sp, modifiers); + name_bindings.define_type(DefTy(self.ast_map.local_def_id(item.id), false), + sp, + modifiers); // If this is a newtype or unit-like struct, define a name // in the value namespace as well if let Some(cid) = ctor_id { - name_bindings.define_value(DefStruct(DefId::local(cid)), sp, modifiers); + name_bindings.define_value(DefStruct(self.ast_map.local_def_id(cid)), + sp, + modifiers); } // Record the def ID and fields of this struct. @@ -512,7 +521,8 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> { UnnamedField(_) => None } }).collect(); - self.structs.insert(DefId::local(item.id), named_fields); + let item_def_id = self.ast_map.local_def_id(item.id); + self.structs.insert(item_def_id, named_fields); parent.clone() } @@ -527,14 +537,14 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> { // Add all the items within to a new module. let parent_link = self.get_parent_link(parent, name); name_bindings.define_module(parent_link, - Some(DefId::local(item.id)), + Some(self.ast_map.local_def_id(item.id)), TraitModuleKind, false, is_public, sp); let module_parent = name_bindings.get_module(); - let def_id = DefId::local(item.id); + let def_id = self.ast_map.local_def_id(item.id); // Add the names of all the items to the trait info. for trait_item in items { @@ -545,25 +555,25 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> { match trait_item.node { hir::ConstTraitItem(..) => { - let def = DefAssociatedConst(DefId::local(trait_item.id)); + let def = DefAssociatedConst(self.ast_map.local_def_id(trait_item.id)); // NB: not DefModifiers::IMPORTABLE name_bindings.define_value(def, trait_item.span, DefModifiers::PUBLIC); } hir::MethodTraitItem(..) => { - let def = DefMethod(DefId::local(trait_item.id)); + let def = DefMethod(self.ast_map.local_def_id(trait_item.id)); // NB: not DefModifiers::IMPORTABLE name_bindings.define_value(def, trait_item.span, DefModifiers::PUBLIC); } hir::TypeTraitItem(..) => { - let def = DefAssociatedTy(DefId::local(item.id), - DefId::local(trait_item.id)); + let def = DefAssociatedTy(self.ast_map.local_def_id(item.id), + self.ast_map.local_def_id(trait_item.id)); // NB: not DefModifiers::IMPORTABLE name_bindings.define_type(def, trait_item.span, DefModifiers::PUBLIC); } } - self.trait_item_map.insert((trait_item.name, def_id), - DefId::local(trait_item.id)); + let trait_item_def_id = self.ast_map.local_def_id(trait_item.id); + self.trait_item_map.insert((trait_item.name, def_id), trait_item_def_id); } name_bindings.define_type(DefTrait(def_id), sp, modifiers); @@ -583,7 +593,8 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> { TupleVariantKind(_) => false, StructVariantKind(_) => { // Not adding fields for variants as they are not accessed with a self receiver - self.structs.insert(DefId::local(variant.node.id), Vec::new()); + let variant_def_id = self.ast_map.local_def_id(variant.node.id); + self.structs.insert(variant_def_id, Vec::new()); true } }; @@ -594,10 +605,10 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> { // variants are always treated as importable to allow them to be glob // used child.define_value(DefVariant(item_id, - DefId::local(variant.node.id), is_exported), + self.ast_map.local_def_id(variant.node.id), is_exported), variant.span, DefModifiers::PUBLIC | DefModifiers::IMPORTABLE); child.define_type(DefVariant(item_id, - DefId::local(variant.node.id), is_exported), + self.ast_map.local_def_id(variant.node.id), is_exported), variant.span, DefModifiers::PUBLIC | DefModifiers::IMPORTABLE); } @@ -618,10 +629,10 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> { let def = match foreign_item.node { ForeignItemFn(..) => { - DefFn(DefId::local(foreign_item.id), false) + DefFn(self.ast_map.local_def_id(foreign_item.id), false) } ForeignItemStatic(_, m) => { - DefStatic(DefId::local(foreign_item.id), m) + DefStatic(self.ast_map.local_def_id(foreign_item.id), m) } }; name_bindings.define_value(def, foreign_item.span, modifiers); diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index 4f6b3f9353a..4497bfb3898 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -2156,7 +2156,8 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { TypeSpace, ItemRibKind), |this| { - this.with_self_rib(DefSelfTy(Some(DefId::local(item.id)), None), |this| { + let local_def_id = this.ast_map.local_def_id(item.id); + this.with_self_rib(DefSelfTy(Some(local_def_id), None), |this| { this.visit_generics(generics); walk_list!(this, visit_ty_param_bound, bounds); @@ -2280,7 +2281,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { function_type_rib.bindings.insert(name, DlDef(DefTyParam(space, index as u32, - DefId::local(type_parameter.id), + self.ast_map.local_def_id(type_parameter.id), name))); } self.type_ribs.push(function_type_rib); diff --git a/src/librustc_trans/save/mod.rs b/src/librustc_trans/save/mod.rs index 61d8a2191a7..c2ec4456e11 100644 --- a/src/librustc_trans/save/mod.rs +++ b/src/librustc_trans/save/mod.rs @@ -349,7 +349,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> { pub fn get_method_data(&self, id: ast::NodeId, name: ast::Name, span: Span) -> FunctionData { // The qualname for a method is the trait name or name of the struct in an impl in // which the method is declared in, followed by the method's name. - let qualname = match self.tcx.impl_of_method(DefId::local(id)) { + let qualname = match self.tcx.impl_of_method(self.tcx.map.local_def_id(id)) { Some(impl_id) => match self.tcx.map.get(impl_id.node) { NodeItem(item) => { match item.node { @@ -357,7 +357,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> { let mut result = String::from("<"); result.push_str(&rustc_front::print::pprust::ty_to_string(&**ty)); - match self.tcx.trait_of_item(DefId::local(id)) { + match self.tcx.trait_of_item(self.tcx.map.local_def_id(id)) { Some(def_id) => { result.push_str(" as "); result.push_str( @@ -381,7 +381,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> { impl_id.node, id, self.tcx.map.get(impl_id.node))); } }, - None => match self.tcx.trait_of_item(DefId::local(id)) { + None => match self.tcx.trait_of_item(self.tcx.map.local_def_id(id)) { Some(def_id) => { match self.tcx.map.get(def_id.node) { NodeItem(_) => { @@ -403,11 +403,13 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> { let qualname = format!("{}::{}", qualname, name); - let decl_id = self.tcx.trait_item_of_item(DefId::local(id)) + let def_id = self.tcx.map.local_def_id(id); + let decl_id = + self.tcx.trait_item_of_item(def_id) .and_then(|new_id| { - let def_id = new_id.def_id(); - if def_id.node != 0 && def_id != DefId::local(id) { - Some(def_id) + let new_def_id = new_id.def_id(); + if new_def_id.node != 0 && new_def_id != def_id { + Some(new_def_id) } else { None } diff --git a/src/librustc_trans/trans/base.rs b/src/librustc_trans/trans/base.rs index 8ec2a83ce90..8a0578332e6 100644 --- a/src/librustc_trans/trans/base.rs +++ b/src/librustc_trans/trans/base.rs @@ -2086,7 +2086,8 @@ pub fn trans_item(ccx: &CrateContext, item: &hir::Item) { // error in trans. This is used to write compile-fail tests // that actually test that compilation succeeds without // reporting an error. - if ccx.tcx().has_attr(DefId::local(item.id), "rustc_error") { + let item_def_id = ccx.tcx().map.local_def_id(item.id); + if ccx.tcx().has_attr(item_def_id, "rustc_error") { ccx.tcx().sess.span_fatal(item.span, "compilation successful"); } } diff --git a/src/librustc_trans/trans/closure.rs b/src/librustc_trans/trans/closure.rs index dc9ea62e9d1..d992f6eeab1 100644 --- a/src/librustc_trans/trans/closure.rs +++ b/src/librustc_trans/trans/closure.rs @@ -43,7 +43,7 @@ fn load_closure_environment<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, let _icx = push_ctxt("closure::load_closure_environment"); // Special case for small by-value selfs. - let closure_id = DefId::local(bcx.fcx.id); + let closure_id = bcx.tcx().map.local_def_id(bcx.fcx.id); let self_type = self_type_for_closure(bcx.ccx(), closure_id, node_id_type(bcx, closure_id.node)); let kind = kind_for_closure(bcx.ccx(), closure_id); @@ -69,7 +69,7 @@ fn load_closure_environment<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, }; for (i, freevar) in freevars.iter().enumerate() { - let upvar_id = ty::UpvarId { var_id: freevar.def.local_node_id(), + let upvar_id = ty::UpvarId { var_id: freevar.def.node_id(), closure_expr_id: closure_id.node }; let upvar_capture = bcx.tcx().upvar_capture(upvar_id).unwrap(); let mut upvar_ptr = StructGEP(bcx, llenv, i); @@ -190,7 +190,7 @@ pub fn trans_closure_expr<'a, 'tcx>(dest: Dest<'a, 'tcx>, debug!("trans_closure_expr()"); - let closure_id = DefId::local(id); + let closure_id = tcx.map.local_def_id(id); let llfn = get_or_create_closure_declaration(ccx, closure_id, closure_substs); // Get the type of this closure. Use the current `param_substs` as @@ -235,7 +235,7 @@ pub fn trans_closure_expr<'a, 'tcx>(dest: Dest<'a, 'tcx>, for (i, freevar) in freevars.iter().enumerate() { let datum = expr::trans_local_var(bcx, freevar.def); let upvar_slot_dest = adt::trans_field_ptr(bcx, &*repr, dest_addr, 0, i); - let upvar_id = ty::UpvarId { var_id: freevar.def.local_node_id(), + let upvar_id = ty::UpvarId { var_id: freevar.def.node_id(), closure_expr_id: id }; match tcx.upvar_capture(upvar_id).unwrap() { ty::UpvarCapture::ByValue => { diff --git a/src/librustc_trans/trans/common.rs b/src/librustc_trans/trans/common.rs index 78f631371c0..ba50bec2ecd 100644 --- a/src/librustc_trans/trans/common.rs +++ b/src/librustc_trans/trans/common.rs @@ -1145,8 +1145,9 @@ pub fn inlined_variant_def<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, }), ..}) => ty, _ => ctor_ty }.ty_adt_def().unwrap(); + let inlined_vid_def_id = ccx.tcx().map.local_def_id(inlined_vid); adt_def.variants.iter().find(|v| { - DefId::local(inlined_vid) == v.did || + inlined_vid_def_id == v.did || ccx.external().borrow().get(&v.did) == Some(&Some(inlined_vid)) }).unwrap_or_else(|| { ccx.sess().bug(&format!("no variant for {:?}::{}", adt_def, inlined_vid)) diff --git a/src/librustc_trans/trans/debuginfo/metadata.rs b/src/librustc_trans/trans/debuginfo/metadata.rs index 1d35b51a5f8..75dc67bd9b0 100644 --- a/src/librustc_trans/trans/debuginfo/metadata.rs +++ b/src/librustc_trans/trans/debuginfo/metadata.rs @@ -1887,7 +1887,8 @@ pub fn create_global_var_metadata(cx: &CrateContext, let is_local_to_unit = is_node_local_to_unit(cx, node_id); let variable_type = cx.tcx().node_id_to_type(node_id); let type_metadata = type_metadata(cx, variable_type, span); - let namespace_node = namespace_for_item(cx, DefId::local(node_id)); + let node_def_id = cx.tcx().map.local_def_id(node_id); + let namespace_node = namespace_for_item(cx, node_def_id); let var_name = name.to_string(); let linkage_name = namespace_node.mangled_name_of_contained_item(&var_name[..]); diff --git a/src/librustc_trans/trans/debuginfo/mod.rs b/src/librustc_trans/trans/debuginfo/mod.rs index ebd2b7ea418..a08f33c8899 100644 --- a/src/librustc_trans/trans/debuginfo/mod.rs +++ b/src/librustc_trans/trans/debuginfo/mod.rs @@ -351,7 +351,8 @@ pub fn create_function_debug_context<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, // somehow (storing a path in the hir_map, or construct a path using the // enclosing function). let (linkage_name, containing_scope) = if has_path { - let namespace_node = namespace_for_item(cx, DefId::local(fn_ast_id)); + let fn_ast_def_id = cx.tcx().map.local_def_id(fn_ast_id); + let namespace_node = namespace_for_item(cx, fn_ast_def_id); let linkage_name = namespace_node.mangled_name_of_contained_item( &function_name[..]); let containing_scope = namespace_node.scope; diff --git a/src/librustc_trans/trans/inline.rs b/src/librustc_trans/trans/inline.rs index 22d624be6fc..bf5f20d72e3 100644 --- a/src/librustc_trans/trans/inline.rs +++ b/src/librustc_trans/trans/inline.rs @@ -30,7 +30,8 @@ fn instantiate_inline(ccx: &CrateContext, fn_id: DefId) // Already inline debug!("instantiate_inline({}): already inline as node id {}", ccx.tcx().item_path_str(fn_id), node_id); - return Some(DefId::local(node_id)); + let node_def_id = ccx.tcx().map.local_def_id(node_id); + return Some(node_def_id); } Some(&None) => { return None; // Not inlinable @@ -144,8 +145,9 @@ fn instantiate_inline(ccx: &CrateContext, fn_id: DefId) // reuse that code, it needs to be able to look up the traits for // inlined items. let ty_trait_item = ccx.tcx().impl_or_trait_item(fn_id).clone(); + let trait_item_def_id = ccx.tcx().map.local_def_id(trait_item.id); ccx.tcx().impl_or_trait_items.borrow_mut() - .insert(DefId::local(trait_item.id), ty_trait_item); + .insert(trait_item_def_id, ty_trait_item); // If this is a default method, we can't look up the // impl type. But we aren't going to translate anyways, so @@ -185,7 +187,8 @@ fn instantiate_inline(ccx: &CrateContext, fn_id: DefId) } }; - Some(DefId::local(inline_id)) + let inline_def_id = ccx.tcx().map.local_def_id(inline_id); + Some(inline_def_id) } pub fn get_local_instance(ccx: &CrateContext, fn_id: DefId) diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index 846ddf2f26a..c424245facc 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -168,12 +168,13 @@ pub fn ast_region_to_region(tcx: &ty::ctxt, lifetime: &hir::Lifetime) } Some(&rl::DefLateBoundRegion(debruijn, id)) => { - ty::ReLateBound(debruijn, ty::BrNamed(DefId::local(id), lifetime.name)) + ty::ReLateBound(debruijn, ty::BrNamed(tcx.map.local_def_id(id), lifetime.name)) } Some(&rl::DefEarlyBoundRegion(space, index, id)) => { + let def_id = tcx.map.local_def_id(id); ty::ReEarlyBound(ty::EarlyBoundRegion { - param_id: id, + param_id: def_id, space: space, index: index, name: lifetime.name @@ -183,7 +184,7 @@ pub fn ast_region_to_region(tcx: &ty::ctxt, lifetime: &hir::Lifetime) Some(&rl::DefFreeRegion(scope, id)) => { ty::ReFree(ty::FreeRegion { scope: tcx.region_maps.item_extent(scope.node_id), - bound_region: ty::BrNamed(DefId::local(id), + bound_region: ty::BrNamed(tcx.map.local_def_id(id), lifetime.name) }) } @@ -1264,7 +1265,7 @@ fn associated_path_def_to_ty<'tcx>(this: &AstConv<'tcx>, (_, def::DefSelfTy(Some(trait_did), Some((impl_id, _)))) => { // `Self` in an impl of a trait - we have a concrete self type and a // trait reference. - let trait_ref = tcx.impl_trait_ref(DefId::local(impl_id)).unwrap(); + let trait_ref = tcx.impl_trait_ref(tcx.map.local_def_id(impl_id)).unwrap(); let trait_ref = if let Some(free_substs) = this.get_free_substs() { trait_ref.subst(tcx, free_substs) } else { @@ -1333,7 +1334,7 @@ fn associated_path_def_to_ty<'tcx>(this: &AstConv<'tcx>, let item = trait_items.iter() .find(|i| i.name == assoc_name) .expect("missing associated type"); - DefId::local(item.id) + tcx.map.local_def_id(item.id) } _ => unreachable!() } @@ -1639,7 +1640,7 @@ pub fn ast_ty_to_ty<'tcx>(this: &AstConv<'tcx>, } else if let Some(hir::QSelf { position: 0, .. }) = *maybe_qself { // Create some fake resolution that can't possibly be a type. def::PathResolution { - base_def: def::DefMod(DefId::local(ast::CRATE_NODE_ID)), + base_def: def::DefMod(tcx.map.local_def_id(ast::CRATE_NODE_ID)), last_private: LastMod(AllPublic), depth: path.segments.len() } diff --git a/src/librustc_typeck/check/_match.rs b/src/librustc_typeck/check/_match.rs index 546e337d746..8bcff225755 100644 --- a/src/librustc_typeck/check/_match.rs +++ b/src/librustc_typeck/check/_match.rs @@ -9,7 +9,6 @@ // except according to those terms. use middle::def; -use middle::def_id::DefId; use middle::infer; use middle::pat_util::{PatIdMap, pat_id_map, pat_is_binding}; use middle::pat_util::pat_is_resolved_const; @@ -202,9 +201,10 @@ pub fn check_pat<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>, let path_res = if let Some(&d) = tcx.def_map.borrow().get(&pat.id) { d } else if qself.position == 0 { + // This is just a sentinel for finish_resolving_def_to_ty. + let sentinel = fcx.tcx().map.local_def_id(ast::CRATE_NODE_ID); def::PathResolution { - // This is just a sentinel for finish_resolving_def_to_ty. - base_def: def::DefMod(DefId::local(ast::CRATE_NODE_ID)), + base_def: def::DefMod(sentinel), last_private: LastMod(AllPublic), depth: path.segments.len() } diff --git a/src/librustc_typeck/check/closure.rs b/src/librustc_typeck/check/closure.rs index 82c898214c5..4f7a6395395 100644 --- a/src/librustc_typeck/check/closure.rs +++ b/src/librustc_typeck/check/closure.rs @@ -13,7 +13,6 @@ use super::{check_fn, Expectation, FnCtxt}; use astconv; -use middle::def_id::DefId; use middle::subst; use middle::ty::{self, ToPolyTraitRef, Ty}; use std::cmp; @@ -46,7 +45,7 @@ fn check_closure<'a,'tcx>(fcx: &FnCtxt<'a,'tcx>, decl: &'tcx hir::FnDecl, body: &'tcx hir::Block, expected_sig: Option<ty::FnSig<'tcx>>) { - let expr_def_id = DefId::local(expr.id); + let expr_def_id = fcx.tcx().map.local_def_id(expr.id); debug!("check_closure opt_kind={:?} expected_sig={:?}", opt_kind, diff --git a/src/librustc_typeck/check/intrinsic.rs b/src/librustc_typeck/check/intrinsic.rs index 8a114473e3c..4afc610f63e 100644 --- a/src/librustc_typeck/check/intrinsic.rs +++ b/src/librustc_typeck/check/intrinsic.rs @@ -13,7 +13,6 @@ use astconv::AstConv; use intrinsics; -use middle::def_id::DefId; use middle::subst; use middle::ty::FnSig; use middle::ty::{self, Ty}; @@ -43,7 +42,7 @@ fn equate_intrinsic_type<'a, 'tcx>(tcx: &ty::ctxt<'tcx>, it: &hir::ForeignItem, variadic: false, }), })); - let i_ty = tcx.lookup_item_type(DefId::local(it.id)); + let i_ty = tcx.lookup_item_type(tcx.map.local_def_id(it.id)); let i_n_tps = i_ty.generics.types.len(subst::FnSpace); if i_n_tps != n_tps { span_err!(tcx.sess, it.span, E0094, @@ -365,7 +364,7 @@ pub fn check_platform_intrinsic_type(ccx: &CrateCtxt, }; let tcx = ccx.tcx; - let i_ty = tcx.lookup_item_type(DefId::local(it.id)); + let i_ty = tcx.lookup_item_type(tcx.map.local_def_id(it.id)); let i_n_tps = i_ty.generics.types.len(subst::FnSpace); let name = it.name.as_str(); diff --git a/src/librustc_typeck/check/method/suggest.rs b/src/librustc_typeck/check/method/suggest.rs index 821615d0341..caa6b226d1b 100644 --- a/src/librustc_typeck/check/method/suggest.rs +++ b/src/librustc_typeck/check/method/suggest.rs @@ -15,6 +15,7 @@ use CrateCtxt; use astconv::AstConv; use check::{self, FnCtxt}; +use front::map as hir_map; use middle::ty::{self, Ty, ToPolyTraitRef, ToPredicate, HasTypeFlags}; use middle::def; use middle::def_id::DefId; @@ -385,14 +386,16 @@ pub fn all_traits<'a>(ccx: &'a CrateCtxt) -> AllTraits<'a> { // Crate-local: // // meh. - struct Visitor<'a> { + struct Visitor<'a, 'tcx:'a> { + map: &'a hir_map::Map<'tcx>, traits: &'a mut AllTraitsVec, } - impl<'v, 'a> visit::Visitor<'v> for Visitor<'a> { + impl<'v, 'a, 'tcx> visit::Visitor<'v> for Visitor<'a, 'tcx> { fn visit_item(&mut self, i: &'v hir::Item) { match i.node { hir::ItemTrait(..) => { - self.traits.push(TraitInfo::new(DefId::local(i.id))); + let def_id = self.map.local_def_id(i.id); + self.traits.push(TraitInfo::new(def_id)); } _ => {} } @@ -400,6 +403,7 @@ pub fn all_traits<'a>(ccx: &'a CrateCtxt) -> AllTraits<'a> { } } visit::walk_crate(&mut Visitor { + map: &ccx.tcx.map, traits: &mut traits }, ccx.tcx.map.krate()); diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 59da69d3696..7f4b1095cb5 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -688,7 +688,7 @@ pub fn check_struct(ccx: &CrateCtxt, id: ast::NodeId, span: Span) { check_representable(tcx, span, id, "struct"); - if tcx.lookup_simd(DefId::local(id)) { + if tcx.lookup_simd(ccx.tcx.map.local_def_id(id)) { check_simd(tcx, span, id); } } @@ -696,7 +696,7 @@ pub fn check_struct(ccx: &CrateCtxt, id: ast::NodeId, span: Span) { pub fn check_item_type<'a,'tcx>(ccx: &CrateCtxt<'a,'tcx>, it: &'tcx hir::Item) { debug!("check_item_type(it.id={}, it.name={})", it.id, - ccx.tcx.item_path_str(DefId::local(it.id))); + ccx.tcx.item_path_str(ccx.tcx.map.local_def_id(it.id))); let _indenter = indenter(); match it.node { // Consts can play a role in type-checking, so they are included here. @@ -711,7 +711,7 @@ pub fn check_item_type<'a,'tcx>(ccx: &CrateCtxt<'a,'tcx>, it: &'tcx hir::Item) { hir::ItemFn(..) => {} // entirely within check_item_body hir::ItemImpl(_, _, _, _, _, ref impl_items) => { debug!("ItemImpl {} with id {}", it.name, it.id); - match ccx.tcx.impl_trait_ref(DefId::local(it.id)) { + match ccx.tcx.impl_trait_ref(ccx.tcx.map.local_def_id(it.id)) { Some(impl_trait_ref) => { check_impl_items_against_trait(ccx, it.span, @@ -742,7 +742,7 @@ pub fn check_item_type<'a,'tcx>(ccx: &CrateCtxt<'a,'tcx>, it: &'tcx hir::Item) { } } else { for item in &m.items { - let pty = ccx.tcx.lookup_item_type(DefId::local(item.id)); + let pty = ccx.tcx.lookup_item_type(ccx.tcx.map.local_def_id(item.id)); if !pty.generics.types.is_empty() { span_err!(ccx.tcx.sess, item.span, E0044, "foreign items may not have type parameters"); @@ -764,18 +764,18 @@ pub fn check_item_type<'a,'tcx>(ccx: &CrateCtxt<'a,'tcx>, it: &'tcx hir::Item) { pub fn check_item_body<'a,'tcx>(ccx: &CrateCtxt<'a,'tcx>, it: &'tcx hir::Item) { debug!("check_item_body(it.id={}, it.name={})", it.id, - ccx.tcx.item_path_str(DefId::local(it.id))); + ccx.tcx.item_path_str(ccx.tcx.map.local_def_id(it.id))); let _indenter = indenter(); match it.node { hir::ItemFn(ref decl, _, _, _, _, ref body) => { - let fn_pty = ccx.tcx.lookup_item_type(DefId::local(it.id)); + let fn_pty = ccx.tcx.lookup_item_type(ccx.tcx.map.local_def_id(it.id)); let param_env = ParameterEnvironment::for_item(ccx.tcx, it.id); check_bare_fn(ccx, &**decl, &**body, it.id, it.span, fn_pty.ty, param_env); } hir::ItemImpl(_, _, _, _, _, ref impl_items) => { debug!("ItemImpl {} with id {}", it.name, it.id); - let impl_pty = ccx.tcx.lookup_item_type(DefId::local(it.id)); + let impl_pty = ccx.tcx.lookup_item_type(ccx.tcx.map.local_def_id(it.id)); for impl_item in impl_items { match impl_item.node { @@ -793,7 +793,7 @@ pub fn check_item_body<'a,'tcx>(ccx: &CrateCtxt<'a,'tcx>, it: &'tcx hir::Item) { } } hir::ItemTrait(_, _, _, ref trait_items) => { - let trait_def = ccx.tcx.lookup_trait_def(DefId::local(it.id)); + let trait_def = ccx.tcx.lookup_trait_def(ccx.tcx.map.local_def_id(it.id)); for trait_item in trait_items { match trait_item.node { hir::ConstTraitItem(_, Some(ref expr)) => { @@ -912,7 +912,7 @@ fn check_impl_items_against_trait<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, // Check existing impl methods to see if they are both present in trait // and compatible with trait signature for impl_item in impl_items { - let ty_impl_item = ccx.tcx.impl_or_trait_item(DefId::local(impl_item.id)); + let ty_impl_item = ccx.tcx.impl_or_trait_item(ccx.tcx.map.local_def_id(impl_item.id)); let ty_trait_item = trait_items.iter() .find(|ac| ac.name() == ty_impl_item.name()) .unwrap_or_else(|| { @@ -1954,7 +1954,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { .unwrap_or(type_variable::Default { ty: self.infcx().next_ty_var(), origin_span: codemap::DUMMY_SP, - def_id: DefId::local(0) // what do I put here? + def_id: self.tcx().map.local_def_id(0) // what do I put here? }); // This is to ensure that we elimnate any non-determinism from the error @@ -3357,7 +3357,7 @@ fn check_expr_with_unifier<'a, 'tcx, F>(fcx: &FnCtxt<'a, 'tcx>, } else if let Some(hir::QSelf { position: 0, .. }) = *maybe_qself { // Create some fake resolution that can't possibly be a type. def::PathResolution { - base_def: def::DefMod(DefId::local(ast::CRATE_NODE_ID)), + base_def: def::DefMod(tcx.map.local_def_id(ast::CRATE_NODE_ID)), last_private: LastMod(AllPublic), depth: path.segments.len() } @@ -4109,7 +4109,7 @@ fn check_const<'a,'tcx>(ccx: &CrateCtxt<'a,'tcx>, let inh = static_inherited_fields(ccx, &tables); let rty = ccx.tcx.node_id_to_type(id); let fcx = blank_fn_ctxt(ccx, &inh, ty::FnConverging(rty), e.id); - let declty = fcx.ccx.tcx.lookup_item_type(DefId::local(id)).ty; + let declty = fcx.ccx.tcx.lookup_item_type(ccx.tcx.map.local_def_id(id)).ty; check_const_with_ty(&fcx, sp, e, declty); } @@ -4237,7 +4237,7 @@ pub fn check_enum_variants<'a,'tcx>(ccx: &CrateCtxt<'a,'tcx>, } } - let def_id = DefId::local(id); + let def_id = ccx.tcx.map.local_def_id(id); let variants = &ccx.tcx.lookup_adt_def(def_id).variants; for (v, variant) in vs.iter().zip(variants.iter()) { diff --git a/src/librustc_typeck/check/upvar.rs b/src/librustc_typeck/check/upvar.rs index f9f711a1a63..590b7e50e94 100644 --- a/src/librustc_typeck/check/upvar.rs +++ b/src/librustc_typeck/check/upvar.rs @@ -43,7 +43,6 @@ use super::FnCtxt; use check::demand; -use middle::def_id::DefId; use middle::expr_use_visitor as euv; use middle::mem_categorization as mc; use middle::ty::{self, Ty}; @@ -116,7 +115,7 @@ impl<'a,'tcx> SeedBorrowKind<'a,'tcx> { capture_clause: hir::CaptureClause, _body: &hir::Block) { - let closure_def_id = DefId::local(expr.id); + let closure_def_id = self.tcx().map.local_def_id(expr.id); if !self.fcx.inh.tables.borrow().closure_kinds.contains_key(&closure_def_id) { self.closures_with_inferred_kinds.insert(expr.id); self.fcx.inh.tables.borrow_mut().closure_kinds @@ -127,7 +126,7 @@ impl<'a,'tcx> SeedBorrowKind<'a,'tcx> { self.tcx().with_freevars(expr.id, |freevars| { for freevar in freevars { - let var_node_id = freevar.def.local_node_id(); + let var_node_id = freevar.def.node_id(); let upvar_id = ty::UpvarId { var_id: var_node_id, closure_expr_id: expr.id }; debug!("seed upvar_id {:?}", upvar_id); @@ -215,7 +214,7 @@ impl<'a,'tcx> AdjustBorrowKind<'a,'tcx> { // Now we must process and remove any deferred resolutions, // since we have a concrete closure kind. - let closure_def_id = DefId::local(id); + let closure_def_id = self.fcx.tcx().map.local_def_id(id); if self.closures_with_inferred_kinds.contains(&id) { let mut deferred_call_resolutions = self.fcx.remove_deferred_call_resolutions(closure_def_id); @@ -469,7 +468,7 @@ impl<'a,'tcx> AdjustBorrowKind<'a,'tcx> { return; } - let closure_def_id = DefId::local(closure_id); + let closure_def_id = self.fcx.tcx().map.local_def_id(closure_id); let closure_kinds = &mut self.fcx.inh.tables.borrow_mut().closure_kinds; let existing_kind = *closure_kinds.get(&closure_def_id).unwrap(); diff --git a/src/librustc_typeck/check/wf.rs b/src/librustc_typeck/check/wf.rs index 70983b89ed5..b5cf069bda6 100644 --- a/src/librustc_typeck/check/wf.rs +++ b/src/librustc_typeck/check/wf.rs @@ -12,7 +12,6 @@ use astconv::AstConv; use check::{FnCtxt, Inherited, blank_fn_ctxt, regionck, wfcheck}; use constrained_type_params::{identify_constrained_type_params, Parameter}; use CrateCtxt; -use middle::def_id::DefId; use middle::region; use middle::subst::{self, TypeSpace, FnSpace, ParamSpace, SelfSpace}; use middle::traits; @@ -57,7 +56,7 @@ impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> { let ccx = self.ccx; debug!("check_item_well_formed(it.id={}, it.name={})", item.id, - ccx.tcx.item_path_str(DefId::local(item.id))); + ccx.tcx.item_path_str(ccx.tcx.map.local_def_id(item.id))); match item.node { /// Right now we check that every default trait implementation @@ -81,7 +80,8 @@ impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> { self.check_impl(item); } hir::ItemImpl(_, hir::ImplPolarity::Negative, _, Some(_), _, _) => { - let trait_ref = ccx.tcx.impl_trait_ref(DefId::local(item.id)).unwrap(); + let item_def_id = ccx.tcx.map.local_def_id(item.id); + let trait_ref = ccx.tcx.impl_trait_ref(item_def_id).unwrap(); ccx.tcx.populate_implementations_for_trait_if_necessary(trait_ref.def_id); match ccx.tcx.lang_items.to_builtin_kind(trait_ref.def_id) { Some(ty::BoundSend) | Some(ty::BoundSync) => {} @@ -117,9 +117,9 @@ impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> { } hir::ItemTrait(_, _, _, ref items) => { let trait_predicates = - ccx.tcx.lookup_predicates(DefId::local(item.id)); + ccx.tcx.lookup_predicates(ccx.tcx.map.local_def_id(item.id)); reject_non_type_param_bounds(ccx.tcx, item.span, &trait_predicates); - if ccx.tcx.trait_has_default_impl(DefId::local(item.id)) { + if ccx.tcx.trait_has_default_impl(ccx.tcx.map.local_def_id(item.id)) { if !items.is_empty() { wfcheck::error_380(ccx, item.span); } @@ -133,7 +133,7 @@ impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> { F: for<'fcx> FnMut(&mut CheckTypeWellFormedVisitor<'ccx, 'tcx>, &FnCtxt<'fcx, 'tcx>), { let ccx = self.ccx; - let item_def_id = DefId::local(item.id); + let item_def_id = ccx.tcx.map.local_def_id(item.id); let type_scheme = ccx.tcx.lookup_item_type(item_def_id); let type_predicates = ccx.tcx.lookup_predicates(item_def_id); reject_non_type_param_bounds(ccx.tcx, item.span, &type_predicates); @@ -194,7 +194,8 @@ impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> { Some(&mut this.cache)); debug!("check_item_type at bounds_checker.scope: {:?}", bounds_checker.scope); - let type_scheme = fcx.tcx().lookup_item_type(DefId::local(item.id)); + let item_def_id = fcx.tcx().map.local_def_id(item.id); + let type_scheme = fcx.tcx().lookup_item_type(item_def_id); let item_ty = fcx.instantiate_type_scheme(item.span, &fcx.inh .infcx @@ -230,7 +231,7 @@ impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> { // Similarly, obtain an "inside" reference to the trait // that the impl implements. - let trait_ref = match fcx.tcx().impl_trait_ref(DefId::local(item.id)) { + let trait_ref = match fcx.tcx().impl_trait_ref(fcx.tcx().map.local_def_id(item.id)) { None => { return; } Some(t) => { t } }; @@ -279,7 +280,7 @@ impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> { item: &hir::Item, ast_generics: &hir::Generics) { - let item_def_id = DefId::local(item.id); + let item_def_id = self.tcx().map.local_def_id(item.id); let ty_predicates = self.tcx().lookup_predicates(item_def_id); let variances = self.tcx().item_variances(item_def_id); @@ -431,7 +432,7 @@ impl<'ccx, 'tcx, 'v> Visitor<'v> for CheckTypeWellFormedVisitor<'ccx, 'tcx> { match fk { FnKind::Closure | FnKind::ItemFn(..) => {} FnKind::Method(..) => { - match self.tcx().impl_or_trait_item(DefId::local(id)) { + match self.tcx().impl_or_trait_item(self.tcx().map.local_def_id(id)) { ty::ImplOrTraitItem::MethodTraitItem(ty_method) => { reject_shadowing_type_parameters(self.tcx(), span, &ty_method.generics) } @@ -444,7 +445,7 @@ impl<'ccx, 'tcx, 'v> Visitor<'v> for CheckTypeWellFormedVisitor<'ccx, 'tcx> { fn visit_trait_item(&mut self, trait_item: &'v hir::TraitItem) { if let hir::MethodTraitItem(_, None) = trait_item.node { - match self.tcx().impl_or_trait_item(DefId::local(trait_item.id)) { + match self.tcx().impl_or_trait_item(self.tcx().map.local_def_id(trait_item.id)) { ty::ImplOrTraitItem::MethodTraitItem(ty_method) => { reject_non_type_param_bounds( self.tcx(), diff --git a/src/librustc_typeck/check/wfcheck.rs b/src/librustc_typeck/check/wfcheck.rs index 2c6879891b1..b8d942ad227 100644 --- a/src/librustc_typeck/check/wfcheck.rs +++ b/src/librustc_typeck/check/wfcheck.rs @@ -63,7 +63,7 @@ impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> { let ccx = self.ccx; debug!("check_item_well_formed(it.id={}, it.name={})", item.id, - ccx.tcx.item_path_str(DefId::local(item.id))); + ccx.tcx.item_path_str(ccx.tcx.map.local_def_id(item.id))); match item.node { /// Right now we check that every default trait implementation @@ -90,7 +90,7 @@ impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> { hir::ItemImpl(_, hir::ImplPolarity::Negative, _, Some(_), _, _) => { // FIXME(#27579) what amount of WF checking do we need for neg impls? - let trait_ref = ccx.tcx.impl_trait_ref(DefId::local(item.id)).unwrap(); + let trait_ref = ccx.tcx.impl_trait_ref(ccx.tcx.map.local_def_id(item.id)).unwrap(); ccx.tcx.populate_implementations_for_trait_if_necessary(trait_ref.def_id); match ccx.tcx.lang_items.to_builtin_kind(trait_ref.def_id) { Some(ty::BoundSend) | Some(ty::BoundSync) => {} @@ -137,7 +137,7 @@ impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> { let free_substs = &fcx.inh.infcx.parameter_environment.free_substs; let free_id = fcx.inh.infcx.parameter_environment.free_id; - let item = fcx.tcx().impl_or_trait_item(DefId::local(item_id)); + let item = fcx.tcx().impl_or_trait_item(fcx.tcx().map.local_def_id(item_id)); let mut implied_bounds = match item.container() { ty::TraitContainer(_) => vec![], @@ -216,7 +216,7 @@ impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> { } let free_substs = &fcx.inh.infcx.parameter_environment.free_substs; - let predicates = fcx.tcx().lookup_predicates(DefId::local(item.id)); + let predicates = fcx.tcx().lookup_predicates(fcx.tcx().map.local_def_id(item.id)); let predicates = fcx.instantiate_bounds(item.span, free_substs, &predicates); this.check_where_clauses(fcx, item.span, &predicates); @@ -228,7 +228,7 @@ impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> { item: &hir::Item, items: &[P<hir::TraitItem>]) { - let trait_def_id = DefId::local(item.id); + let trait_def_id = self.tcx().map.local_def_id(item.id); if self.ccx.tcx.trait_has_default_impl(trait_def_id) { if !items.is_empty() { @@ -251,7 +251,7 @@ impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> { { self.with_item_fcx(item, |fcx, this| { let free_substs = &fcx.inh.infcx.parameter_environment.free_substs; - let type_scheme = fcx.tcx().lookup_item_type(DefId::local(item.id)); + let type_scheme = fcx.tcx().lookup_item_type(fcx.tcx().map.local_def_id(item.id)); let item_ty = fcx.instantiate_type_scheme(item.span, free_substs, &type_scheme.ty); let bare_fn_ty = match item_ty.sty { ty::TyBareFn(_, ref bare_fn_ty) => bare_fn_ty, @@ -260,7 +260,7 @@ impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> { } }; - let predicates = fcx.tcx().lookup_predicates(DefId::local(item.id)); + let predicates = fcx.tcx().lookup_predicates(fcx.tcx().map.local_def_id(item.id)); let predicates = fcx.instantiate_bounds(item.span, free_substs, &predicates); let mut implied_bounds = vec![]; @@ -276,7 +276,7 @@ impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> { debug!("check_item_type: {:?}", item); self.with_item_fcx(item, |fcx, this| { - let type_scheme = fcx.tcx().lookup_item_type(DefId::local(item.id)); + let type_scheme = fcx.tcx().lookup_item_type(fcx.tcx().map.local_def_id(item.id)); let item_ty = fcx.instantiate_type_scheme(item.span, &fcx.inh .infcx @@ -299,7 +299,7 @@ impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> { self.with_item_fcx(item, |fcx, this| { let free_substs = &fcx.inh.infcx.parameter_environment.free_substs; - let item_def_id = DefId::local(item.id); + let item_def_id = fcx.tcx().map.local_def_id(item.id); match *ast_trait_ref { Some(ref ast_trait_ref) => { @@ -328,7 +328,7 @@ impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> { let predicates = fcx.instantiate_bounds(item.span, free_substs, &predicates); this.check_where_clauses(fcx, item.span, &predicates); - impl_implied_bounds(fcx, DefId::local(item.id), item.span) + impl_implied_bounds(fcx, fcx.tcx().map.local_def_id(item.id), item.span) }); } @@ -386,7 +386,7 @@ impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> { item: &hir::Item, ast_generics: &hir::Generics) { - let item_def_id = DefId::local(item.id); + let item_def_id = self.tcx().map.local_def_id(item.id); let ty_predicates = self.tcx().lookup_predicates(item_def_id); let variances = self.tcx().item_variances(item_def_id); diff --git a/src/librustc_typeck/coherence/mod.rs b/src/librustc_typeck/coherence/mod.rs index 5c3c95ba4d2..ddb11c910b1 100644 --- a/src/librustc_typeck/coherence/mod.rs +++ b/src/librustc_typeck/coherence/mod.rs @@ -139,7 +139,7 @@ impl<'a, 'tcx> CoherenceChecker<'a, 'tcx> { fn check_implementation(&self, item: &Item) { let tcx = self.crate_context.tcx; - let impl_did = DefId::local(item.id); + let impl_did = tcx.map.local_def_id(item.id); let self_type = tcx.lookup_item_type(impl_did); // If there are no traits, then this implementation must have a @@ -195,15 +195,16 @@ impl<'a, 'tcx> CoherenceChecker<'a, 'tcx> { match item.node { ItemImpl(_, _, _, _, _, ref impl_items) => { impl_items.iter().map(|impl_item| { + let impl_def_id = self.crate_context.tcx.map.local_def_id(impl_item.id); match impl_item.node { hir::ConstImplItem(..) => { - ConstTraitItemId(DefId::local(impl_item.id)) + ConstTraitItemId(impl_def_id) } hir::MethodImplItem(..) => { - MethodTraitItemId(DefId::local(impl_item.id)) + MethodTraitItemId(impl_def_id) } hir::TypeImplItem(_) => { - TypeTraitItemId(DefId::local(impl_item.id)) + TypeTraitItemId(impl_def_id) } } }).collect() diff --git a/src/librustc_typeck/coherence/orphan.rs b/src/librustc_typeck/coherence/orphan.rs index 4f1c958b6dd..f796f7fe9f9 100644 --- a/src/librustc_typeck/coherence/orphan.rs +++ b/src/librustc_typeck/coherence/orphan.rs @@ -64,7 +64,7 @@ impl<'cx, 'tcx> OrphanChecker<'cx, 'tcx> { /// to prevent inundating the user with a bunch of similar error /// reports. fn check_item(&self, item: &hir::Item) { - let def_id = DefId::local(item.id); + let def_id = self.tcx.map.local_def_id(item.id); match item.node { hir::ItemImpl(_, _, _, None, _, _) => { // For inherent impls, self type must be a nominal type diff --git a/src/librustc_typeck/coherence/overlap.rs b/src/librustc_typeck/coherence/overlap.rs index f257dfb62c9..a2c8e8fd131 100644 --- a/src/librustc_typeck/coherence/overlap.rs +++ b/src/librustc_typeck/coherence/overlap.rs @@ -178,20 +178,20 @@ impl<'cx, 'tcx,'v> visit::Visitor<'v> for OverlapChecker<'cx, 'tcx> { // look for another default impl; note that due to the // general orphan/coherence rules, it must always be // in this crate. - let impl_def_id = DefId::local(item.id); + let impl_def_id = self.tcx.map.local_def_id(item.id); let trait_ref = self.tcx.impl_trait_ref(impl_def_id).unwrap(); let prev_default_impl = self.default_impls.insert(trait_ref.def_id, item.id); match prev_default_impl { Some(prev_id) => { self.report_overlap_error(trait_ref.def_id, impl_def_id, - DefId::local(prev_id)); + self.tcx.map.local_def_id(prev_id)); } None => { } } } hir::ItemImpl(_, _, _, Some(_), ref self_ty, _) => { - let impl_def_id = DefId::local(item.id); + let impl_def_id = self.tcx.map.local_def_id(item.id); let trait_ref = self.tcx.impl_trait_ref(impl_def_id).unwrap(); let trait_def_id = trait_ref.def_id; match trait_ref.self_ty().sty { diff --git a/src/librustc_typeck/coherence/unsafety.rs b/src/librustc_typeck/coherence/unsafety.rs index b739709e622..f7b10b90013 100644 --- a/src/librustc_typeck/coherence/unsafety.rs +++ b/src/librustc_typeck/coherence/unsafety.rs @@ -11,7 +11,6 @@ //! Unsafety checker: every impl either implements a trait defined in this //! crate or pertains to a type defined in this crate. -use middle::def_id::DefId; use middle::ty; use rustc_front::visit; use rustc_front::hir; @@ -30,7 +29,7 @@ impl<'cx, 'tcx, 'v> UnsafetyChecker<'cx, 'tcx> { fn check_unsafety_coherence(&mut self, item: &'v hir::Item, unsafety: hir::Unsafety, polarity: hir::ImplPolarity) { - match self.tcx.impl_trait_ref(DefId::local(item.id)) { + match self.tcx.impl_trait_ref(self.tcx.map.local_def_id(item.id)) { None => { // Inherent impl. match unsafety { diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index 5811c3c72f7..e24d3f340b6 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -199,7 +199,7 @@ impl<'a,'tcx> CrateCtxt<'a,'tcx> { } fn method_ty(&self, method_id: ast::NodeId) -> Rc<ty::Method<'tcx>> { - let def_id = DefId::local(method_id); + let def_id = self.tcx.map.local_def_id(method_id); match *self.tcx.impl_or_trait_items.borrow().get(&def_id).unwrap() { ty::MethodTraitItem(ref mty) => mty.clone(), _ => { @@ -562,7 +562,7 @@ fn is_param<'tcx>(tcx: &ty::ctxt<'tcx>, path_res.depth == 0 && def_id.node == param_id } def::DefTyParam(_, _, def_id, _) => { - path_res.depth == 0 && def_id == DefId::local(param_id) + path_res.depth == 0 && def_id == tcx.map.local_def_id(param_id) } _ => { false @@ -592,7 +592,7 @@ fn convert_method<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, astconv::ty_of_method(&ccx.icx(&(rcvr_ty_predicates, &sig.generics)), sig, untransformed_rcvr_ty); - let def_id = DefId::local(id); + let def_id = ccx.tcx.map.local_def_id(id); let ty_method = ty::Method::new(name, ty_generics, ty_generic_predicates, @@ -632,12 +632,12 @@ fn convert_field<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, write_ty_to_tcx(ccx.tcx, v.node.id, tt); /* add the field to the tcache */ - ccx.tcx.register_item_type(DefId::local(v.node.id), + ccx.tcx.register_item_type(ccx.tcx.map.local_def_id(v.node.id), ty::TypeScheme { generics: struct_generics.clone(), ty: tt }); - ccx.tcx.predicates.borrow_mut().insert(DefId::local(v.node.id), + ccx.tcx.predicates.borrow_mut().insert(ccx.tcx.map.local_def_id(v.node.id), struct_predicates.clone()); } @@ -649,7 +649,7 @@ fn convert_associated_const<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, ty: ty::Ty<'tcx>, has_value: bool) { - ccx.tcx.predicates.borrow_mut().insert(DefId::local(id), + ccx.tcx.predicates.borrow_mut().insert(ccx.tcx.map.local_def_id(id), ty::GenericPredicates::empty()); write_ty_to_tcx(ccx.tcx, id, ty); @@ -657,13 +657,13 @@ fn convert_associated_const<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, let associated_const = Rc::new(ty::AssociatedConst { name: name, vis: vis, - def_id: DefId::local(id), + def_id: ccx.tcx.map.local_def_id(id), container: container, ty: ty, has_value: has_value }); ccx.tcx.impl_or_trait_items.borrow_mut() - .insert(DefId::local(id), ty::ConstTraitItem(associated_const)); + .insert(ccx.tcx.map.local_def_id(id), ty::ConstTraitItem(associated_const)); } fn convert_associated_type<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, @@ -677,11 +677,11 @@ fn convert_associated_type<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, name: name, vis: vis, ty: ty, - def_id: DefId::local(id), + def_id: ccx.tcx.map.local_def_id(id), container: container }); ccx.tcx.impl_or_trait_items.borrow_mut() - .insert(DefId::local(id), ty::TypeTraitItem(associated_type)); + .insert(ccx.tcx.map.local_def_id(id), ty::TypeTraitItem(associated_type)); } fn convert_methods<'a,'tcx,'i,I>(ccx: &CrateCtxt<'a, 'tcx>, @@ -752,7 +752,7 @@ fn convert_item(ccx: &CrateCtxt, it: &hir::Item) { let (scheme, predicates) = convert_typed_item(ccx, it); write_ty_to_tcx(tcx, it.id, scheme.ty); convert_enum_variant_types(ccx, - tcx.lookup_adt_def_master(DefId::local(it.id)), + tcx.lookup_adt_def_master(ccx.tcx.map.local_def_id(it.id)), scheme, predicates, &enum_definition.variants); @@ -766,7 +766,8 @@ fn convert_item(ccx: &CrateCtxt, it: &hir::Item) { tcx.record_trait_has_default_impl(trait_ref.def_id); - tcx.impl_trait_refs.borrow_mut().insert(DefId::local(it.id), Some(trait_ref)); + tcx.impl_trait_refs.borrow_mut().insert(ccx.tcx.map.local_def_id(it.id), + Some(trait_ref)); } hir::ItemImpl(_, _, ref generics, @@ -783,21 +784,21 @@ fn convert_item(ccx: &CrateCtxt, it: &hir::Item) { let selfty = ccx.icx(&ty_predicates).to_ty(&ExplicitRscope, &**selfty); write_ty_to_tcx(tcx, it.id, selfty); - tcx.register_item_type(DefId::local(it.id), + tcx.register_item_type(ccx.tcx.map.local_def_id(it.id), TypeScheme { generics: ty_generics.clone(), ty: selfty }); - tcx.predicates.borrow_mut().insert(DefId::local(it.id), + tcx.predicates.borrow_mut().insert(ccx.tcx.map.local_def_id(it.id), ty_predicates.clone()); if let &Some(ref ast_trait_ref) = opt_trait_ref { tcx.impl_trait_refs.borrow_mut().insert( - DefId::local(it.id), + ccx.tcx.map.local_def_id(it.id), Some(astconv::instantiate_mono_trait_ref(&ccx.icx(&ty_predicates), &ExplicitRscope, ast_trait_ref, Some(selfty))) ); } else { - tcx.impl_trait_refs.borrow_mut().insert(DefId::local(it.id), None); + tcx.impl_trait_refs.borrow_mut().insert(ccx.tcx.map.local_def_id(it.id), None); } @@ -839,12 +840,12 @@ fn convert_item(ccx: &CrateCtxt, it: &hir::Item) { if let hir::ConstImplItem(ref ty, _) = impl_item.node { let ty = ccx.icx(&ty_predicates) .to_ty(&ExplicitRscope, &*ty); - tcx.register_item_type(DefId::local(impl_item.id), + tcx.register_item_type(ccx.tcx.map.local_def_id(impl_item.id), TypeScheme { generics: ty_generics.clone(), ty: ty, }); - convert_associated_const(ccx, ImplContainer(DefId::local(it.id)), + convert_associated_const(ccx, ImplContainer(ccx.tcx.map.local_def_id(it.id)), impl_item.name, impl_item.id, impl_item.vis.inherit_from(parent_visibility), ty, true /* has_value */); @@ -861,7 +862,7 @@ fn convert_item(ccx: &CrateCtxt, it: &hir::Item) { let typ = ccx.icx(&ty_predicates).to_ty(&ExplicitRscope, ty); - convert_associated_type(ccx, ImplContainer(DefId::local(it.id)), + convert_associated_type(ccx, ImplContainer(ccx.tcx.map.local_def_id(it.id)), impl_item.name, impl_item.id, impl_item.vis, Some(typ)); } @@ -880,7 +881,7 @@ fn convert_item(ccx: &CrateCtxt, it: &hir::Item) { } }); convert_methods(ccx, - ImplContainer(DefId::local(it.id)), + ImplContainer(ccx.tcx.map.local_def_id(it.id)), methods, selfty, &ty_generics, @@ -900,15 +901,15 @@ fn convert_item(ccx: &CrateCtxt, it: &hir::Item) { enforce_impl_params_are_constrained(tcx, generics, - DefId::local(it.id), + ccx.tcx.map.local_def_id(it.id), impl_items); }, hir::ItemTrait(_, _, _, ref trait_items) => { let trait_def = trait_def_of_item(ccx, it); let _: Result<(), ErrorReported> = // any error is already reported, can ignore - ccx.ensure_super_predicates(it.span, DefId::local(it.id)); + ccx.ensure_super_predicates(it.span, ccx.tcx.map.local_def_id(it.id)); convert_trait_predicates(ccx, it); - let trait_predicates = tcx.lookup_predicates(DefId::local(it.id)); + let trait_predicates = tcx.lookup_predicates(ccx.tcx.map.local_def_id(it.id)); debug!("convert: trait_bounds={:?}", trait_predicates); @@ -918,14 +919,18 @@ fn convert_item(ccx: &CrateCtxt, it: &hir::Item) { hir::ConstTraitItem(ref ty, ref default) => { let ty = ccx.icx(&trait_predicates) .to_ty(&ExplicitRscope, ty); - tcx.register_item_type(DefId::local(trait_item.id), + tcx.register_item_type(ccx.tcx.map.local_def_id(trait_item.id), TypeScheme { generics: trait_def.generics.clone(), ty: ty, }); - convert_associated_const(ccx, TraitContainer(DefId::local(it.id)), - trait_item.name, trait_item.id, - hir::Public, ty, default.is_some()); + convert_associated_const(ccx, + TraitContainer(ccx.tcx.map.local_def_id(it.id)), + trait_item.name, + trait_item.id, + hir::Public, + ty, + default.is_some()) } _ => {} } @@ -939,8 +944,11 @@ fn convert_item(ccx: &CrateCtxt, it: &hir::Item) { |ty| ccx.icx(&trait_predicates).to_ty(&ExplicitRscope, &ty) }); - convert_associated_type(ccx, TraitContainer(DefId::local(it.id)), - trait_item.name, trait_item.id, hir::Public, + convert_associated_type(ccx, + TraitContainer(ccx.tcx.map.local_def_id(it.id)), + trait_item.name, + trait_item.id, + hir::Public, typ); } _ => {} @@ -957,7 +965,7 @@ fn convert_item(ccx: &CrateCtxt, it: &hir::Item) { // Run convert_methods on the trait methods. convert_methods(ccx, - TraitContainer(DefId::local(it.id)), + TraitContainer(ccx.tcx.map.local_def_id(it.id)), methods, tcx.mk_self_type(), &trait_def.generics, @@ -965,7 +973,7 @@ fn convert_item(ccx: &CrateCtxt, it: &hir::Item) { // Add an entry mapping let trait_item_def_ids = Rc::new(trait_items.iter().map(|trait_item| { - let def_id = DefId::local(trait_item.id); + let def_id = ccx.tcx.map.local_def_id(trait_item.id); match trait_item.node { hir::ConstTraitItem(..) => { ty::ConstTraitItemId(def_id) @@ -978,7 +986,8 @@ fn convert_item(ccx: &CrateCtxt, it: &hir::Item) { } } }).collect()); - tcx.trait_item_def_ids.borrow_mut().insert(DefId::local(it.id), trait_item_def_ids); + tcx.trait_item_def_ids.borrow_mut().insert(ccx.tcx.map.local_def_id(it.id), + trait_item_def_ids); // This must be done after `collect_trait_methods` so that // we have a method type stored for every method. @@ -999,7 +1008,8 @@ fn convert_item(ccx: &CrateCtxt, it: &hir::Item) { let (scheme, predicates) = convert_typed_item(ccx, it); write_ty_to_tcx(tcx, it.id, scheme.ty); - let variant = tcx.lookup_adt_def_master(DefId::local(it.id)).struct_variant(); + let it_def_id = ccx.tcx.map.local_def_id(it.id); + let variant = tcx.lookup_adt_def_master(it_def_id).struct_variant(); for (f, ty_f) in struct_def.fields.iter().zip(variant.fields.iter()) { convert_field(ccx, &scheme.generics, &predicates, f, ty_f) @@ -1037,14 +1047,14 @@ fn convert_variant_ctor<'a, 'tcx>(tcx: &ty::ctxt<'tcx>, .iter() .map(|field| field.unsubst_ty()) .collect(); - tcx.mk_ctor_fn(DefId::local(ctor_id), + tcx.mk_ctor_fn(tcx.map.local_def_id(ctor_id), &inputs[..], scheme.ty) } }; write_ty_to_tcx(tcx, ctor_id, ctor_ty); - tcx.predicates.borrow_mut().insert(DefId::local(ctor_id), predicates); - tcx.register_item_type(DefId::local(ctor_id), + tcx.predicates.borrow_mut().insert(tcx.map.local_def_id(ctor_id), predicates); + tcx.register_item_type(tcx.map.local_def_id(ctor_id), TypeScheme { generics: scheme.generics, ty: ctor_ty @@ -1096,7 +1106,7 @@ fn convert_struct_variant<'tcx>(tcx: &ty::ctxt<'tcx>, def: &hir::StructDef) -> ty::VariantDefData<'tcx, 'tcx> { let mut seen_fields: FnvHashMap<ast::Name, Span> = FnvHashMap(); let fields = def.fields.iter().map(|f| { - let fid = DefId::local(f.node.id); + let fid = tcx.map.local_def_id(f.node.id); match f.node.kind { hir::NamedField(name, vis) => { let dup_span = seen_fields.get(&name).cloned(); @@ -1130,7 +1140,7 @@ fn convert_struct_def<'tcx>(tcx: &ty::ctxt<'tcx>, -> ty::AdtDefMaster<'tcx> { - let did = DefId::local(it.id); + let did = tcx.map.local_def_id(it.id); tcx.intern_adt_def( did, ty::AdtKind::Struct, @@ -1207,7 +1217,7 @@ fn convert_enum_def<'tcx>(tcx: &ty::ctxt<'tcx>, disr: ty::Disr) -> ty::VariantDefData<'tcx, 'tcx> { - let did = DefId::local(v.node.id); + let did = tcx.map.local_def_id(v.node.id); let name = v.node.name; match v.node.kind { hir::TupleVariantKind(ref va) => { @@ -1217,7 +1227,7 @@ fn convert_enum_def<'tcx>(tcx: &ty::ctxt<'tcx>, disr_val: disr, fields: va.iter().map(|&hir::VariantArg { id, .. }| { ty::FieldDefData::new( - DefId::local(id), + tcx.map.local_def_id(id), special_idents::unnamed_field.name, hir::Visibility::Public ) @@ -1229,7 +1239,7 @@ fn convert_enum_def<'tcx>(tcx: &ty::ctxt<'tcx>, } } } - let did = DefId::local(it.id); + let did = tcx.map.local_def_id(it.id); let repr_hints = tcx.lookup_repr_hints(did); let (repr_type, repr_type_ty) = tcx.enum_repr_type(repr_hints.get(0)); let mut prev_disr = None; @@ -1243,7 +1253,7 @@ fn convert_enum_def<'tcx>(tcx: &ty::ctxt<'tcx>, prev_disr = Some(disr); v }).collect(); - tcx.intern_adt_def(DefId::local(it.id), ty::AdtKind::Enum, variants) + tcx.intern_adt_def(tcx.map.local_def_id(it.id), ty::AdtKind::Enum, variants) } /// Ensures that the super-predicates of the trait with def-id @@ -1316,7 +1326,7 @@ fn ensure_super_predicates_step(ccx: &CrateCtxt, predicates: VecPerParamSpace::new(superbounds, vec![], vec![]) }; debug!("superpredicates for trait {:?} = {:?}", - DefId::local(item.id), + tcx.map.local_def_id(item.id), superpredicates); tcx.super_predicates.borrow_mut().insert(trait_def_id, superpredicates.clone()); @@ -1339,7 +1349,7 @@ fn trait_def_of_item<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, it: &hir::Item) -> &'tcx ty::TraitDef<'tcx> { - let def_id = DefId::local(it.id); + let def_id = ccx.tcx.map.local_def_id(it.id); let tcx = ccx.tcx; if let Some(def) = tcx.trait_defs.borrow().get(&def_id) { @@ -1402,12 +1412,15 @@ fn trait_def_of_item<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, generics.lifetimes .iter() .enumerate() - .map(|(i, def)| ty::ReEarlyBound(ty::EarlyBoundRegion { - param_id: def.lifetime.id, - space: TypeSpace, - index: i as u32, - name: def.lifetime.name - })) + .map(|(i, def)| { + let def_id = tcx.map.local_def_id(def.lifetime.id); + ty::ReEarlyBound(ty::EarlyBoundRegion { + param_id: def_id, + space: TypeSpace, + index: i as u32, + name: def.lifetime.name + }) + }) .collect(); // Start with the generics in the type parameters... @@ -1453,7 +1466,7 @@ fn convert_trait_predicates<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, it: &hir::Item) let tcx = ccx.tcx; let trait_def = trait_def_of_item(ccx, it); - let def_id = DefId::local(it.id); + let def_id = ccx.tcx.map.local_def_id(it.id); let (generics, items) = match it.node { hir::ItemTrait(_, ref generics, _, ref items) => (generics, items), @@ -1552,7 +1565,7 @@ fn type_scheme_of_item<'a,'tcx>(ccx: &CrateCtxt<'a,'tcx>, -> ty::TypeScheme<'tcx> { memoized(&ccx.tcx.tcache, - DefId::local(it.id), + ccx.tcx.map.local_def_id(it.id), |_| compute_type_scheme_of_item(ccx, it)) } @@ -1569,7 +1582,7 @@ fn compute_type_scheme_of_item<'a,'tcx>(ccx: &CrateCtxt<'a,'tcx>, hir::ItemFn(ref decl, unsafety, _, abi, ref generics, _) => { let ty_generics = ty_generics_for_fn(ccx, generics, &ty::Generics::empty()); let tofd = astconv::ty_of_bare_fn(&ccx.icx(generics), unsafety, abi, &**decl); - let ty = tcx.mk_fn(Some(DefId::local(it.id)), tcx.mk_bare_fn(tofd)); + let ty = tcx.mk_fn(Some(ccx.tcx.map.local_def_id(it.id)), tcx.mk_bare_fn(tofd)); ty::TypeScheme { ty: ty, generics: ty_generics } } hir::ItemTy(ref t, ref generics) => { @@ -1644,12 +1657,12 @@ fn convert_typed_item<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, } }; - let prev_predicates = tcx.predicates.borrow_mut().insert(DefId::local(it.id), + let prev_predicates = tcx.predicates.borrow_mut().insert(ccx.tcx.map.local_def_id(it.id), predicates.clone()); assert!(prev_predicates.is_none()); // Debugging aid. - if tcx.has_attr(DefId::local(it.id), "rustc_object_lifetime_default") { + if tcx.has_attr(ccx.tcx.map.local_def_id(it.id), "rustc_object_lifetime_default") { let object_lifetime_default_reprs: String = scheme.generics.types.iter() .map(|t| match t.object_lifetime_default { @@ -1672,7 +1685,7 @@ fn type_scheme_of_foreign_item<'a, 'tcx>( -> ty::TypeScheme<'tcx> { memoized(&ccx.tcx.tcache, - DefId::local(it.id), + ccx.tcx.map.local_def_id(it.id), |_| compute_type_scheme_of_foreign_item(ccx, it, abi)) } @@ -1717,7 +1730,8 @@ fn convert_foreign_item<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, } }; - let prev_predicates = tcx.predicates.borrow_mut().insert(DefId::local(it.id), predicates); + let prev_predicates = tcx.predicates.borrow_mut().insert(ccx.tcx.map.local_def_id(it.id), + predicates); assert!(prev_predicates.is_none()); } @@ -1741,7 +1755,7 @@ fn ty_generics_for_trait<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, -> ty::Generics<'tcx> { debug!("ty_generics_for_trait(trait_id={:?}, substs={:?})", - DefId::local(trait_id), substs); + ccx.tcx.map.local_def_id(trait_id), substs); let mut generics = ty_generics_for_type_or_impl(ccx, ast_generics); @@ -1757,8 +1771,8 @@ fn ty_generics_for_trait<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, space: SelfSpace, index: 0, name: special_idents::type_self.name, - def_id: DefId::local(param_id), - default_def_id: DefId::local(parent), + def_id: ccx.tcx.map.local_def_id(param_id), + default_def_id: ccx.tcx.map.local_def_id(parent), default: None, object_lifetime_default: ty::ObjectLifetimeDefault::BaseDefault, }; @@ -1877,9 +1891,10 @@ fn ty_generic_predicates<'a,'tcx>(ccx: &CrateCtxt<'a,'tcx>, let early_lifetimes = early_bound_lifetimes_from_generics(space, ast_generics); for (index, param) in early_lifetimes.iter().enumerate() { let index = index as u32; + let def_id = tcx.map.local_def_id(param.lifetime.id); let region = ty::ReEarlyBound(ty::EarlyBoundRegion { - param_id: param.lifetime.id, + param_id: def_id, space: space, index: index, name: param.lifetime.name @@ -1965,7 +1980,7 @@ fn ty_generics<'a,'tcx>(ccx: &CrateCtxt<'a,'tcx>, let def = ty::RegionParameterDef { name: l.lifetime.name, space: space, index: i as u32, - def_id: DefId::local(l.lifetime.id), + def_id: ccx.tcx.map.local_def_id(l.lifetime.id), bounds: bounds }; result.regions.push(space, def); } @@ -2033,8 +2048,8 @@ fn get_or_create_type_parameter_def<'a,'tcx>(ccx: &CrateCtxt<'a,'tcx>, space: space, index: index, name: param.name, - def_id: DefId::local(param.id), - default_def_id: DefId::local(parent), + def_id: ccx.tcx.map.local_def_id(param.id), + default_def_id: ccx.tcx.map.local_def_id(parent), default: default, object_lifetime_default: object_lifetime_default, }; @@ -2377,7 +2392,7 @@ fn check_method_self_type<'a, 'tcx, RS:RegionScope>( tcx.fold_regions(value, &mut false, |region, _| { match region { ty::ReEarlyBound(data) => { - let def_id = DefId::local(data.param_id); + let def_id = data.param_id; ty::ReFree(ty::FreeRegion { scope: scope, bound_region: ty::BrNamed(def_id, data.name) }) } @@ -2424,7 +2439,7 @@ fn enforce_impl_params_are_constrained<'tcx>(tcx: &ty::ctxt<'tcx>, let lifetimes_in_associated_types: HashSet<_> = impl_items.iter() - .map(|item| tcx.impl_or_trait_item(DefId::local(item.id))) + .map(|item| tcx.impl_or_trait_item(tcx.map.local_def_id(item.id))) .filter_map(|item| match item { ty::TypeTraitItem(ref assoc_ty) => assoc_ty.ty, ty::ConstTraitItem(..) | ty::MethodTraitItem(..) => None @@ -2437,7 +2452,8 @@ fn enforce_impl_params_are_constrained<'tcx>(tcx: &ty::ctxt<'tcx>, .collect(); for (index, lifetime_def) in ast_generics.lifetimes.iter().enumerate() { - let region = ty::EarlyBoundRegion { param_id: lifetime_def.lifetime.id, + let def_id = tcx.map.local_def_id(lifetime_def.lifetime.id); + let region = ty::EarlyBoundRegion { param_id: def_id, space: TypeSpace, index: index as u32, name: lifetime_def.lifetime.name }; diff --git a/src/librustc_typeck/lib.rs b/src/librustc_typeck/lib.rs index a11cd54b658..7156c9c6091 100644 --- a/src/librustc_typeck/lib.rs +++ b/src/librustc_typeck/lib.rs @@ -98,20 +98,20 @@ extern crate rustc; extern crate rustc_platform_intrinsics as intrinsics; extern crate rustc_front; +pub use rustc::front; pub use rustc::lint; pub use rustc::metadata; pub use rustc::middle; pub use rustc::session; pub use rustc::util; +use front::map as hir_map; use middle::def; -use middle::def_id::DefId; use middle::infer; use middle::subst; use middle::ty::{self, Ty, HasTypeFlags}; use session::config; use util::common::time; -use rustc::front::map as hir_map; use rustc_front::hir; use syntax::codemap::Span; @@ -239,7 +239,8 @@ fn check_main_fn_ty(ccx: &CrateCtxt, } _ => () } - let se_ty = tcx.mk_fn(Some(DefId::local(main_id)), tcx.mk_bare_fn(ty::BareFnTy { + let main_def_id = tcx.map.local_def_id(main_id); + let se_ty = tcx.mk_fn(Some(main_def_id), tcx.mk_bare_fn(ty::BareFnTy { unsafety: hir::Unsafety::Normal, abi: abi::Rust, sig: ty::Binder(ty::FnSig { @@ -285,7 +286,8 @@ fn check_start_fn_ty(ccx: &CrateCtxt, _ => () } - let se_ty = tcx.mk_fn(Some(DefId::local(start_id)), tcx.mk_bare_fn(ty::BareFnTy { + let se_ty = tcx.mk_fn(Some(ccx.tcx.map.local_def_id(start_id)), + tcx.mk_bare_fn(ty::BareFnTy { unsafety: hir::Unsafety::Normal, abi: abi::Rust, sig: ty::Binder(ty::FnSig { diff --git a/src/librustc_typeck/variance.rs b/src/librustc_typeck/variance.rs index 4220e258ca5..86a97f305aa 100644 --- a/src/librustc_typeck/variance.rs +++ b/src/librustc_typeck/variance.rs @@ -452,9 +452,10 @@ impl<'a, 'tcx> TermsContext<'a, 'tcx> { // "invalid item id" from "item id with no // parameters". if self.num_inferred() == inferreds_on_entry { + let item_def_id = self.tcx.map.local_def_id(item_id); let newly_added = self.tcx.item_variance_map.borrow_mut().insert( - DefId::local(item_id), + item_def_id, self.empty_variances.clone()).is_none(); assert!(newly_added); } @@ -487,7 +488,7 @@ impl<'a, 'tcx> TermsContext<'a, 'tcx> { param_id={}, \ inf_index={:?}, \ initial_variance={:?})", - self.tcx.item_path_str(DefId::local(item_id)), + self.tcx.item_path_str(self.tcx.map.local_def_id(item_id)), item_id, kind, space, index, param_id, inf_index, initial_variance); } @@ -597,8 +598,8 @@ fn add_constraints_from_crate<'a, 'tcx>(terms_cx: TermsContext<'a, 'tcx>, impl<'a, 'tcx, 'v> Visitor<'v> for ConstraintContext<'a, 'tcx> { fn visit_item(&mut self, item: &hir::Item) { - let did = DefId::local(item.id); let tcx = self.terms_cx.tcx; + let did = tcx.map.local_def_id(item.id); debug!("visit_item item={}", tcx.map.node_to_string(item.id)); @@ -1012,8 +1013,9 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> { variance: VarianceTermPtr<'a>) { match region { ty::ReEarlyBound(ref data) => { - if self.is_to_be_inferred(data.param_id) { - let index = self.inferred_index(data.param_id); + let node_id = self.tcx().map.as_local_node_id(data.param_id).unwrap(); + if self.is_to_be_inferred(node_id) { + let index = self.inferred_index(node_id); self.add_constraint(index, variance); } } @@ -1164,7 +1166,7 @@ impl<'a, 'tcx> SolveContext<'a, 'tcx> { item_id, item_variances); - let item_def_id = DefId::local(item_id); + let item_def_id = tcx.map.local_def_id(item_id); // For unit testing: check for a special "rustc_variance" // attribute and report an error with various results if found. diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 4ecaa46fb45..e6580a2c037 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -189,7 +189,7 @@ impl<'a, 'tcx> Clean<Crate> for visit_ast::RustdocVisitor<'a, 'tcx> { attrs: child.attrs.clone(), visibility: Some(hir::Public), stability: None, - def_id: DefId::local(prim.to_node_id()), + def_id: cx.map.local_def_id(prim.to_node_id()), inner: PrimitiveItem(prim), }); } @@ -420,7 +420,7 @@ impl Clean<Item> for doctree::Module { source: whence.clean(cx), visibility: self.vis.clean(cx), stability: self.stab.clean(cx), - def_id: DefId::local(self.id), + def_id: cx.map.local_def_id(self.id), inner: ModuleItem(Module { is_crate: self.is_crate, items: items @@ -1088,7 +1088,7 @@ impl Clean<Item> for doctree::Function { source: self.whence.clean(cx), visibility: self.vis.clean(cx), stability: self.stab.clean(cx), - def_id: DefId::local(self.id), + def_id: cx.map.local_def_id(self.id), inner: FunctionItem(Function { decl: self.decl.clean(cx), generics: self.generics.clean(cx), @@ -1211,7 +1211,7 @@ impl Clean<Item> for doctree::Trait { name: Some(self.name.clean(cx)), attrs: self.attrs.clean(cx), source: self.whence.clean(cx), - def_id: DefId::local(self.id), + def_id: cx.map.local_def_id(self.id), visibility: self.vis.clean(cx), stability: self.stab.clean(cx), inner: TraitItem(Trait { @@ -1261,9 +1261,9 @@ impl Clean<Item> for hir::TraitItem { name: Some(self.name.clean(cx)), attrs: self.attrs.clean(cx), source: self.span.clean(cx), - def_id: DefId::local(self.id), + def_id: cx.map.local_def_id(self.id), visibility: None, - stability: get_stability(cx, DefId::local(self.id)), + stability: get_stability(cx, cx.map.local_def_id(self.id)), inner: inner } } @@ -1294,9 +1294,9 @@ impl Clean<Item> for hir::ImplItem { name: Some(self.name.clean(cx)), source: self.span.clean(cx), attrs: self.attrs.clean(cx), - def_id: DefId::local(self.id), + def_id: cx.map.local_def_id(self.id), visibility: self.vis.clean(cx), - stability: get_stability(cx, DefId::local(self.id)), + stability: get_stability(cx, cx.map.local_def_id(self.id)), inner: inner } } @@ -1660,7 +1660,7 @@ impl<'tcx> Clean<Type> for ty::Ty<'tcx> { type_params: Vec::new(), where_predicates: Vec::new() }, - decl: (DefId::local(0), &fty.sig).clean(cx), + decl: (cx.map.local_def_id(0), &fty.sig).clean(cx), abi: fty.abi.to_string(), }), ty::TyStruct(def, substs) | @@ -1728,8 +1728,8 @@ impl Clean<Item> for hir::StructField { attrs: self.node.attrs.clean(cx), source: self.span.clean(cx), visibility: Some(vis), - stability: get_stability(cx, DefId::local(self.node.id)), - def_id: DefId::local(self.node.id), + stability: get_stability(cx, cx.map.local_def_id(self.node.id)), + def_id: cx.map.local_def_id(self.node.id), inner: StructFieldItem(TypedStructField(self.node.ty.clean(cx))), } } @@ -1782,7 +1782,7 @@ impl Clean<Item> for doctree::Struct { name: Some(self.name.clean(cx)), attrs: self.attrs.clean(cx), source: self.whence.clean(cx), - def_id: DefId::local(self.id), + def_id: cx.map.local_def_id(self.id), visibility: self.vis.clean(cx), stability: self.stab.clean(cx), inner: StructItem(Struct { @@ -1828,7 +1828,7 @@ impl Clean<Item> for doctree::Enum { name: Some(self.name.clean(cx)), attrs: self.attrs.clean(cx), source: self.whence.clean(cx), - def_id: DefId::local(self.id), + def_id: cx.map.local_def_id(self.id), visibility: self.vis.clean(cx), stability: self.stab.clean(cx), inner: EnumItem(Enum { @@ -1853,7 +1853,7 @@ impl Clean<Item> for doctree::Variant { source: self.whence.clean(cx), visibility: None, stability: self.stab.clean(cx), - def_id: DefId::local(self.id), + def_id: cx.map.local_def_id(self.id), inner: VariantItem(Variant { kind: self.kind.clean(cx), }), @@ -2083,7 +2083,7 @@ impl Clean<Item> for doctree::Typedef { name: Some(self.name.clean(cx)), attrs: self.attrs.clean(cx), source: self.whence.clean(cx), - def_id: DefId::local(self.id.clone()), + def_id: cx.map.local_def_id(self.id.clone()), visibility: self.vis.clean(cx), stability: self.stab.clean(cx), inner: TypedefItem(Typedef { @@ -2134,7 +2134,7 @@ impl Clean<Item> for doctree::Static { name: Some(self.name.clean(cx)), attrs: self.attrs.clean(cx), source: self.whence.clean(cx), - def_id: DefId::local(self.id), + def_id: cx.map.local_def_id(self.id), visibility: self.vis.clean(cx), stability: self.stab.clean(cx), inner: StaticItem(Static { @@ -2158,7 +2158,7 @@ impl Clean<Item> for doctree::Constant { name: Some(self.name.clean(cx)), attrs: self.attrs.clean(cx), source: self.whence.clean(cx), - def_id: DefId::local(self.id), + def_id: cx.map.local_def_id(self.id), visibility: self.vis.clean(cx), stability: self.stab.clean(cx), inner: ConstantItem(Constant { @@ -2232,7 +2232,7 @@ impl Clean<Vec<Item>> for doctree::Impl { name: None, attrs: self.attrs.clean(cx), source: self.whence.clean(cx), - def_id: DefId::local(self.id), + def_id: cx.map.local_def_id(self.id), visibility: self.vis.clean(cx), stability: self.stab.clean(cx), inner: ImplItem(Impl { @@ -2314,7 +2314,7 @@ impl Clean<Item> for doctree::DefaultImpl { name: None, attrs: self.attrs.clean(cx), source: self.whence.clean(cx), - def_id: DefId::local(self.id), + def_id: cx.map.local_def_id(self.id), visibility: Some(hir::Public), stability: None, inner: DefaultImplItem(DefaultImpl { @@ -2331,7 +2331,7 @@ impl Clean<Item> for doctree::ExternCrate { name: None, attrs: self.attrs.clean(cx), source: self.whence.clean(cx), - def_id: DefId::local(0), + def_id: cx.map.local_def_id(0), visibility: self.vis.clean(cx), stability: None, inner: ExternCrateItem(self.name.clean(cx), self.path.clone()) @@ -2396,7 +2396,7 @@ impl Clean<Vec<Item>> for doctree::Import { name: None, attrs: self.attrs.clean(cx), source: self.whence.clean(cx), - def_id: DefId::local(0), + def_id: cx.map.local_def_id(0), visibility: self.vis.clean(cx), stability: None, inner: ImportItem(inner) @@ -2482,9 +2482,9 @@ impl Clean<Item> for hir::ForeignItem { name: Some(self.name.clean(cx)), attrs: self.attrs.clean(cx), source: self.span.clean(cx), - def_id: DefId::local(self.id), + def_id: cx.map.local_def_id(self.id), visibility: self.vis.clean(cx), - stability: get_stability(cx, DefId::local(self.id)), + stability: get_stability(cx, cx.map.local_def_id(self.id)), inner: inner, } } @@ -2662,7 +2662,7 @@ impl Clean<Item> for doctree::Macro { source: self.whence.clean(cx), visibility: hir::Public.clean(cx), stability: self.stab.clean(cx), - def_id: DefId::local(self.id), + def_id: cx.map.local_def_id(self.id), inner: MacroItem(Macro { source: self.whence.to_src(cx), imported_from: self.imported_from.clean(cx), diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index d7238c827ab..8bc832a68db 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -19,7 +19,6 @@ use rustc::lint; use rustc_trans::back::link; use rustc_resolve as resolve; use rustc_front::lowering::lower_crate; -use rustc_front::hir; use syntax::{ast, codemap, diagnostic}; use syntax::feature_gate::UnstableFeatures; @@ -44,7 +43,7 @@ pub type ExternalPaths = RefCell<Option<HashMap<DefId, (Vec<String>, clean::TypeKind)>>>; pub struct DocContext<'a, 'tcx: 'a> { - pub krate: &'tcx hir::Crate, + pub map: &'a hir_map::Map<'tcx>, pub maybe_typed: MaybeTyped<'a, 'tcx>, pub input: Input, pub external_paths: ExternalPaths, @@ -148,7 +147,7 @@ pub fn run_core(search_paths: SearchPaths, cfgs: Vec<String>, externs: Externs, let ty::CrateAnalysis { exported_items, public_items, .. } = analysis; let ctxt = DocContext { - krate: tcx.map.krate(), + map: &tcx.map, maybe_typed: Typed(tcx), input: input, external_traits: RefCell::new(Some(HashMap::new())), @@ -158,7 +157,7 @@ pub fn run_core(search_paths: SearchPaths, cfgs: Vec<String>, externs: Externs, populated_crate_impls: RefCell::new(HashSet::new()), deref_trait_did: Cell::new(None), }; - debug!("crate: {:?}", ctxt.krate); + debug!("crate: {:?}", ctxt.map.krate()); let mut analysis = CrateAnalysis { exported_items: exported_items, @@ -171,7 +170,7 @@ pub fn run_core(search_paths: SearchPaths, cfgs: Vec<String>, externs: Externs, let krate = { let mut v = RustdocVisitor::new(&ctxt, Some(&analysis)); - v.visit(ctxt.krate); + v.visit(ctxt.map.krate()); v.clean(&ctxt) }; diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index 509e6c7df77..c392e75ebf9 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -214,7 +214,7 @@ pub struct Cache { // then the fully qualified name of the structure isn't presented in `paths` // yet when its implementation methods are being indexed. Caches such methods // and their parent id here and indexes them at the end of crate parsing. - orphan_methods: Vec<(ast::NodeId, clean::Item)>, + orphan_methods: Vec<(DefId, clean::Item)>, } /// Helper struct to render all source code to HTML pages @@ -460,8 +460,7 @@ fn build_index(krate: &clean::Crate, cache: &mut Cache) -> io::Result<String> { // Attach all orphan methods to the type's definition if the type // has since been learned. - for &(pid, ref item) in orphan_methods { - let did = DefId::local(pid); + for &(did, ref item) in orphan_methods { match paths.get(&did) { Some(&(ref fqp, _)) => { // Needed to determine `self` type. @@ -969,7 +968,7 @@ impl DocFolder for Cache { if parent.is_local() { // We have a parent, but we don't know where they're // defined yet. Wait for later to index this item. - self.orphan_methods.push((parent.node, item.clone())) + self.orphan_methods.push((parent, item.clone())) } } _ => {} @@ -1034,7 +1033,7 @@ impl DocFolder for Cache { ref t => { match t.primitive_type() { Some(prim) => { - let did = DefId::local(prim.to_node_id()); + let did = DefId::xxx_local(prim.to_node_id()); // TODO self.parent_stack.push(did); true } diff --git a/src/librustdoc/test.rs b/src/librustdoc/test.rs index 2f47353fee7..387e1a8cc07 100644 --- a/src/librustdoc/test.rs +++ b/src/librustdoc/test.rs @@ -22,6 +22,7 @@ use std::sync::{Arc, Mutex}; use testing; use rustc_lint; +use rustc::front::map as hir_map; use rustc::session::{self, config}; use rustc::session::config::get_unstable_features_setting; use rustc::session::search_paths::{SearchPaths, PathKind}; @@ -86,8 +87,11 @@ pub fn run(input: &str, let opts = scrape_test_config(&krate); + let mut forest = hir_map::Forest::new(krate); + let map = hir_map::map_crate(&mut forest); + let ctx = core::DocContext { - krate: &krate, + map: &map, maybe_typed: core::NotTyped(sess), input: input, external_paths: RefCell::new(Some(HashMap::new())), @@ -99,7 +103,7 @@ pub fn run(input: &str, }; let mut v = RustdocVisitor::new(&ctx, None); - v.visit(ctx.krate); + v.visit(ctx.map.krate()); let mut krate = v.clean(&ctx); match crate_name { Some(name) => krate.name = name, diff --git a/src/librustdoc/visit_ast.rs b/src/librustdoc/visit_ast.rs index d8181155677..f9c8f2a0b8d 100644 --- a/src/librustdoc/visit_ast.rs +++ b/src/librustdoc/visit_ast.rs @@ -21,7 +21,6 @@ use syntax::attr::AttrMetaMethods; use syntax::codemap::Span; use rustc::front::map as hir_map; -use rustc::middle::def_id::DefId; use rustc::middle::stability; use rustc_front::hir; @@ -64,7 +63,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> { fn stability(&self, id: ast::NodeId) -> Option<attr::Stability> { self.cx.tcx_opt().and_then( - |tcx| stability::lookup(tcx, DefId::local(id)).map(|x| x.clone())) + |tcx| stability::lookup(tcx, self.cx.map.local_def_id(id)).map(|x| x.clone())) } pub fn visit(&mut self, krate: &hir::Crate) { |
