rustc: factor most DefId-containing variants out of Def and into DefKind.
This commit is contained in:
parent
3af1bdc4bc
commit
a3fcab36d2
49 changed files with 737 additions and 611 deletions
|
|
@ -8,7 +8,7 @@ use rustc::hir::map::{DefKey, DefPath, DefPathData, DefPathHash, Definitions};
|
|||
use rustc::hir;
|
||||
use rustc::middle::cstore::LinkagePreference;
|
||||
use rustc::middle::exported_symbols::{ExportedSymbol, SymbolExportLevel};
|
||||
use rustc::hir::def::{self, Def, CtorOf, CtorKind};
|
||||
use rustc::hir::def::{self, Def, DefKind, CtorOf, CtorKind};
|
||||
use rustc::hir::def_id::{CrateNum, DefId, DefIndex, DefIndexAddressSpace,
|
||||
CRATE_DEF_INDEX, LOCAL_CRATE, LocalDefId};
|
||||
use rustc::hir::map::definitions::DefPathTable;
|
||||
|
|
@ -401,30 +401,30 @@ impl<'a, 'tcx> MetadataBlob {
|
|||
impl<'tcx> EntryKind<'tcx> {
|
||||
fn to_def(&self, did: DefId) -> Option<Def> {
|
||||
Some(match *self {
|
||||
EntryKind::Const(..) => Def::Const(did),
|
||||
EntryKind::AssociatedConst(..) => Def::AssociatedConst(did),
|
||||
EntryKind::Const(..) => Def::Def(DefKind::Const, did),
|
||||
EntryKind::AssociatedConst(..) => Def::Def(DefKind::AssociatedConst, did),
|
||||
EntryKind::ImmStatic |
|
||||
EntryKind::MutStatic |
|
||||
EntryKind::ForeignImmStatic |
|
||||
EntryKind::ForeignMutStatic => Def::Static(did),
|
||||
EntryKind::Struct(_, _) => Def::Struct(did),
|
||||
EntryKind::Union(_, _) => Def::Union(did),
|
||||
EntryKind::ForeignMutStatic => Def::Def(DefKind::Static, did),
|
||||
EntryKind::Struct(_, _) => Def::Def(DefKind::Struct, did),
|
||||
EntryKind::Union(_, _) => Def::Def(DefKind::Union, did),
|
||||
EntryKind::Fn(_) |
|
||||
EntryKind::ForeignFn(_) => Def::Fn(did),
|
||||
EntryKind::Method(_) => Def::Method(did),
|
||||
EntryKind::Type => Def::TyAlias(did),
|
||||
EntryKind::TypeParam => Def::TyParam(did),
|
||||
EntryKind::ConstParam => Def::ConstParam(did),
|
||||
EntryKind::Existential => Def::Existential(did),
|
||||
EntryKind::AssociatedType(_) => Def::AssociatedTy(did),
|
||||
EntryKind::AssociatedExistential(_) => Def::AssociatedExistential(did),
|
||||
EntryKind::Mod(_) => Def::Mod(did),
|
||||
EntryKind::Variant(_) => Def::Variant(did),
|
||||
EntryKind::Trait(_) => Def::Trait(did),
|
||||
EntryKind::TraitAlias(_) => Def::TraitAlias(did),
|
||||
EntryKind::Enum(..) => Def::Enum(did),
|
||||
EntryKind::MacroDef(_) => Def::Macro(did, MacroKind::Bang),
|
||||
EntryKind::ForeignType => Def::ForeignTy(did),
|
||||
EntryKind::ForeignFn(_) => Def::Def(DefKind::Fn, did),
|
||||
EntryKind::Method(_) => Def::Def(DefKind::Method, did),
|
||||
EntryKind::Type => Def::Def(DefKind::TyAlias, did),
|
||||
EntryKind::TypeParam => Def::Def(DefKind::TyParam, did),
|
||||
EntryKind::ConstParam => Def::Def(DefKind::ConstParam, did),
|
||||
EntryKind::Existential => Def::Def(DefKind::Existential, did),
|
||||
EntryKind::AssociatedType(_) => Def::Def(DefKind::AssociatedTy, did),
|
||||
EntryKind::AssociatedExistential(_) => Def::Def(DefKind::AssociatedExistential, did),
|
||||
EntryKind::Mod(_) => Def::Def(DefKind::Mod, did),
|
||||
EntryKind::Variant(_) => Def::Def(DefKind::Variant, did),
|
||||
EntryKind::Trait(_) => Def::Def(DefKind::Trait, did),
|
||||
EntryKind::TraitAlias(_) => Def::Def(DefKind::TraitAlias, did),
|
||||
EntryKind::Enum(..) => Def::Def(DefKind::Enum, did),
|
||||
EntryKind::MacroDef(_) => Def::Def(DefKind::Macro(MacroKind::Bang), did),
|
||||
EntryKind::ForeignType => Def::Def(DefKind::ForeignTy, did),
|
||||
|
||||
EntryKind::ForeignMod |
|
||||
EntryKind::GlobalAsm |
|
||||
|
|
@ -512,7 +512,7 @@ impl<'a, 'tcx> CrateMetadata {
|
|||
self.entry(index).kind.to_def(self.local_def_id(index))
|
||||
} else {
|
||||
let kind = self.proc_macros.as_ref().unwrap()[index.to_proc_macro_index()].1.kind();
|
||||
Some(Def::Macro(self.local_def_id(index), kind))
|
||||
Some(Def::Def(DefKind::Macro(kind), self.local_def_id(index)))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -743,12 +743,12 @@ impl<'a, 'tcx> CrateMetadata {
|
|||
*/
|
||||
if id == CRATE_DEF_INDEX {
|
||||
for (id, &(name, ref ext)) in proc_macros.iter().enumerate() {
|
||||
let def = Def::Macro(
|
||||
let def = Def::Def(
|
||||
DefKind::Macro(ext.kind()),
|
||||
DefId {
|
||||
krate: self.cnum,
|
||||
index: DefIndex::from_proc_macro_index(id),
|
||||
},
|
||||
ext.kind()
|
||||
);
|
||||
let ident = Ident::with_empty_ctxt(name);
|
||||
callback(def::Export {
|
||||
|
|
@ -815,22 +815,28 @@ impl<'a, 'tcx> CrateMetadata {
|
|||
// For non-re-export structs and variants add their constructors to children.
|
||||
// Re-export lists automatically contain constructors when necessary.
|
||||
match def {
|
||||
Def::Struct(..) => {
|
||||
Def::Def(DefKind::Struct, _) => {
|
||||
if let Some(ctor_def_id) = self.get_ctor_def_id(child_index) {
|
||||
let ctor_kind = self.get_ctor_kind(child_index);
|
||||
let ctor_def = Def::Ctor(ctor_def_id, CtorOf::Struct, ctor_kind);
|
||||
let ctor_def = Def::Def(
|
||||
DefKind::Ctor(CtorOf::Struct, ctor_kind),
|
||||
ctor_def_id,
|
||||
);
|
||||
let vis = self.get_visibility(ctor_def_id.index);
|
||||
callback(def::Export { def: ctor_def, vis, ident, span });
|
||||
}
|
||||
}
|
||||
Def::Variant(def_id) => {
|
||||
Def::Def(DefKind::Variant, def_id) => {
|
||||
// Braced variants, unlike structs, generate unusable names in
|
||||
// value namespace, they are reserved for possible future use.
|
||||
// It's ok to use the variant's id as a ctor id since an
|
||||
// error will be reported on any use of such resolution anyway.
|
||||
let ctor_def_id = self.get_ctor_def_id(child_index).unwrap_or(def_id);
|
||||
let ctor_kind = self.get_ctor_kind(child_index);
|
||||
let ctor_def = Def::Ctor(ctor_def_id, CtorOf::Variant, ctor_kind);
|
||||
let ctor_def = Def::Def(
|
||||
DefKind::Ctor(CtorOf::Variant, ctor_kind),
|
||||
ctor_def_id,
|
||||
);
|
||||
let mut vis = self.get_visibility(ctor_def_id.index);
|
||||
if ctor_def_id == def_id && vis == ty::Visibility::Public {
|
||||
// For non-exhaustive variants lower the constructor visibility to
|
||||
|
|
@ -854,7 +860,7 @@ impl<'a, 'tcx> CrateMetadata {
|
|||
if let EntryKind::Mod(data) = item.kind {
|
||||
for exp in data.decode((self, sess)).reexports.decode((self, sess)) {
|
||||
match exp.def {
|
||||
Def::Macro(..) => {}
|
||||
Def::Def(DefKind::Macro(..), _) => {}
|
||||
_ if macros_only => continue,
|
||||
_ => {}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue