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
|
|
@ -11,12 +11,12 @@ use std::fmt::Debug;
|
|||
|
||||
use self::Namespace::*;
|
||||
|
||||
/// Encodes if a `Def::Ctor` is the constructor of an enum variant or a struct.
|
||||
/// Encodes if a `DefKind::Ctor` is the constructor of an enum variant or a struct.
|
||||
#[derive(Clone, Copy, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, HashStable)]
|
||||
pub enum CtorOf {
|
||||
/// This `Def::Ctor` is a synthesized constructor of a tuple or unit struct.
|
||||
/// This `DefKind::Ctor` is a synthesized constructor of a tuple or unit struct.
|
||||
Struct,
|
||||
/// This `Def::Ctor` is a synthesized constructor of a tuple or unit variant.
|
||||
/// This `DefKind::Ctor` is a synthesized constructor of a tuple or unit variant.
|
||||
Variant,
|
||||
}
|
||||
|
||||
|
|
@ -45,41 +45,52 @@ pub enum NonMacroAttrKind {
|
|||
}
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, HashStable)]
|
||||
pub enum Def<Id = hir::HirId> {
|
||||
pub enum DefKind {
|
||||
// Type namespace
|
||||
Mod(DefId),
|
||||
/// `DefId` refers to the struct itself, `Def::Ctor` refers to its constructor if it exists.
|
||||
Struct(DefId),
|
||||
Union(DefId),
|
||||
Enum(DefId),
|
||||
/// `DefId` refers to the variant itself, `Def::Ctor` refers to its constructor if it exists.
|
||||
Variant(DefId),
|
||||
Trait(DefId),
|
||||
Mod,
|
||||
/// Refers to the struct itself, `DefKind::Ctor` refers to its constructor if it exists.
|
||||
Struct,
|
||||
Union,
|
||||
Enum,
|
||||
/// Refers to the variant itself, `DefKind::Ctor` refers to its constructor if it exists.
|
||||
Variant,
|
||||
Trait,
|
||||
/// `existential type Foo: Bar;`
|
||||
Existential(DefId),
|
||||
Existential,
|
||||
/// `type Foo = Bar;`
|
||||
TyAlias(DefId),
|
||||
ForeignTy(DefId),
|
||||
TraitAlias(DefId),
|
||||
AssociatedTy(DefId),
|
||||
TyAlias,
|
||||
ForeignTy,
|
||||
TraitAlias,
|
||||
AssociatedTy,
|
||||
/// `existential type Foo: Bar;`
|
||||
AssociatedExistential(DefId),
|
||||
AssociatedExistential,
|
||||
TyParam,
|
||||
|
||||
// Value namespace
|
||||
Fn,
|
||||
Const,
|
||||
ConstParam,
|
||||
Static,
|
||||
/// Refers to the struct or enum variant's constructor.
|
||||
Ctor(CtorOf, CtorKind),
|
||||
Method,
|
||||
AssociatedConst,
|
||||
|
||||
// Macro namespace
|
||||
Macro(MacroKind),
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, HashStable)]
|
||||
pub enum Def<Id = hir::HirId> {
|
||||
Def(DefKind, DefId),
|
||||
|
||||
// Type namespace
|
||||
PrimTy(hir::PrimTy),
|
||||
TyParam(DefId),
|
||||
SelfTy(Option<DefId> /* trait */, Option<DefId> /* impl */),
|
||||
ToolMod, // e.g., `rustfmt` in `#[rustfmt::skip]`
|
||||
|
||||
// Value namespace
|
||||
Fn(DefId),
|
||||
Const(DefId),
|
||||
ConstParam(DefId),
|
||||
Static(DefId),
|
||||
/// `DefId` refers to the struct or enum variant's constructor.
|
||||
Ctor(DefId, CtorOf, CtorKind),
|
||||
SelfCtor(DefId /* impl */), // `DefId` refers to the impl
|
||||
Method(DefId),
|
||||
AssociatedConst(DefId),
|
||||
|
||||
Local(Id),
|
||||
Upvar(Id, // `HirId` of closed over local
|
||||
usize, // index in the `freevars` list of the closure
|
||||
|
|
@ -87,10 +98,9 @@ pub enum Def<Id = hir::HirId> {
|
|||
Label(ast::NodeId),
|
||||
|
||||
// Macro namespace
|
||||
Macro(DefId, MacroKind),
|
||||
NonMacroAttr(NonMacroAttrKind), // e.g., `#[inline]` or `#[rustfmt::skip]`
|
||||
|
||||
// Both namespaces
|
||||
// All namespaces
|
||||
Err,
|
||||
}
|
||||
|
||||
|
|
@ -291,15 +301,7 @@ impl<Id> Def<Id> {
|
|||
/// Return `Some(..)` with the `DefId` of this `Def` if it has a id, else `None`.
|
||||
pub fn opt_def_id(&self) -> Option<DefId> {
|
||||
match *self {
|
||||
Def::Fn(id) | Def::Mod(id) | Def::Static(id) |
|
||||
Def::Variant(id) | Def::Ctor(id, ..) | Def::Enum(id) |
|
||||
Def::TyAlias(id) | Def::TraitAlias(id) |
|
||||
Def::AssociatedTy(id) | Def::TyParam(id) | Def::ConstParam(id) | Def::Struct(id) |
|
||||
Def::Union(id) | Def::Trait(id) | Def::Method(id) | Def::Const(id) |
|
||||
Def::AssociatedConst(id) | Def::Macro(id, ..) |
|
||||
Def::Existential(id) | Def::AssociatedExistential(id) | Def::ForeignTy(id) => {
|
||||
Some(id)
|
||||
}
|
||||
Def::Def(_, id) => Some(id),
|
||||
|
||||
Def::Local(..) |
|
||||
Def::Upvar(..) |
|
||||
|
|
@ -318,7 +320,7 @@ impl<Id> Def<Id> {
|
|||
/// Return the `DefId` of this `Def` if it represents a module.
|
||||
pub fn mod_def_id(&self) -> Option<DefId> {
|
||||
match *self {
|
||||
Def::Mod(id) => Some(id),
|
||||
Def::Def(DefKind::Mod, id) => Some(id),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
|
@ -326,39 +328,39 @@ impl<Id> Def<Id> {
|
|||
/// A human readable name for the def kind ("function", "module", etc.).
|
||||
pub fn kind_name(&self) -> &'static str {
|
||||
match *self {
|
||||
Def::Fn(..) => "function",
|
||||
Def::Mod(..) => "module",
|
||||
Def::Static(..) => "static",
|
||||
Def::Enum(..) => "enum",
|
||||
Def::Variant(..) => "variant",
|
||||
Def::Ctor(_, CtorOf::Variant, CtorKind::Fn) => "tuple variant",
|
||||
Def::Ctor(_, CtorOf::Variant, CtorKind::Const) => "unit variant",
|
||||
Def::Ctor(_, CtorOf::Variant, CtorKind::Fictive) => "struct variant",
|
||||
Def::Struct(..) => "struct",
|
||||
Def::Ctor(_, CtorOf::Struct, CtorKind::Fn) => "tuple struct",
|
||||
Def::Ctor(_, CtorOf::Struct, CtorKind::Const) => "unit struct",
|
||||
Def::Ctor(_, CtorOf::Struct, CtorKind::Fictive) =>
|
||||
Def::Def(DefKind::Fn, _) => "function",
|
||||
Def::Def(DefKind::Mod, _) => "module",
|
||||
Def::Def(DefKind::Static, _) => "static",
|
||||
Def::Def(DefKind::Enum, _) => "enum",
|
||||
Def::Def(DefKind::Variant, _) => "variant",
|
||||
Def::Def(DefKind::Ctor(CtorOf::Variant, CtorKind::Fn), _) => "tuple variant",
|
||||
Def::Def(DefKind::Ctor(CtorOf::Variant, CtorKind::Const), _) => "unit variant",
|
||||
Def::Def(DefKind::Ctor(CtorOf::Variant, CtorKind::Fictive), _) => "struct variant",
|
||||
Def::Def(DefKind::Struct, _) => "struct",
|
||||
Def::Def(DefKind::Ctor(CtorOf::Struct, CtorKind::Fn), _) => "tuple struct",
|
||||
Def::Def(DefKind::Ctor(CtorOf::Struct, CtorKind::Const), _) => "unit struct",
|
||||
Def::Def(DefKind::Ctor(CtorOf::Struct, CtorKind::Fictive), _) =>
|
||||
bug!("impossible struct constructor"),
|
||||
Def::Existential(..) => "existential type",
|
||||
Def::TyAlias(..) => "type alias",
|
||||
Def::TraitAlias(..) => "trait alias",
|
||||
Def::AssociatedTy(..) => "associated type",
|
||||
Def::AssociatedExistential(..) => "associated existential type",
|
||||
Def::Def(DefKind::Existential, _) => "existential type",
|
||||
Def::Def(DefKind::TyAlias, _) => "type alias",
|
||||
Def::Def(DefKind::TraitAlias, _) => "trait alias",
|
||||
Def::Def(DefKind::AssociatedTy, _) => "associated type",
|
||||
Def::Def(DefKind::AssociatedExistential, _) => "associated existential type",
|
||||
Def::SelfCtor(..) => "self constructor",
|
||||
Def::Union(..) => "union",
|
||||
Def::Trait(..) => "trait",
|
||||
Def::ForeignTy(..) => "foreign type",
|
||||
Def::Method(..) => "method",
|
||||
Def::Const(..) => "constant",
|
||||
Def::AssociatedConst(..) => "associated constant",
|
||||
Def::TyParam(..) => "type parameter",
|
||||
Def::ConstParam(..) => "const parameter",
|
||||
Def::Def(DefKind::Union, _) => "union",
|
||||
Def::Def(DefKind::Trait, _) => "trait",
|
||||
Def::Def(DefKind::ForeignTy, _) => "foreign type",
|
||||
Def::Def(DefKind::Method, _) => "method",
|
||||
Def::Def(DefKind::Const, _) => "constant",
|
||||
Def::Def(DefKind::AssociatedConst, _) => "associated constant",
|
||||
Def::Def(DefKind::TyParam, _) => "type parameter",
|
||||
Def::Def(DefKind::ConstParam, _) => "const parameter",
|
||||
Def::PrimTy(..) => "builtin type",
|
||||
Def::Local(..) => "local variable",
|
||||
Def::Upvar(..) => "closure capture",
|
||||
Def::Label(..) => "label",
|
||||
Def::SelfTy(..) => "self type",
|
||||
Def::Macro(.., macro_kind) => macro_kind.descr(),
|
||||
Def::Def(DefKind::Macro(macro_kind), _) => macro_kind.descr(),
|
||||
Def::ToolMod => "tool module",
|
||||
Def::NonMacroAttr(attr_kind) => attr_kind.descr(),
|
||||
Def::Err => "unresolved item",
|
||||
|
|
@ -368,36 +370,21 @@ impl<Id> Def<Id> {
|
|||
/// An English article for the def.
|
||||
pub fn article(&self) -> &'static str {
|
||||
match *self {
|
||||
Def::AssociatedTy(..) | Def::AssociatedConst(..) | Def::AssociatedExistential(..) |
|
||||
Def::Enum(..) | Def::Existential(..) | Def::Err => "an",
|
||||
Def::Macro(.., macro_kind) => macro_kind.article(),
|
||||
Def::Def(DefKind::AssociatedTy, _)
|
||||
| Def::Def(DefKind::AssociatedConst, _)
|
||||
| Def::Def(DefKind::AssociatedExistential, _)
|
||||
| Def::Def(DefKind::Enum, _)
|
||||
| Def::Def(DefKind::Existential, _)
|
||||
| Def::Err => "an",
|
||||
Def::Def(DefKind::Macro(macro_kind), _) => macro_kind.article(),
|
||||
_ => "a",
|
||||
}
|
||||
}
|
||||
|
||||
pub fn map_id<R>(self, mut map: impl FnMut(Id) -> R) -> Def<R> {
|
||||
match self {
|
||||
Def::Fn(id) => Def::Fn(id),
|
||||
Def::Mod(id) => Def::Mod(id),
|
||||
Def::Static(id) => Def::Static(id),
|
||||
Def::Enum(id) => Def::Enum(id),
|
||||
Def::Variant(id) => Def::Variant(id),
|
||||
Def::Ctor(a, b, c) => Def::Ctor(a, b, c),
|
||||
Def::Struct(id) => Def::Struct(id),
|
||||
Def::Existential(id) => Def::Existential(id),
|
||||
Def::TyAlias(id) => Def::TyAlias(id),
|
||||
Def::TraitAlias(id) => Def::TraitAlias(id),
|
||||
Def::AssociatedTy(id) => Def::AssociatedTy(id),
|
||||
Def::AssociatedExistential(id) => Def::AssociatedExistential(id),
|
||||
Def::Def(kind, id) => Def::Def(kind, id),
|
||||
Def::SelfCtor(id) => Def::SelfCtor(id),
|
||||
Def::Union(id) => Def::Union(id),
|
||||
Def::Trait(id) => Def::Trait(id),
|
||||
Def::ForeignTy(id) => Def::ForeignTy(id),
|
||||
Def::Method(id) => Def::Method(id),
|
||||
Def::Const(id) => Def::Const(id),
|
||||
Def::AssociatedConst(id) => Def::AssociatedConst(id),
|
||||
Def::TyParam(id) => Def::TyParam(id),
|
||||
Def::ConstParam(id) => Def::ConstParam(id),
|
||||
Def::PrimTy(id) => Def::PrimTy(id),
|
||||
Def::Local(id) => Def::Local(map(id)),
|
||||
Def::Upvar(id, index, closure) => Def::Upvar(
|
||||
|
|
@ -407,7 +394,6 @@ impl<Id> Def<Id> {
|
|||
),
|
||||
Def::Label(id) => Def::Label(id),
|
||||
Def::SelfTy(a, b) => Def::SelfTy(a, b),
|
||||
Def::Macro(id, macro_kind) => Def::Macro(id, macro_kind),
|
||||
Def::ToolMod => Def::ToolMod,
|
||||
Def::NonMacroAttr(attr_kind) => Def::NonMacroAttr(attr_kind),
|
||||
Def::Err => Def::Err,
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ use crate::hir::{self, ParamName};
|
|||
use crate::hir::HirVec;
|
||||
use crate::hir::map::{DefKey, DefPathData, Definitions};
|
||||
use crate::hir::def_id::{DefId, DefIndex, DefIndexAddressSpace, CRATE_DEF_INDEX};
|
||||
use crate::hir::def::{Def, PathResolution, PerNS};
|
||||
use crate::hir::def::{Def, DefKind, PathResolution, PerNS};
|
||||
use crate::hir::{GenericArg, ConstArg};
|
||||
use crate::lint::builtin::{self, PARENTHESIZED_PARAMS_IN_TYPES_AND_MODULES,
|
||||
ELIDED_LIFETIMES_IN_PATHS};
|
||||
|
|
@ -1500,7 +1500,7 @@ impl<'a> LoweringContext<'a> {
|
|||
None,
|
||||
P(hir::Path {
|
||||
span,
|
||||
def: Def::TyParam(DefId::local(def_index)),
|
||||
def: Def::Def(DefKind::TyParam, DefId::local(def_index)),
|
||||
segments: hir_vec![hir::PathSegment::from_ident(ident)],
|
||||
}),
|
||||
))
|
||||
|
|
@ -1870,17 +1870,17 @@ impl<'a> LoweringContext<'a> {
|
|||
index: this.def_key(def_id).parent.expect("missing parent"),
|
||||
};
|
||||
let type_def_id = match resolution.base_def() {
|
||||
Def::AssociatedTy(def_id) if i + 2 == proj_start => {
|
||||
Def::Def(DefKind::AssociatedTy, def_id) if i + 2 == proj_start => {
|
||||
Some(parent_def_id(self, def_id))
|
||||
}
|
||||
Def::Variant(def_id) if i + 1 == proj_start => {
|
||||
Def::Def(DefKind::Variant, def_id) if i + 1 == proj_start => {
|
||||
Some(parent_def_id(self, def_id))
|
||||
}
|
||||
Def::Struct(def_id)
|
||||
| Def::Union(def_id)
|
||||
| Def::Enum(def_id)
|
||||
| Def::TyAlias(def_id)
|
||||
| Def::Trait(def_id) if i + 1 == proj_start =>
|
||||
Def::Def(DefKind::Struct, def_id)
|
||||
| Def::Def(DefKind::Union, def_id)
|
||||
| Def::Def(DefKind::Enum, def_id)
|
||||
| Def::Def(DefKind::TyAlias, def_id)
|
||||
| Def::Def(DefKind::Trait, def_id) if i + 1 == proj_start =>
|
||||
{
|
||||
Some(def_id)
|
||||
}
|
||||
|
|
@ -1888,9 +1888,12 @@ impl<'a> LoweringContext<'a> {
|
|||
};
|
||||
let parenthesized_generic_args = match resolution.base_def() {
|
||||
// `a::b::Trait(Args)`
|
||||
Def::Trait(..) if i + 1 == proj_start => ParenthesizedGenericArgs::Ok,
|
||||
Def::Def(DefKind::Trait, _)
|
||||
if i + 1 == proj_start => ParenthesizedGenericArgs::Ok,
|
||||
// `a::b::Trait(Args)::TraitItem`
|
||||
Def::Method(..) | Def::AssociatedConst(..) | Def::AssociatedTy(..)
|
||||
Def::Def(DefKind::Method, _)
|
||||
| Def::Def(DefKind::AssociatedConst, _)
|
||||
| Def::Def(DefKind::AssociatedTy, _)
|
||||
if i + 2 == proj_start =>
|
||||
{
|
||||
ParenthesizedGenericArgs::Ok
|
||||
|
|
@ -1898,11 +1901,11 @@ impl<'a> LoweringContext<'a> {
|
|||
// Avoid duplicated errors.
|
||||
Def::Err => ParenthesizedGenericArgs::Ok,
|
||||
// An error
|
||||
Def::Struct(..)
|
||||
| Def::Enum(..)
|
||||
| Def::Union(..)
|
||||
| Def::TyAlias(..)
|
||||
| Def::Variant(..) if i + 1 == proj_start =>
|
||||
Def::Def(DefKind::Struct, _)
|
||||
| Def::Def(DefKind::Enum, _)
|
||||
| Def::Def(DefKind::Union, _)
|
||||
| Def::Def(DefKind::TyAlias, _)
|
||||
| Def::Def(DefKind::Variant, _) if i + 1 == proj_start =>
|
||||
{
|
||||
ParenthesizedGenericArgs::Err
|
||||
}
|
||||
|
|
@ -2788,7 +2791,7 @@ impl<'a> LoweringContext<'a> {
|
|||
if path.segments.len() == 1
|
||||
&& bound_pred.bound_generic_params.is_empty() =>
|
||||
{
|
||||
if let Some(Def::TyParam(def_id)) = self.resolver
|
||||
if let Some(Def::Def(DefKind::TyParam, def_id)) = self.resolver
|
||||
.get_resolution(bound_pred.bounded_ty.id)
|
||||
.map(|d| d.base_def())
|
||||
{
|
||||
|
|
@ -3242,7 +3245,7 @@ impl<'a> LoweringContext<'a> {
|
|||
});
|
||||
|
||||
if let Some(ref trait_ref) = trait_ref {
|
||||
if let Def::Trait(def_id) = trait_ref.path.def {
|
||||
if let Def::Def(DefKind::Trait, def_id) = trait_ref.path.def {
|
||||
this.trait_impls.entry(def_id).or_default().push(
|
||||
lowered_trait_impl_id);
|
||||
}
|
||||
|
|
@ -5277,7 +5280,7 @@ impl<'a> LoweringContext<'a> {
|
|||
hir::QPath::Resolved(None, path) => {
|
||||
// Turn trait object paths into `TyKind::TraitObject` instead.
|
||||
match path.def {
|
||||
Def::Trait(_) | Def::TraitAlias(_) => {
|
||||
Def::Def(DefKind::Trait, _) | Def::Def(DefKind::TraitAlias, _) => {
|
||||
let principal = hir::PolyTraitRef {
|
||||
bound_generic_params: hir::HirVec::new(),
|
||||
trait_ref: hir::TraitRef {
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ use syntax::ext::base::MacroKind;
|
|||
use syntax_pos::{Span, DUMMY_SP};
|
||||
|
||||
use crate::hir::*;
|
||||
use crate::hir::{Def, DefKind};
|
||||
use crate::hir::itemlikevisit::ItemLikeVisitor;
|
||||
use crate::hir::print::Nested;
|
||||
use crate::util::nodemap::FxHashMap;
|
||||
|
|
@ -316,67 +317,61 @@ impl<'hir> Map<'hir> {
|
|||
return None
|
||||
};
|
||||
|
||||
match node {
|
||||
let kind = match node {
|
||||
Node::Item(item) => {
|
||||
let def_id = || self.local_def_id_from_hir_id(item.hir_id);
|
||||
|
||||
match item.node {
|
||||
ItemKind::Static(..) => Some(Def::Static(def_id())),
|
||||
ItemKind::Const(..) => Some(Def::Const(def_id())),
|
||||
ItemKind::Fn(..) => Some(Def::Fn(def_id())),
|
||||
ItemKind::Mod(..) => Some(Def::Mod(def_id())),
|
||||
ItemKind::Existential(..) => Some(Def::Existential(def_id())),
|
||||
ItemKind::Ty(..) => Some(Def::TyAlias(def_id())),
|
||||
ItemKind::Enum(..) => Some(Def::Enum(def_id())),
|
||||
ItemKind::Struct(..) => Some(Def::Struct(def_id())),
|
||||
ItemKind::Union(..) => Some(Def::Union(def_id())),
|
||||
ItemKind::Trait(..) => Some(Def::Trait(def_id())),
|
||||
ItemKind::TraitAlias(..) => Some(Def::TraitAlias(def_id())),
|
||||
ItemKind::Static(..) => DefKind::Static,
|
||||
ItemKind::Const(..) => DefKind::Const,
|
||||
ItemKind::Fn(..) => DefKind::Fn,
|
||||
ItemKind::Mod(..) => DefKind::Mod,
|
||||
ItemKind::Existential(..) => DefKind::Existential,
|
||||
ItemKind::Ty(..) => DefKind::TyAlias,
|
||||
ItemKind::Enum(..) => DefKind::Enum,
|
||||
ItemKind::Struct(..) => DefKind::Struct,
|
||||
ItemKind::Union(..) => DefKind::Union,
|
||||
ItemKind::Trait(..) => DefKind::Trait,
|
||||
ItemKind::TraitAlias(..) => DefKind::TraitAlias,
|
||||
ItemKind::ExternCrate(_) |
|
||||
ItemKind::Use(..) |
|
||||
ItemKind::ForeignMod(..) |
|
||||
ItemKind::GlobalAsm(..) |
|
||||
ItemKind::Impl(..) => None,
|
||||
ItemKind::Impl(..) => return None,
|
||||
}
|
||||
}
|
||||
Node::ForeignItem(item) => {
|
||||
let def_id = self.local_def_id_from_hir_id(item.hir_id);
|
||||
match item.node {
|
||||
ForeignItemKind::Fn(..) => Some(Def::Fn(def_id)),
|
||||
ForeignItemKind::Static(..) => Some(Def::Static(def_id)),
|
||||
ForeignItemKind::Type => Some(Def::ForeignTy(def_id)),
|
||||
ForeignItemKind::Fn(..) => DefKind::Fn,
|
||||
ForeignItemKind::Static(..) => DefKind::Static,
|
||||
ForeignItemKind::Type => DefKind::ForeignTy,
|
||||
}
|
||||
}
|
||||
Node::TraitItem(item) => {
|
||||
let def_id = self.local_def_id_from_hir_id(item.hir_id);
|
||||
match item.node {
|
||||
TraitItemKind::Const(..) => Some(Def::AssociatedConst(def_id)),
|
||||
TraitItemKind::Method(..) => Some(Def::Method(def_id)),
|
||||
TraitItemKind::Type(..) => Some(Def::AssociatedTy(def_id)),
|
||||
TraitItemKind::Const(..) => DefKind::AssociatedConst,
|
||||
TraitItemKind::Method(..) => DefKind::Method,
|
||||
TraitItemKind::Type(..) => DefKind::AssociatedTy,
|
||||
}
|
||||
}
|
||||
Node::ImplItem(item) => {
|
||||
let def_id = self.local_def_id_from_hir_id(item.hir_id);
|
||||
match item.node {
|
||||
ImplItemKind::Const(..) => Some(Def::AssociatedConst(def_id)),
|
||||
ImplItemKind::Method(..) => Some(Def::Method(def_id)),
|
||||
ImplItemKind::Type(..) => Some(Def::AssociatedTy(def_id)),
|
||||
ImplItemKind::Existential(..) => Some(Def::AssociatedExistential(def_id)),
|
||||
ImplItemKind::Const(..) => DefKind::AssociatedConst,
|
||||
ImplItemKind::Method(..) => DefKind::Method,
|
||||
ImplItemKind::Type(..) => DefKind::AssociatedTy,
|
||||
ImplItemKind::Existential(..) => DefKind::AssociatedExistential,
|
||||
}
|
||||
}
|
||||
Node::Variant(variant) => {
|
||||
let def_id = self.local_def_id_from_hir_id(variant.node.id);
|
||||
Some(Def::Variant(def_id))
|
||||
}
|
||||
Node::Variant(_) => DefKind::Variant,
|
||||
Node::Ctor(variant_data) => {
|
||||
// FIXME(eddyb) is this even possible, if we have a `Node::Ctor`?
|
||||
if variant_data.ctor_hir_id().is_none() {
|
||||
return None;
|
||||
}
|
||||
let ctor_of = match self.find(self.get_parent_node(node_id)) {
|
||||
Some(Node::Item(..)) => def::CtorOf::Struct,
|
||||
Some(Node::Variant(..)) => def::CtorOf::Variant,
|
||||
_ => unreachable!(),
|
||||
};
|
||||
variant_data.ctor_hir_id()
|
||||
.map(|hir_id| self.local_def_id_from_hir_id(hir_id))
|
||||
.map(|def_id| Def::Ctor(def_id, ctor_of, def::CtorKind::from_hir(variant_data)))
|
||||
DefKind::Ctor(ctor_of, def::CtorKind::from_hir(variant_data))
|
||||
}
|
||||
Node::AnonConst(_) |
|
||||
Node::Field(_) |
|
||||
|
|
@ -390,26 +385,22 @@ impl<'hir> Map<'hir> {
|
|||
Node::Lifetime(_) |
|
||||
Node::Visibility(_) |
|
||||
Node::Block(_) |
|
||||
Node::Crate => None,
|
||||
Node::Crate => return None,
|
||||
// FIXME(eddyb) this is the only non-`DefKind` case here,
|
||||
// investigate whether it's actually used, and ideally remove it.
|
||||
Node::Local(local) => {
|
||||
Some(Def::Local(local.hir_id))
|
||||
}
|
||||
Node::MacroDef(macro_def) => {
|
||||
Some(Def::Macro(self.local_def_id_from_hir_id(macro_def.hir_id),
|
||||
MacroKind::Bang))
|
||||
return Some(Def::Local(local.hir_id));
|
||||
}
|
||||
Node::MacroDef(_) => DefKind::Macro(MacroKind::Bang),
|
||||
Node::GenericParam(param) => {
|
||||
Some(match param.kind {
|
||||
GenericParamKind::Lifetime { .. } => {
|
||||
Def::Local(param.hir_id)
|
||||
},
|
||||
GenericParamKind::Type { .. } => Def::TyParam(
|
||||
self.local_def_id_from_hir_id(param.hir_id)),
|
||||
GenericParamKind::Const { .. } => Def::ConstParam(
|
||||
self.local_def_id_from_hir_id(param.hir_id)),
|
||||
})
|
||||
match param.kind {
|
||||
GenericParamKind::Lifetime { .. } => return None,
|
||||
GenericParamKind::Type { .. } => DefKind::TyParam,
|
||||
GenericParamKind::Const { .. } => DefKind::ConstParam,
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
Some(Def::Def(kind, self.local_def_id(node_id)))
|
||||
}
|
||||
|
||||
// FIXME(@ljedrz): replace the NodeId variant
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ pub use self::PrimTy::*;
|
|||
pub use self::UnOp::*;
|
||||
pub use self::UnsafeSource::*;
|
||||
|
||||
use crate::hir::def::Def;
|
||||
use crate::hir::def::{Def, DefKind};
|
||||
use crate::hir::def_id::{DefId, DefIndex, LocalDefId, CRATE_DEF_INDEX};
|
||||
use crate::util::nodemap::{NodeMap, FxHashSet};
|
||||
use crate::mir::mono::Linkage;
|
||||
|
|
@ -1394,7 +1394,10 @@ impl Expr {
|
|||
match self.node {
|
||||
ExprKind::Path(QPath::Resolved(_, ref path)) => {
|
||||
match path.def {
|
||||
Def::Local(..) | Def::Upvar(..) | Def::Static(..) | Def::Err => true,
|
||||
Def::Local(..)
|
||||
| Def::Upvar(..)
|
||||
| Def::Def(DefKind::Static, _)
|
||||
| Def::Err => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
|
@ -2152,8 +2155,8 @@ impl TraitRef {
|
|||
/// Gets the `DefId` of the referenced trait. It _must_ actually be a trait or trait alias.
|
||||
pub fn trait_def_id(&self) -> DefId {
|
||||
match self.path.def {
|
||||
Def::Trait(did) => did,
|
||||
Def::TraitAlias(did) => did,
|
||||
Def::Def(DefKind::Trait, did) => did,
|
||||
Def::Def(DefKind::TraitAlias, did) => did,
|
||||
Def::Err => {
|
||||
FatalError.raise();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use crate::hir::def::{CtorOf, Def};
|
||||
use crate::hir::def::{CtorOf, Def, DefKind};
|
||||
use crate::hir::def_id::DefId;
|
||||
use crate::hir::{self, HirId, PatKind};
|
||||
use syntax::ast;
|
||||
|
|
@ -55,7 +55,7 @@ impl hir::Pat {
|
|||
PatKind::TupleStruct(hir::QPath::Resolved(_, ref path), ..) |
|
||||
PatKind::Struct(hir::QPath::Resolved(_, ref path), ..) => {
|
||||
match path.def {
|
||||
Def::Variant(..) => true,
|
||||
Def::Def(DefKind::Variant, _) => true,
|
||||
_ => false
|
||||
}
|
||||
}
|
||||
|
|
@ -125,8 +125,8 @@ impl hir::Pat {
|
|||
PatKind::TupleStruct(hir::QPath::Resolved(_, ref path), ..) |
|
||||
PatKind::Struct(hir::QPath::Resolved(_, ref path), ..) => {
|
||||
match path.def {
|
||||
Def::Variant(id) => variants.push(id),
|
||||
Def::Ctor(id, CtorOf::Variant, ..) => variants.push(id),
|
||||
Def::Def(DefKind::Variant, id) => variants.push(id),
|
||||
Def::Def(DefKind::Ctor(CtorOf::Variant, ..), id) => variants.push(id),
|
||||
_ => ()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ use crate::hir::{self, PatKind, TyKind};
|
|||
use crate::hir::intravisit::{self, Visitor, NestedVisitorMap};
|
||||
use crate::hir::itemlikevisit::ItemLikeVisitor;
|
||||
|
||||
use crate::hir::def::{CtorOf, Def};
|
||||
use crate::hir::def::{CtorOf, Def, DefKind};
|
||||
use crate::hir::CodegenFnAttrFlags;
|
||||
use crate::hir::def_id::{DefId, LOCAL_CRATE};
|
||||
use crate::lint;
|
||||
|
|
@ -70,13 +70,15 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
|
|||
|
||||
fn handle_definition(&mut self, def: Def) {
|
||||
match def {
|
||||
Def::Const(_) | Def::AssociatedConst(..) | Def::TyAlias(_) => {
|
||||
Def::Def(DefKind::Const, _)
|
||||
| Def::Def(DefKind::AssociatedConst, _)
|
||||
| Def::Def(DefKind::TyAlias, _) => {
|
||||
self.check_def_id(def.def_id());
|
||||
}
|
||||
_ if self.in_pat => {},
|
||||
Def::PrimTy(..) | Def::SelfTy(..) | Def::SelfCtor(..) |
|
||||
Def::Local(..) | Def::Upvar(..) => {}
|
||||
Def::Ctor(ctor_def_id, CtorOf::Variant, ..) => {
|
||||
Def::Def(DefKind::Ctor(CtorOf::Variant, ..), ctor_def_id) => {
|
||||
let variant_id = self.tcx.parent(ctor_def_id).unwrap();
|
||||
let enum_id = self.tcx.parent(variant_id).unwrap();
|
||||
self.check_def_id(enum_id);
|
||||
|
|
@ -84,7 +86,7 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
|
|||
self.check_def_id(variant_id);
|
||||
}
|
||||
}
|
||||
Def::Variant(variant_id) => {
|
||||
Def::Def(DefKind::Variant, variant_id) => {
|
||||
let enum_id = self.tcx.parent(variant_id).unwrap();
|
||||
self.check_def_id(enum_id);
|
||||
if !self.ignore_variant_stack.contains(&variant_id) {
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ pub use self::MatchMode::*;
|
|||
use self::TrackMatchMode::*;
|
||||
use self::OverloadedCallType::*;
|
||||
|
||||
use crate::hir::def::{CtorOf, Def};
|
||||
use crate::hir::def::{CtorOf, Def, DefKind};
|
||||
use crate::hir::def_id::DefId;
|
||||
use crate::infer::InferCtxt;
|
||||
use crate::middle::mem_categorization as mc;
|
||||
|
|
@ -900,21 +900,25 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
|
|||
};
|
||||
let def = mc.tables.qpath_def(qpath, pat.hir_id);
|
||||
match def {
|
||||
Def::Ctor(variant_ctor_did, CtorOf::Variant, ..) => {
|
||||
Def::Def(DefKind::Ctor(CtorOf::Variant, ..), variant_ctor_did) => {
|
||||
let variant_did = mc.tcx.parent(variant_ctor_did).unwrap();
|
||||
let downcast_cmt = mc.cat_downcast_if_needed(pat, cmt_pat, variant_did);
|
||||
|
||||
debug!("variantctor downcast_cmt={:?} pat={:?}", downcast_cmt, pat);
|
||||
delegate.matched_pat(pat, &downcast_cmt, match_mode);
|
||||
}
|
||||
Def::Variant(variant_did) => {
|
||||
Def::Def(DefKind::Variant, variant_did) => {
|
||||
let downcast_cmt = mc.cat_downcast_if_needed(pat, cmt_pat, variant_did);
|
||||
|
||||
debug!("variant downcast_cmt={:?} pat={:?}", downcast_cmt, pat);
|
||||
delegate.matched_pat(pat, &downcast_cmt, match_mode);
|
||||
}
|
||||
Def::Struct(..) | Def::Ctor(..) | Def::Union(..) |
|
||||
Def::TyAlias(..) | Def::AssociatedTy(..) | Def::SelfTy(..) => {
|
||||
Def::Def(DefKind::Struct, _)
|
||||
| Def::Def(DefKind::Ctor(..), _)
|
||||
| Def::Def(DefKind::Union, _)
|
||||
| Def::Def(DefKind::TyAlias, _)
|
||||
| Def::Def(DefKind::AssociatedTy, _)
|
||||
| Def::SelfTy(..) => {
|
||||
debug!("struct cmt_pat={:?} pat={:?}", cmt_pat, pat);
|
||||
delegate.matched_pat(pat, &cmt_pat, match_mode);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use crate::hir::def::Def;
|
||||
use crate::hir::def::{Def, DefKind};
|
||||
use crate::hir::def_id::DefId;
|
||||
use crate::ty::{self, Ty, TyCtxt};
|
||||
use crate::ty::layout::{LayoutError, Pointer, SizeSkeleton, VariantIdx};
|
||||
|
|
@ -157,7 +157,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ExprVisitor<'a, 'tcx> {
|
|||
} else {
|
||||
Def::Err
|
||||
};
|
||||
if let Def::Fn(did) = def {
|
||||
if let Def::Def(DefKind::Fn, did) = def {
|
||||
if self.def_id_is_transmute(did) {
|
||||
let typ = self.tables.node_type(expr.hir_id);
|
||||
let sig = typ.fn_sig(self.tcx);
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ use crate::middle::region;
|
|||
use crate::hir::def_id::{DefId, LocalDefId};
|
||||
use crate::hir::Node;
|
||||
use crate::infer::InferCtxt;
|
||||
use crate::hir::def::{CtorOf, Def, CtorKind};
|
||||
use crate::hir::def::{CtorOf, Def, DefKind, CtorKind};
|
||||
use crate::ty::adjustment;
|
||||
use crate::ty::{self, DefIdTree, Ty, TyCtxt};
|
||||
use crate::ty::fold::TypeFoldable;
|
||||
|
|
@ -699,12 +699,17 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
|
|||
hir_id, expr_ty, def);
|
||||
|
||||
match def {
|
||||
Def::Ctor(..) | Def::Const(..) | Def::ConstParam(..) |
|
||||
Def::AssociatedConst(..) | Def::Fn(..) | Def::Method(..) | Def::SelfCtor(..) => {
|
||||
Def::Def(DefKind::Ctor(..), _)
|
||||
| Def::Def(DefKind::Const, _)
|
||||
| Def::Def(DefKind::ConstParam, _)
|
||||
| Def::Def(DefKind::AssociatedConst, _)
|
||||
| Def::Def(DefKind::Fn, _)
|
||||
| Def::Def(DefKind::Method, _)
|
||||
| Def::SelfCtor(..) => {
|
||||
Ok(self.cat_rvalue_node(hir_id, span, expr_ty))
|
||||
}
|
||||
|
||||
Def::Static(def_id) => {
|
||||
Def::Def(DefKind::Static, def_id) => {
|
||||
// `#[thread_local]` statics may not outlive the current function, but
|
||||
// they also cannot be moved out of.
|
||||
let is_thread_local = self.tcx.get_attrs(def_id)[..]
|
||||
|
|
@ -1274,14 +1279,15 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
|
|||
debug!("access to unresolvable pattern {:?}", pat);
|
||||
return Err(())
|
||||
}
|
||||
Def::Ctor(variant_ctor_did, CtorOf::Variant, CtorKind::Fn) => {
|
||||
Def::Def(DefKind::Ctor(CtorOf::Variant, CtorKind::Fn), variant_ctor_did) => {
|
||||
let variant_did = self.tcx.parent(variant_ctor_did).unwrap();
|
||||
let enum_did = self.tcx.parent(variant_did).unwrap();
|
||||
(self.cat_downcast_if_needed(pat, cmt, variant_did),
|
||||
self.tcx.adt_def(enum_did)
|
||||
.variant_with_ctor_id(variant_ctor_did).fields.len())
|
||||
}
|
||||
Def::Ctor(_, CtorOf::Struct, CtorKind::Fn) | Def::SelfCtor(..) => {
|
||||
Def::Def(DefKind::Ctor(CtorOf::Struct, CtorKind::Fn), _)
|
||||
| Def::SelfCtor(..) => {
|
||||
let ty = self.pat_ty_unadjusted(&pat)?;
|
||||
match ty.sty {
|
||||
ty::Adt(adt_def, _) => {
|
||||
|
|
@ -1316,11 +1322,11 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
|
|||
debug!("access to unresolvable pattern {:?}", pat);
|
||||
return Err(())
|
||||
}
|
||||
Def::Ctor(variant_ctor_did, CtorOf::Variant, _) => {
|
||||
Def::Def(DefKind::Ctor(CtorOf::Variant, _), variant_ctor_did) => {
|
||||
let variant_did = self.tcx.parent(variant_ctor_did).unwrap();
|
||||
self.cat_downcast_if_needed(pat, cmt, variant_did)
|
||||
}
|
||||
Def::Variant(variant_did) => {
|
||||
Def::Def(DefKind::Variant, variant_did) => {
|
||||
self.cat_downcast_if_needed(pat, cmt, variant_did)
|
||||
}
|
||||
_ => cmt,
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
use crate::hir::{CodegenFnAttrs, CodegenFnAttrFlags};
|
||||
use crate::hir::Node;
|
||||
use crate::hir::def::Def;
|
||||
use crate::hir::def::{Def, DefKind};
|
||||
use crate::hir::def_id::{DefId, CrateNum};
|
||||
use rustc_data_structures::sync::Lrc;
|
||||
use crate::ty::{self, TyCtxt};
|
||||
|
|
@ -117,7 +117,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ReachableContext<'a, 'tcx> {
|
|||
// If this path leads to a constant, then we need to
|
||||
// recurse into the constant to continue finding
|
||||
// items that are reachable.
|
||||
Def::Const(..) | Def::AssociatedConst(..) => {
|
||||
Def::Def(DefKind::Const, _) | Def::Def(DefKind::AssociatedConst, _) => {
|
||||
self.worklist.push(hir_id);
|
||||
}
|
||||
|
||||
|
|
@ -357,7 +357,7 @@ impl<'a, 'tcx: 'a> ItemLikeVisitor<'tcx> for CollectPrivateImplItemsVisitor<'a,
|
|||
self.worklist.extend(impl_item_refs.iter().map(|ii_ref| ii_ref.id.hir_id));
|
||||
|
||||
let trait_def_id = match trait_ref.path.def {
|
||||
Def::Trait(def_id) => def_id,
|
||||
Def::Def(DefKind::Trait, def_id) => def_id,
|
||||
_ => unreachable!()
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
//! used between functions, and they operate in a purely top-down
|
||||
//! way. Therefore, we break lifetime name resolution into a separate pass.
|
||||
|
||||
use crate::hir::def::Def;
|
||||
use crate::hir::def::{Def, DefKind};
|
||||
use crate::hir::def_id::{CrateNum, DefId, LocalDefId, LOCAL_CRATE};
|
||||
use crate::hir::map::Map;
|
||||
use crate::hir::{GenericArg, GenericParam, ItemLocalId, LifetimeName, Node, ParamName};
|
||||
|
|
@ -1365,7 +1365,7 @@ fn object_lifetime_defaults_for_item(
|
|||
_ => continue,
|
||||
};
|
||||
|
||||
if def == Def::TyParam(param_def_id) {
|
||||
if def == Def::Def(DefKind::TyParam, param_def_id) {
|
||||
add_bounds(&mut set, &data.bounds);
|
||||
}
|
||||
}
|
||||
|
|
@ -1929,13 +1929,15 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
|
|||
}
|
||||
};
|
||||
let type_def_id = match def {
|
||||
Def::AssociatedTy(def_id) if depth == 1 => Some(parent_def_id(self, def_id)),
|
||||
Def::Variant(def_id) if depth == 0 => Some(parent_def_id(self, def_id)),
|
||||
Def::Struct(def_id)
|
||||
| Def::Union(def_id)
|
||||
| Def::Enum(def_id)
|
||||
| Def::TyAlias(def_id)
|
||||
| Def::Trait(def_id) if depth == 0 =>
|
||||
Def::Def(DefKind::AssociatedTy, def_id)
|
||||
if depth == 1 => Some(parent_def_id(self, def_id)),
|
||||
Def::Def(DefKind::Variant, def_id)
|
||||
if depth == 0 => Some(parent_def_id(self, def_id)),
|
||||
Def::Def(DefKind::Struct, def_id)
|
||||
| Def::Def(DefKind::Union, def_id)
|
||||
| Def::Def(DefKind::Enum, def_id)
|
||||
| Def::Def(DefKind::TyAlias, def_id)
|
||||
| Def::Def(DefKind::Trait, def_id) if depth == 0 =>
|
||||
{
|
||||
Some(def_id)
|
||||
}
|
||||
|
|
@ -2139,7 +2141,10 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
|
|||
// Whitelist the types that unambiguously always
|
||||
// result in the same type constructor being used
|
||||
// (it can't differ between `Self` and `self`).
|
||||
Def::Struct(_) | Def::Union(_) | Def::Enum(_) | Def::PrimTy(_) => {
|
||||
Def::Def(DefKind::Struct, _)
|
||||
| Def::Def(DefKind::Union, _)
|
||||
| Def::Def(DefKind::Enum, _)
|
||||
| Def::PrimTy(_) => {
|
||||
return def == path.def
|
||||
}
|
||||
_ => {}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ pub use self::StabilityLevel::*;
|
|||
|
||||
use crate::lint::{self, Lint, in_derive_expansion};
|
||||
use crate::hir::{self, Item, Generics, StructField, Variant, HirId};
|
||||
use crate::hir::def::Def;
|
||||
use crate::hir::def::{Def, DefKind};
|
||||
use crate::hir::def_id::{CrateNum, CRATE_DEF_INDEX, DefId, LOCAL_CRATE};
|
||||
use crate::hir::intravisit::{self, Visitor, NestedVisitorMap};
|
||||
use crate::ty::query::Providers;
|
||||
|
|
@ -526,9 +526,9 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
|||
fn skip_stability_check_due_to_privacy(self, mut def_id: DefId) -> bool {
|
||||
// Check if `def_id` is a trait method.
|
||||
match self.describe_def(def_id) {
|
||||
Some(Def::Method(_)) |
|
||||
Some(Def::AssociatedTy(_)) |
|
||||
Some(Def::AssociatedConst(_)) => {
|
||||
Some(Def::Def(DefKind::Method, _)) |
|
||||
Some(Def::Def(DefKind::AssociatedTy, _)) |
|
||||
Some(Def::Def(DefKind::AssociatedConst, _)) => {
|
||||
if let ty::TraitContainer(trait_def_id) = self.associated_item(def_id).container {
|
||||
// Trait methods do not declare visibility (even
|
||||
// for visibility info in cstore). Use containing
|
||||
|
|
@ -779,7 +779,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Checker<'a, 'tcx> {
|
|||
// individually as it's possible to have a stable trait with unstable
|
||||
// items.
|
||||
hir::ItemKind::Impl(.., Some(ref t), _, ref impl_item_refs) => {
|
||||
if let Def::Trait(trait_did) = t.path.def {
|
||||
if let Def::Def(DefKind::Trait, trait_did) = t.path.def {
|
||||
for impl_item_ref in impl_item_refs {
|
||||
let impl_item = self.tcx.hir().impl_item(impl_item_ref.id);
|
||||
let trait_item_def_id = self.tcx.associated_items(trait_did)
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ use crate::session::config::{BorrowckMode, OutputFilenames};
|
|||
use crate::session::config::CrateType;
|
||||
use crate::middle;
|
||||
use crate::hir::{TraitCandidate, HirId, ItemKind, ItemLocalId, Node};
|
||||
use crate::hir::def::{Def, Export};
|
||||
use crate::hir::def::{Def, DefKind, Export};
|
||||
use crate::hir::def_id::{CrateNum, DefId, DefIndex, LOCAL_CRATE};
|
||||
use crate::hir::map as hir_map;
|
||||
use crate::hir::map::DefPathHash;
|
||||
|
|
@ -658,7 +658,7 @@ impl<'tcx> TypeckTables<'tcx> {
|
|||
}
|
||||
|
||||
match self.type_dependent_defs().get(expr.hir_id) {
|
||||
Some(&Def::Method(_)) => true,
|
||||
Some(&Def::Def(DefKind::Method, _)) => true,
|
||||
_ => false
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ pub use self::fold::TypeFoldable;
|
|||
|
||||
use crate::hir::{map as hir_map, FreevarMap, GlobMap, TraitMap};
|
||||
use crate::hir::{HirId, Node};
|
||||
use crate::hir::def::{Def, CtorOf, CtorKind, ExportMap};
|
||||
use crate::hir::def::{Def, DefKind, CtorOf, CtorKind, ExportMap};
|
||||
use crate::hir::def_id::{CrateNum, DefId, LocalDefId, CRATE_DEF_INDEX, LOCAL_CRATE};
|
||||
use rustc_data_structures::svh::Svh;
|
||||
use rustc_macros::HashStable;
|
||||
|
|
@ -193,10 +193,10 @@ pub enum AssociatedKind {
|
|||
impl AssociatedItem {
|
||||
pub fn def(&self) -> Def {
|
||||
match self.kind {
|
||||
AssociatedKind::Const => Def::AssociatedConst(self.def_id),
|
||||
AssociatedKind::Method => Def::Method(self.def_id),
|
||||
AssociatedKind::Type => Def::AssociatedTy(self.def_id),
|
||||
AssociatedKind::Existential => Def::AssociatedExistential(self.def_id),
|
||||
AssociatedKind::Const => Def::Def(DefKind::AssociatedConst, self.def_id),
|
||||
AssociatedKind::Method => Def::Def(DefKind::Method, self.def_id),
|
||||
AssociatedKind::Type => Def::Def(DefKind::AssociatedTy, self.def_id),
|
||||
AssociatedKind::Existential => Def::Def(DefKind::AssociatedExistential, self.def_id),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -2339,10 +2339,10 @@ impl<'a, 'gcx, 'tcx> AdtDef {
|
|||
|
||||
pub fn variant_of_def(&self, def: Def) -> &VariantDef {
|
||||
match def {
|
||||
Def::Variant(vid) => self.variant_with_id(vid),
|
||||
Def::Ctor(cid, ..) => self.variant_with_ctor_id(cid),
|
||||
Def::Struct(..) | Def::Union(..) |
|
||||
Def::TyAlias(..) | Def::AssociatedTy(..) | Def::SelfTy(..) |
|
||||
Def::Def(DefKind::Variant, vid) => self.variant_with_id(vid),
|
||||
Def::Def(DefKind::Ctor(..), cid) => self.variant_with_ctor_id(cid),
|
||||
Def::Def(DefKind::Struct, _) | Def::Def(DefKind::Union, _) |
|
||||
Def::Def(DefKind::TyAlias, _) | Def::Def(DefKind::AssociatedTy, _) | Def::SelfTy(..) |
|
||||
Def::SelfCtor(..) => self.non_enum_variant(),
|
||||
_ => bug!("unexpected def {:?} in variant_of_def", def)
|
||||
}
|
||||
|
|
@ -2806,7 +2806,9 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
|||
}
|
||||
} else {
|
||||
match self.describe_def(def_id).expect("no def for def-id") {
|
||||
Def::AssociatedConst(_) | Def::Method(_) | Def::AssociatedTy(_) => true,
|
||||
Def::Def(DefKind::AssociatedConst, _)
|
||||
| Def::Def(DefKind::Method, _)
|
||||
| Def::Def(DefKind::AssociatedTy, _) => true,
|
||||
_ => false,
|
||||
}
|
||||
};
|
||||
|
|
@ -2952,19 +2954,19 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
|||
/// or variant or their constructors, panics otherwise.
|
||||
pub fn expect_variant_def(self, def: Def) -> &'tcx VariantDef {
|
||||
match def {
|
||||
Def::Variant(did) => {
|
||||
Def::Def(DefKind::Variant, did) => {
|
||||
let enum_did = self.parent(did).unwrap();
|
||||
self.adt_def(enum_did).variant_with_id(did)
|
||||
}
|
||||
Def::Struct(did) | Def::Union(did) => {
|
||||
Def::Def(DefKind::Struct, did) | Def::Def(DefKind::Union, did) => {
|
||||
self.adt_def(did).non_enum_variant()
|
||||
}
|
||||
Def::Ctor(variant_ctor_did, CtorOf::Variant, ..) => {
|
||||
Def::Def(DefKind::Ctor(CtorOf::Variant, ..), variant_ctor_did) => {
|
||||
let variant_did = self.parent(variant_ctor_did).unwrap();
|
||||
let enum_did = self.parent(variant_did).unwrap();
|
||||
self.adt_def(enum_did).variant_with_ctor_id(variant_ctor_did)
|
||||
}
|
||||
Def::Ctor(ctor_did, CtorOf::Struct, ..) => {
|
||||
Def::Def(DefKind::Ctor(CtorOf::Struct, ..), ctor_did) => {
|
||||
let struct_did = self.parent(ctor_did).expect("struct ctor has no parent");
|
||||
self.adt_def(struct_did).non_enum_variant()
|
||||
}
|
||||
|
|
@ -3044,7 +3046,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
|||
/// `DefId` of the impl that the method belongs to; otherwise, returns `None`.
|
||||
pub fn impl_of_method(self, def_id: DefId) -> Option<DefId> {
|
||||
let item = if def_id.krate != LOCAL_CRATE {
|
||||
if let Some(Def::Method(_)) = self.describe_def(def_id) {
|
||||
if let Some(Def::Def(DefKind::Method, _)) = self.describe_def(def_id) {
|
||||
Some(self.associated_item(def_id))
|
||||
} else {
|
||||
None
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue