rustc: collapse relevant DefPathData variants into TypeNs.
This commit is contained in:
parent
13fde05b12
commit
e5b9f54cd9
9 changed files with 61 additions and 90 deletions
|
|
@ -139,14 +139,13 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
|
|||
// information we encapsulate into, the better
|
||||
let def_data = match i.node {
|
||||
ItemKind::Impl(..) => DefPathData::Impl,
|
||||
ItemKind::Trait(..) => DefPathData::Trait(i.ident.as_interned_str()),
|
||||
ItemKind::TraitAlias(..) => DefPathData::TraitAlias(i.ident.as_interned_str()),
|
||||
ItemKind::Enum(..) | ItemKind::Struct(..) | ItemKind::Union(..) |
|
||||
ItemKind::Existential(..) | ItemKind::ExternCrate(..) | ItemKind::ForeignMod(..) |
|
||||
ItemKind::Ty(..) => DefPathData::TypeNs(i.ident.as_interned_str()),
|
||||
ItemKind::Mod(..) if i.ident == keywords::Invalid.ident() => {
|
||||
return visit::walk_item(self, i);
|
||||
}
|
||||
ItemKind::Mod(..) | ItemKind::Trait(..) | ItemKind::TraitAlias(..) |
|
||||
ItemKind::Enum(..) | ItemKind::Struct(..) | ItemKind::Union(..) |
|
||||
ItemKind::Existential(..) | ItemKind::ExternCrate(..) | ItemKind::ForeignMod(..) |
|
||||
ItemKind::Ty(..) => DefPathData::TypeNs(i.ident.as_interned_str()),
|
||||
ItemKind::Fn(
|
||||
ref decl,
|
||||
ref header,
|
||||
|
|
@ -163,7 +162,6 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
|
|||
body,
|
||||
)
|
||||
}
|
||||
ItemKind::Mod(..) => DefPathData::Module(i.ident.as_interned_str()),
|
||||
ItemKind::Static(..) | ItemKind::Const(..) | ItemKind::Fn(..) =>
|
||||
DefPathData::ValueNs(i.ident.as_interned_str()),
|
||||
ItemKind::MacroDef(..) => DefPathData::MacroDef(i.ident.as_interned_str()),
|
||||
|
|
@ -211,7 +209,7 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
|
|||
|
||||
fn visit_variant(&mut self, v: &'a Variant, g: &'a Generics, item_id: NodeId) {
|
||||
let def = self.create_def(v.node.id,
|
||||
DefPathData::EnumVariant(v.node.ident.as_interned_str()),
|
||||
DefPathData::TypeNs(v.node.ident.as_interned_str()),
|
||||
REGULAR_SPACE,
|
||||
v.span);
|
||||
self.with_parent(def, |this| {
|
||||
|
|
@ -239,7 +237,7 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
|
|||
let name = param.ident.as_interned_str();
|
||||
let def_path_data = match param.kind {
|
||||
GenericParamKind::Lifetime { .. } => DefPathData::LifetimeParam(name),
|
||||
GenericParamKind::Type { .. } => DefPathData::TypeParam(name),
|
||||
GenericParamKind::Type { .. } => DefPathData::TypeNs(name),
|
||||
GenericParamKind::Const { .. } => DefPathData::ConstParam(name),
|
||||
};
|
||||
self.create_def(param.id, def_path_data, REGULAR_SPACE, param.ident.span);
|
||||
|
|
@ -252,7 +250,7 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
|
|||
TraitItemKind::Method(..) | TraitItemKind::Const(..) =>
|
||||
DefPathData::ValueNs(ti.ident.as_interned_str()),
|
||||
TraitItemKind::Type(..) => {
|
||||
DefPathData::AssocTypeInTrait(ti.ident.as_interned_str())
|
||||
DefPathData::TypeNs(ti.ident.as_interned_str())
|
||||
},
|
||||
TraitItemKind::Macro(..) => return self.visit_macro_invoc(ti.id),
|
||||
};
|
||||
|
|
@ -279,9 +277,9 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
|
|||
}
|
||||
ImplItemKind::Method(..) | ImplItemKind::Const(..) =>
|
||||
DefPathData::ValueNs(ii.ident.as_interned_str()),
|
||||
ImplItemKind::Type(..) => DefPathData::AssocTypeInImpl(ii.ident.as_interned_str()),
|
||||
ImplItemKind::Type(..) |
|
||||
ImplItemKind::Existential(..) => {
|
||||
DefPathData::AssocExistentialInImpl(ii.ident.as_interned_str())
|
||||
DefPathData::TypeNs(ii.ident.as_interned_str())
|
||||
},
|
||||
ImplItemKind::Macro(..) => return self.visit_macro_invoc(ii.id),
|
||||
};
|
||||
|
|
|
|||
|
|
@ -337,33 +337,19 @@ pub enum DefPathData {
|
|||
// Different kinds of items and item-like things:
|
||||
/// An impl
|
||||
Impl,
|
||||
/// A trait
|
||||
Trait(InternedString),
|
||||
/// An associated type **declaration** (i.e., in a trait)
|
||||
AssocTypeInTrait(InternedString),
|
||||
/// An associated type **value** (i.e., in an impl)
|
||||
AssocTypeInImpl(InternedString),
|
||||
/// An existential associated type **value** (i.e., in an impl)
|
||||
AssocExistentialInImpl(InternedString),
|
||||
/// Something in the type NS
|
||||
TypeNs(InternedString),
|
||||
/// Something in the value NS
|
||||
ValueNs(InternedString),
|
||||
/// A module declaration
|
||||
Module(InternedString),
|
||||
/// A macro rule
|
||||
MacroDef(InternedString),
|
||||
/// A closure expression
|
||||
ClosureExpr,
|
||||
// Subportions of items
|
||||
/// A type (generic) parameter
|
||||
TypeParam(InternedString),
|
||||
/// A lifetime (generic) parameter
|
||||
LifetimeParam(InternedString),
|
||||
/// A const (generic) parameter
|
||||
ConstParam(InternedString),
|
||||
/// A variant of a enum
|
||||
EnumVariant(InternedString),
|
||||
/// A struct field
|
||||
Field(InternedString),
|
||||
/// Implicit ctor for a unit or tuple-like struct or enum variant.
|
||||
|
|
@ -376,8 +362,6 @@ pub enum DefPathData {
|
|||
/// a whole crate (as opposed to just one item). GlobalMetaData components
|
||||
/// are only supposed to show up right below the crate root.
|
||||
GlobalMetaData(InternedString),
|
||||
/// A trait alias.
|
||||
TraitAlias(InternedString),
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Hash, PartialEq, Eq, PartialOrd, Ord, Debug,
|
||||
|
|
@ -633,18 +617,10 @@ impl DefPathData {
|
|||
use self::DefPathData::*;
|
||||
match *self {
|
||||
TypeNs(name) |
|
||||
Trait(name) |
|
||||
TraitAlias(name) |
|
||||
AssocTypeInTrait(name) |
|
||||
AssocTypeInImpl(name) |
|
||||
AssocExistentialInImpl(name) |
|
||||
ValueNs(name) |
|
||||
Module(name) |
|
||||
MacroDef(name) |
|
||||
TypeParam(name) |
|
||||
LifetimeParam(name) |
|
||||
ConstParam(name) |
|
||||
EnumVariant(name) |
|
||||
Field(name) |
|
||||
GlobalMetaData(name) => Some(name),
|
||||
|
||||
|
|
@ -662,18 +638,10 @@ impl DefPathData {
|
|||
use self::DefPathData::*;
|
||||
let s = match *self {
|
||||
TypeNs(name) |
|
||||
Trait(name) |
|
||||
TraitAlias(name) |
|
||||
AssocTypeInTrait(name) |
|
||||
AssocTypeInImpl(name) |
|
||||
AssocExistentialInImpl(name) |
|
||||
ValueNs(name) |
|
||||
Module(name) |
|
||||
MacroDef(name) |
|
||||
TypeParam(name) |
|
||||
LifetimeParam(name) |
|
||||
ConstParam(name) |
|
||||
EnumVariant(name) |
|
||||
Field(name) |
|
||||
GlobalMetaData(name) => {
|
||||
return name
|
||||
|
|
|
|||
|
|
@ -355,7 +355,6 @@ pub trait PrettyPrinter<'gcx: 'tcx, 'tcx>:
|
|||
// the children of the visible parent (as was done when computing
|
||||
// `visible_parent_map`), looking for the specific child we currently have and then
|
||||
// have access to the re-exported name.
|
||||
DefPathData::Module(ref mut name) |
|
||||
DefPathData::TypeNs(ref mut name) if Some(visible_parent) != actual_parent => {
|
||||
let reexport = self.tcx().item_children(visible_parent)
|
||||
.iter()
|
||||
|
|
@ -367,7 +366,7 @@ pub trait PrettyPrinter<'gcx: 'tcx, 'tcx>:
|
|||
}
|
||||
// Re-exported `extern crate` (#43189).
|
||||
DefPathData::CrateRoot => {
|
||||
data = DefPathData::Module(
|
||||
data = DefPathData::TypeNs(
|
||||
self.tcx().original_crate_name(def_id.krate).as_interned_str(),
|
||||
);
|
||||
}
|
||||
|
|
@ -860,7 +859,6 @@ impl TyCtxt<'_, '_, '_> {
|
|||
fn guess_def_namespace(self, def_id: DefId) -> Namespace {
|
||||
match self.def_key(def_id).disambiguated_data.data {
|
||||
DefPathData::ValueNs(..) |
|
||||
DefPathData::EnumVariant(..) |
|
||||
DefPathData::Field(..) |
|
||||
DefPathData::AnonConst |
|
||||
DefPathData::ConstParam(..) |
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
//! Miscellaneous type-system utilities that are too small to deserve their own modules.
|
||||
|
||||
use crate::hir;
|
||||
use crate::hir::def::DefKind;
|
||||
use crate::hir::def_id::DefId;
|
||||
use crate::hir::map::DefPathData;
|
||||
use crate::mir::interpret::{sign_extend, truncate};
|
||||
|
|
@ -529,21 +530,13 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
|||
|
||||
/// Returns `true` if `def_id` refers to a trait (i.e., `trait Foo { ... }`).
|
||||
pub fn is_trait(self, def_id: DefId) -> bool {
|
||||
if let DefPathData::Trait(_) = self.def_key(def_id).disambiguated_data.data {
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
self.def_kind(def_id) == Some(DefKind::Trait)
|
||||
}
|
||||
|
||||
/// Returns `true` if `def_id` refers to a trait alias (i.e., `trait Foo = ...;`),
|
||||
/// and `false` otherwise.
|
||||
pub fn is_trait_alias(self, def_id: DefId) -> bool {
|
||||
if let DefPathData::TraitAlias(_) = self.def_key(def_id).disambiguated_data.data {
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
self.def_kind(def_id) == Some(DefKind::TraitAlias)
|
||||
}
|
||||
|
||||
/// Returns `true` if this `DefId` refers to the implicit constructor for
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue