rustc: Harmonize DefKind
and DefPathData
`DefPathData::(ClosureExpr,ImplTrait)` are renamed to match `DefKind::(Closure,OpaqueTy)`. `DefPathData::ImplTraitAssocTy` is replaced with `DefPathData::TypeNS(kw::Empty)` because both correspond to `DefKind::AssocTy`. It's possible that introducing `(DefKind,DefPathData)::AssocOpaqueTy` could be a better solution, but that would be a much more invasive change. Const generic parameters introduced for effects are moved from `DefPathData::TypeNS` to `DefPathData::ValueNS`, because constants are values. `DefPathData` is no longer passed to `create_def` functions to avoid redundancy.
This commit is contained in:
parent
7ceaf19868
commit
17e799c270
17 changed files with 133 additions and 132 deletions
|
@ -14,8 +14,8 @@ use rustc_ast::*;
|
||||||
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap};
|
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap};
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::def::{DefKind, Res};
|
use rustc_hir::def::{DefKind, Res};
|
||||||
use rustc_hir::definitions::DefPathData;
|
|
||||||
use rustc_session::parse::feature_err;
|
use rustc_session::parse::feature_err;
|
||||||
|
use rustc_span::symbol::kw;
|
||||||
use rustc_span::{sym, Span};
|
use rustc_span::{sym, Span};
|
||||||
use rustc_target::asm;
|
use rustc_target::asm;
|
||||||
use std::collections::hash_map::Entry;
|
use std::collections::hash_map::Entry;
|
||||||
|
@ -227,7 +227,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
self.create_def(
|
self.create_def(
|
||||||
parent_def_id.def_id,
|
parent_def_id.def_id,
|
||||||
node_id,
|
node_id,
|
||||||
DefPathData::AnonConst,
|
kw::Empty,
|
||||||
DefKind::AnonConst,
|
DefKind::AnonConst,
|
||||||
*op_sp,
|
*op_sp,
|
||||||
);
|
);
|
||||||
|
|
|
@ -13,10 +13,9 @@ use rustc_ast::*;
|
||||||
use rustc_data_structures::stack::ensure_sufficient_stack;
|
use rustc_data_structures::stack::ensure_sufficient_stack;
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::def::{DefKind, Res};
|
use rustc_hir::def::{DefKind, Res};
|
||||||
use rustc_hir::definitions::DefPathData;
|
|
||||||
use rustc_session::errors::report_lit_error;
|
use rustc_session::errors::report_lit_error;
|
||||||
use rustc_span::source_map::{respan, Spanned};
|
use rustc_span::source_map::{respan, Spanned};
|
||||||
use rustc_span::symbol::{sym, Ident, Symbol};
|
use rustc_span::symbol::{kw, sym, Ident, Symbol};
|
||||||
use rustc_span::DUMMY_SP;
|
use rustc_span::DUMMY_SP;
|
||||||
use rustc_span::{DesugaringKind, Span};
|
use rustc_span::{DesugaringKind, Span};
|
||||||
use thin_vec::{thin_vec, ThinVec};
|
use thin_vec::{thin_vec, ThinVec};
|
||||||
|
@ -376,7 +375,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||||
self.create_def(
|
self.create_def(
|
||||||
parent_def_id.def_id,
|
parent_def_id.def_id,
|
||||||
node_id,
|
node_id,
|
||||||
DefPathData::AnonConst,
|
kw::Empty,
|
||||||
DefKind::AnonConst,
|
DefKind::AnonConst,
|
||||||
f.span,
|
f.span,
|
||||||
);
|
);
|
||||||
|
|
|
@ -3,7 +3,6 @@ use super::ResolverAstLoweringExt;
|
||||||
use super::{AstOwner, ImplTraitContext, ImplTraitPosition};
|
use super::{AstOwner, ImplTraitContext, ImplTraitPosition};
|
||||||
use super::{FnDeclKind, LoweringContext, ParamMode};
|
use super::{FnDeclKind, LoweringContext, ParamMode};
|
||||||
|
|
||||||
use hir::definitions::DefPathData;
|
|
||||||
use rustc_ast::ptr::P;
|
use rustc_ast::ptr::P;
|
||||||
use rustc_ast::visit::AssocCtxt;
|
use rustc_ast::visit::AssocCtxt;
|
||||||
use rustc_ast::*;
|
use rustc_ast::*;
|
||||||
|
@ -1367,7 +1366,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||||
let def_id = self.create_def(
|
let def_id = self.create_def(
|
||||||
self.local_def_id(parent_node_id),
|
self.local_def_id(parent_node_id),
|
||||||
param_node_id,
|
param_node_id,
|
||||||
DefPathData::TypeNs(sym::host),
|
sym::host,
|
||||||
DefKind::ConstParam,
|
DefKind::ConstParam,
|
||||||
span,
|
span,
|
||||||
);
|
);
|
||||||
|
@ -1427,13 +1426,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||||
|
|
||||||
if let Some((span, hir_id, def_id)) = host_param_parts {
|
if let Some((span, hir_id, def_id)) = host_param_parts {
|
||||||
let const_node_id = self.next_node_id();
|
let const_node_id = self.next_node_id();
|
||||||
let anon_const = self.create_def(
|
let anon_const =
|
||||||
def_id,
|
self.create_def(def_id, const_node_id, kw::Empty, DefKind::AnonConst, span);
|
||||||
const_node_id,
|
|
||||||
DefPathData::AnonConst,
|
|
||||||
DefKind::AnonConst,
|
|
||||||
span,
|
|
||||||
);
|
|
||||||
|
|
||||||
let const_id = self.next_id();
|
let const_id = self.next_id();
|
||||||
let const_expr_id = self.next_id();
|
let const_expr_id = self.next_id();
|
||||||
|
|
|
@ -58,7 +58,6 @@ use rustc_errors::{DiagnosticArgFromDisplay, StashKey};
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::def::{DefKind, LifetimeRes, Namespace, PartialRes, PerNS, Res};
|
use rustc_hir::def::{DefKind, LifetimeRes, Namespace, PartialRes, PerNS, Res};
|
||||||
use rustc_hir::def_id::{LocalDefId, CRATE_DEF_ID, LOCAL_CRATE};
|
use rustc_hir::def_id::{LocalDefId, CRATE_DEF_ID, LOCAL_CRATE};
|
||||||
use rustc_hir::definitions::DefPathData;
|
|
||||||
use rustc_hir::{ConstArg, GenericArg, ItemLocalId, ParamName, TraitCandidate};
|
use rustc_hir::{ConstArg, GenericArg, ItemLocalId, ParamName, TraitCandidate};
|
||||||
use rustc_index::{Idx, IndexSlice, IndexVec};
|
use rustc_index::{Idx, IndexSlice, IndexVec};
|
||||||
use rustc_middle::{
|
use rustc_middle::{
|
||||||
|
@ -499,20 +498,20 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
&mut self,
|
&mut self,
|
||||||
parent: LocalDefId,
|
parent: LocalDefId,
|
||||||
node_id: ast::NodeId,
|
node_id: ast::NodeId,
|
||||||
data: DefPathData,
|
name: Symbol,
|
||||||
def_kind: DefKind,
|
def_kind: DefKind,
|
||||||
span: Span,
|
span: Span,
|
||||||
) -> LocalDefId {
|
) -> LocalDefId {
|
||||||
debug_assert_ne!(node_id, ast::DUMMY_NODE_ID);
|
debug_assert_ne!(node_id, ast::DUMMY_NODE_ID);
|
||||||
assert!(
|
assert!(
|
||||||
self.opt_local_def_id(node_id).is_none(),
|
self.opt_local_def_id(node_id).is_none(),
|
||||||
"adding a def'n for node-id {:?} and data {:?} but a previous def'n exists: {:?}",
|
"adding a def'n for node-id {:?} and def kind {:?} but a previous def'n exists: {:?}",
|
||||||
node_id,
|
node_id,
|
||||||
data,
|
def_kind,
|
||||||
self.tcx.hir().def_key(self.local_def_id(node_id)),
|
self.tcx.hir().def_key(self.local_def_id(node_id)),
|
||||||
);
|
);
|
||||||
|
|
||||||
let def_id = self.tcx.at(span).create_def(parent, data, def_kind).def_id();
|
let def_id = self.tcx.at(span).create_def(parent, name, def_kind).def_id();
|
||||||
|
|
||||||
debug!("create_def: def_id_to_node_id[{:?}] <-> {:?}", def_id, node_id);
|
debug!("create_def: def_id_to_node_id[{:?}] <-> {:?}", def_id, node_id);
|
||||||
self.resolver.node_id_to_def_id.insert(node_id, def_id);
|
self.resolver.node_id_to_def_id.insert(node_id, def_id);
|
||||||
|
@ -809,7 +808,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
let _def_id = self.create_def(
|
let _def_id = self.create_def(
|
||||||
self.current_hir_id_owner.def_id,
|
self.current_hir_id_owner.def_id,
|
||||||
param,
|
param,
|
||||||
DefPathData::LifetimeNs(kw::UnderscoreLifetime),
|
kw::UnderscoreLifetime,
|
||||||
DefKind::LifetimeParam,
|
DefKind::LifetimeParam,
|
||||||
ident.span,
|
ident.span,
|
||||||
);
|
);
|
||||||
|
@ -1227,7 +1226,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
let def_id = self.create_def(
|
let def_id = self.create_def(
|
||||||
parent_def_id.def_id,
|
parent_def_id.def_id,
|
||||||
node_id,
|
node_id,
|
||||||
DefPathData::AnonConst,
|
kw::Empty,
|
||||||
DefKind::AnonConst,
|
DefKind::AnonConst,
|
||||||
span,
|
span,
|
||||||
);
|
);
|
||||||
|
@ -1465,7 +1464,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
self.create_def(
|
self.create_def(
|
||||||
self.current_hir_id_owner.def_id,
|
self.current_hir_id_owner.def_id,
|
||||||
*def_node_id,
|
*def_node_id,
|
||||||
DefPathData::TypeNs(ident.name),
|
ident.name,
|
||||||
DefKind::TyParam,
|
DefKind::TyParam,
|
||||||
span,
|
span,
|
||||||
);
|
);
|
||||||
|
@ -1619,7 +1618,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
let opaque_ty_def_id = self.create_def(
|
let opaque_ty_def_id = self.create_def(
|
||||||
self.current_hir_id_owner.def_id,
|
self.current_hir_id_owner.def_id,
|
||||||
opaque_ty_node_id,
|
opaque_ty_node_id,
|
||||||
DefPathData::ImplTrait,
|
kw::Empty,
|
||||||
DefKind::OpaqueTy,
|
DefKind::OpaqueTy,
|
||||||
opaque_ty_span,
|
opaque_ty_span,
|
||||||
);
|
);
|
||||||
|
@ -1674,7 +1673,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
let duplicated_lifetime_def_id = self.create_def(
|
let duplicated_lifetime_def_id = self.create_def(
|
||||||
opaque_ty_def_id,
|
opaque_ty_def_id,
|
||||||
duplicated_lifetime_node_id,
|
duplicated_lifetime_node_id,
|
||||||
DefPathData::LifetimeNs(lifetime.ident.name),
|
lifetime.ident.name,
|
||||||
DefKind::LifetimeParam,
|
DefKind::LifetimeParam,
|
||||||
lifetime.ident.span,
|
lifetime.ident.span,
|
||||||
);
|
);
|
||||||
|
@ -2549,7 +2548,7 @@ impl<'hir> GenericArgsCtor<'hir> {
|
||||||
let def_id = lcx.create_def(
|
let def_id = lcx.create_def(
|
||||||
lcx.current_hir_id_owner.def_id,
|
lcx.current_hir_id_owner.def_id,
|
||||||
id,
|
id,
|
||||||
DefPathData::AnonConst,
|
kw::Empty,
|
||||||
DefKind::AnonConst,
|
DefKind::AnonConst,
|
||||||
span,
|
span,
|
||||||
);
|
);
|
||||||
|
|
|
@ -594,7 +594,7 @@ fn push_unqualified_item_name(
|
||||||
DefPathData::CrateRoot => {
|
DefPathData::CrateRoot => {
|
||||||
output.push_str(tcx.crate_name(def_id.krate).as_str());
|
output.push_str(tcx.crate_name(def_id.krate).as_str());
|
||||||
}
|
}
|
||||||
DefPathData::ClosureExpr => {
|
DefPathData::Closure => {
|
||||||
let label = coroutine_kind_label(tcx.coroutine_kind(def_id));
|
let label = coroutine_kind_label(tcx.coroutine_kind(def_id));
|
||||||
|
|
||||||
push_disambiguated_special_name(
|
push_disambiguated_special_name(
|
||||||
|
|
|
@ -282,9 +282,7 @@ impl<'mir, 'tcx, Prov: Provenance, Extra> Frame<'mir, 'tcx, Prov, Extra> {
|
||||||
impl<'tcx> fmt::Display for FrameInfo<'tcx> {
|
impl<'tcx> fmt::Display for FrameInfo<'tcx> {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
ty::tls::with(|tcx| {
|
ty::tls::with(|tcx| {
|
||||||
if tcx.def_key(self.instance.def_id()).disambiguated_data.data
|
if tcx.def_key(self.instance.def_id()).disambiguated_data.data == DefPathData::Closure {
|
||||||
== DefPathData::ClosureExpr
|
|
||||||
{
|
|
||||||
write!(f, "inside closure")
|
write!(f, "inside closure")
|
||||||
} else {
|
} else {
|
||||||
// Note: this triggers a `good_path_delayed_bug` state, which means that if we ever
|
// Note: this triggers a `good_path_delayed_bug` state, which means that if we ever
|
||||||
|
@ -299,7 +297,7 @@ impl<'tcx> fmt::Display for FrameInfo<'tcx> {
|
||||||
impl<'tcx> FrameInfo<'tcx> {
|
impl<'tcx> FrameInfo<'tcx> {
|
||||||
pub fn as_note(&self, tcx: TyCtxt<'tcx>) -> errors::FrameNote {
|
pub fn as_note(&self, tcx: TyCtxt<'tcx>) -> errors::FrameNote {
|
||||||
let span = self.span;
|
let span = self.span;
|
||||||
if tcx.def_key(self.instance.def_id()).disambiguated_data.data == DefPathData::ClosureExpr {
|
if tcx.def_key(self.instance.def_id()).disambiguated_data.data == DefPathData::Closure {
|
||||||
errors::FrameNote { where_: "closure", span, instance: String::new(), times: 0 }
|
errors::FrameNote { where_: "closure", span, instance: String::new(), times: 0 }
|
||||||
} else {
|
} else {
|
||||||
let instance = format!("{}", self.instance);
|
let instance = format!("{}", self.instance);
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
use crate::definitions::DefPathData;
|
||||||
use crate::hir;
|
use crate::hir;
|
||||||
|
|
||||||
use rustc_ast as ast;
|
use rustc_ast as ast;
|
||||||
|
@ -45,6 +46,7 @@ pub enum NonMacroAttrKind {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// What kind of definition something is; e.g., `mod` vs `struct`.
|
/// What kind of definition something is; e.g., `mod` vs `struct`.
|
||||||
|
/// `enum DefPathData` may need to be updated if a new variant is added here.
|
||||||
#[derive(Clone, Copy, PartialEq, Eq, Encodable, Decodable, Hash, Debug, HashStable_Generic)]
|
#[derive(Clone, Copy, PartialEq, Eq, Encodable, Decodable, Hash, Debug, HashStable_Generic)]
|
||||||
pub enum DefKind {
|
pub enum DefKind {
|
||||||
// Type namespace
|
// Type namespace
|
||||||
|
@ -221,6 +223,41 @@ impl DefKind {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn def_path_data(self, name: Symbol) -> DefPathData {
|
||||||
|
match self {
|
||||||
|
DefKind::Mod
|
||||||
|
| DefKind::Struct
|
||||||
|
| DefKind::Union
|
||||||
|
| DefKind::Enum
|
||||||
|
| DefKind::Variant
|
||||||
|
| DefKind::Trait
|
||||||
|
| DefKind::TyAlias
|
||||||
|
| DefKind::ForeignTy
|
||||||
|
| DefKind::TraitAlias
|
||||||
|
| DefKind::AssocTy
|
||||||
|
| DefKind::TyParam
|
||||||
|
| DefKind::ExternCrate => DefPathData::TypeNs(name),
|
||||||
|
DefKind::Fn
|
||||||
|
| DefKind::Const
|
||||||
|
| DefKind::ConstParam
|
||||||
|
| DefKind::Static(..)
|
||||||
|
| DefKind::AssocFn
|
||||||
|
| DefKind::AssocConst
|
||||||
|
| DefKind::Field => DefPathData::ValueNs(name),
|
||||||
|
DefKind::Macro(..) => DefPathData::MacroNs(name),
|
||||||
|
DefKind::LifetimeParam => DefPathData::LifetimeNs(name),
|
||||||
|
DefKind::Ctor(..) => DefPathData::Ctor,
|
||||||
|
DefKind::Use => DefPathData::Use,
|
||||||
|
DefKind::ForeignMod => DefPathData::ForeignMod,
|
||||||
|
DefKind::AnonConst => DefPathData::AnonConst,
|
||||||
|
DefKind::InlineConst => DefPathData::AnonConst,
|
||||||
|
DefKind::OpaqueTy => DefPathData::OpaqueTy,
|
||||||
|
DefKind::GlobalAsm => DefPathData::GlobalAsm,
|
||||||
|
DefKind::Impl { .. } => DefPathData::Impl,
|
||||||
|
DefKind::Closure => DefPathData::Closure,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn is_fn_like(self) -> bool {
|
pub fn is_fn_like(self) -> bool {
|
||||||
matches!(self, DefKind::Fn | DefKind::AssocFn | DefKind::Closure)
|
matches!(self, DefKind::Fn | DefKind::AssocFn | DefKind::Closure)
|
||||||
|
|
|
@ -246,6 +246,7 @@ impl DefPath {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// New variants should only be added in synchronization with `enum DefKind`.
|
||||||
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Encodable, Decodable)]
|
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Encodable, Decodable)]
|
||||||
pub enum DefPathData {
|
pub enum DefPathData {
|
||||||
// Root: these should only be used for the root nodes, because
|
// Root: these should only be used for the root nodes, because
|
||||||
|
@ -271,7 +272,7 @@ pub enum DefPathData {
|
||||||
/// Something in the lifetime namespace.
|
/// Something in the lifetime namespace.
|
||||||
LifetimeNs(Symbol),
|
LifetimeNs(Symbol),
|
||||||
/// A closure expression.
|
/// A closure expression.
|
||||||
ClosureExpr,
|
Closure,
|
||||||
|
|
||||||
// Subportions of items:
|
// Subportions of items:
|
||||||
/// Implicit constructor for a unit or tuple-like struct or enum variant.
|
/// Implicit constructor for a unit or tuple-like struct or enum variant.
|
||||||
|
@ -280,9 +281,7 @@ pub enum DefPathData {
|
||||||
AnonConst,
|
AnonConst,
|
||||||
/// An existential `impl Trait` type node.
|
/// An existential `impl Trait` type node.
|
||||||
/// Argument position `impl Trait` have a `TypeNs` with their pretty-printed name.
|
/// Argument position `impl Trait` have a `TypeNs` with their pretty-printed name.
|
||||||
ImplTrait,
|
OpaqueTy,
|
||||||
/// `impl Trait` generated associated type node.
|
|
||||||
ImplTraitAssocTy,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Definitions {
|
impl Definitions {
|
||||||
|
@ -403,16 +402,17 @@ impl DefPathData {
|
||||||
pub fn get_opt_name(&self) -> Option<Symbol> {
|
pub fn get_opt_name(&self) -> Option<Symbol> {
|
||||||
use self::DefPathData::*;
|
use self::DefPathData::*;
|
||||||
match *self {
|
match *self {
|
||||||
|
TypeNs(name) if name == kw::Empty => None,
|
||||||
TypeNs(name) | ValueNs(name) | MacroNs(name) | LifetimeNs(name) => Some(name),
|
TypeNs(name) | ValueNs(name) | MacroNs(name) | LifetimeNs(name) => Some(name),
|
||||||
|
Impl | ForeignMod | CrateRoot | Use | GlobalAsm | Closure | Ctor | AnonConst
|
||||||
Impl | ForeignMod | CrateRoot | Use | GlobalAsm | ClosureExpr | Ctor | AnonConst
|
| OpaqueTy => None,
|
||||||
| ImplTrait | ImplTraitAssocTy => None,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn name(&self) -> DefPathDataName {
|
pub fn name(&self) -> DefPathDataName {
|
||||||
use self::DefPathData::*;
|
use self::DefPathData::*;
|
||||||
match *self {
|
match *self {
|
||||||
|
TypeNs(name) if name == kw::Empty => DefPathDataName::Anon { namespace: sym::opaque },
|
||||||
TypeNs(name) | ValueNs(name) | MacroNs(name) | LifetimeNs(name) => {
|
TypeNs(name) | ValueNs(name) | MacroNs(name) | LifetimeNs(name) => {
|
||||||
DefPathDataName::Named(name)
|
DefPathDataName::Named(name)
|
||||||
}
|
}
|
||||||
|
@ -422,10 +422,10 @@ impl DefPathData {
|
||||||
ForeignMod => DefPathDataName::Anon { namespace: kw::Extern },
|
ForeignMod => DefPathDataName::Anon { namespace: kw::Extern },
|
||||||
Use => DefPathDataName::Anon { namespace: kw::Use },
|
Use => DefPathDataName::Anon { namespace: kw::Use },
|
||||||
GlobalAsm => DefPathDataName::Anon { namespace: sym::global_asm },
|
GlobalAsm => DefPathDataName::Anon { namespace: sym::global_asm },
|
||||||
ClosureExpr => DefPathDataName::Anon { namespace: sym::closure },
|
Closure => DefPathDataName::Anon { namespace: sym::closure },
|
||||||
Ctor => DefPathDataName::Anon { namespace: sym::constructor },
|
Ctor => DefPathDataName::Anon { namespace: sym::constructor },
|
||||||
AnonConst => DefPathDataName::Anon { namespace: sym::constant },
|
AnonConst => DefPathDataName::Anon { namespace: sym::constant },
|
||||||
ImplTrait | ImplTraitAssocTy => DefPathDataName::Anon { namespace: sym::opaque },
|
OpaqueTy => DefPathDataName::Anon { namespace: sym::opaque },
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -977,7 +977,7 @@ impl<'tcx> TyCtxtAt<'tcx> {
|
||||||
pub fn create_def(
|
pub fn create_def(
|
||||||
self,
|
self,
|
||||||
parent: LocalDefId,
|
parent: LocalDefId,
|
||||||
data: hir::definitions::DefPathData,
|
name: Symbol,
|
||||||
def_kind: DefKind,
|
def_kind: DefKind,
|
||||||
) -> TyCtxtFeed<'tcx, LocalDefId> {
|
) -> TyCtxtFeed<'tcx, LocalDefId> {
|
||||||
// This function modifies `self.definitions` using a side-effect.
|
// This function modifies `self.definitions` using a side-effect.
|
||||||
|
@ -1000,6 +1000,7 @@ impl<'tcx> TyCtxtAt<'tcx> {
|
||||||
// This is fine because:
|
// This is fine because:
|
||||||
// - those queries are `eval_always` so we won't miss their result changing;
|
// - those queries are `eval_always` so we won't miss their result changing;
|
||||||
// - this write will have happened before these queries are called.
|
// - this write will have happened before these queries are called.
|
||||||
|
let data = def_kind.def_path_data(name);
|
||||||
let key = self.untracked.definitions.write().create_def(parent, data);
|
let key = self.untracked.definitions.write().create_def(parent, data);
|
||||||
|
|
||||||
let feed = TyCtxtFeed { tcx: self.tcx, key };
|
let feed = TyCtxtFeed { tcx: self.tcx, key };
|
||||||
|
|
|
@ -215,7 +215,7 @@ impl<'tcx> InstanceDef<'tcx> {
|
||||||
};
|
};
|
||||||
matches!(
|
matches!(
|
||||||
tcx.def_key(def_id).disambiguated_data.data,
|
tcx.def_key(def_id).disambiguated_data.data,
|
||||||
DefPathData::Ctor | DefPathData::ClosureExpr
|
DefPathData::Ctor | DefPathData::Closure
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -131,7 +131,7 @@ pub trait Printer<'tcx>: Sized {
|
||||||
|
|
||||||
match key.disambiguated_data.data {
|
match key.disambiguated_data.data {
|
||||||
// Closures' own generics are only captures, don't print them.
|
// Closures' own generics are only captures, don't print them.
|
||||||
DefPathData::ClosureExpr => {}
|
DefPathData::Closure => {}
|
||||||
// This covers both `DefKind::AnonConst` and `DefKind::InlineConst`.
|
// This covers both `DefKind::AnonConst` and `DefKind::InlineConst`.
|
||||||
// Anon consts doesn't have their own generics, and inline consts' own
|
// Anon consts doesn't have their own generics, and inline consts' own
|
||||||
// generics are their inferred types, so don't print them.
|
// generics are their inferred types, so don't print them.
|
||||||
|
|
|
@ -1804,13 +1804,13 @@ impl<'a, 'tcx> FmtPrinter<'a, 'tcx> {
|
||||||
// (but also some things just print a `DefId` generally so maybe we need this?)
|
// (but also some things just print a `DefId` generally so maybe we need this?)
|
||||||
fn guess_def_namespace(tcx: TyCtxt<'_>, def_id: DefId) -> Namespace {
|
fn guess_def_namespace(tcx: TyCtxt<'_>, def_id: DefId) -> Namespace {
|
||||||
match tcx.def_key(def_id).disambiguated_data.data {
|
match tcx.def_key(def_id).disambiguated_data.data {
|
||||||
DefPathData::TypeNs(..) | DefPathData::CrateRoot | DefPathData::ImplTrait => {
|
DefPathData::TypeNs(..) | DefPathData::CrateRoot | DefPathData::OpaqueTy => {
|
||||||
Namespace::TypeNS
|
Namespace::TypeNS
|
||||||
}
|
}
|
||||||
|
|
||||||
DefPathData::ValueNs(..)
|
DefPathData::ValueNs(..)
|
||||||
| DefPathData::AnonConst
|
| DefPathData::AnonConst
|
||||||
| DefPathData::ClosureExpr
|
| DefPathData::Closure
|
||||||
| DefPathData::Ctor => Namespace::ValueNS,
|
| DefPathData::Ctor => Namespace::ValueNS,
|
||||||
|
|
||||||
DefPathData::MacroNs(..) => Namespace::MacroNS,
|
DefPathData::MacroNs(..) => Namespace::MacroNS,
|
||||||
|
|
|
@ -4,9 +4,8 @@ use rustc_ast::*;
|
||||||
use rustc_expand::expand::AstFragment;
|
use rustc_expand::expand::AstFragment;
|
||||||
use rustc_hir::def::{CtorKind, CtorOf, DefKind};
|
use rustc_hir::def::{CtorKind, CtorOf, DefKind};
|
||||||
use rustc_hir::def_id::LocalDefId;
|
use rustc_hir::def_id::LocalDefId;
|
||||||
use rustc_hir::definitions::*;
|
|
||||||
use rustc_span::hygiene::LocalExpnId;
|
use rustc_span::hygiene::LocalExpnId;
|
||||||
use rustc_span::symbol::sym;
|
use rustc_span::symbol::{kw, sym, Symbol};
|
||||||
use rustc_span::Span;
|
use rustc_span::Span;
|
||||||
|
|
||||||
pub(crate) fn collect_definitions(
|
pub(crate) fn collect_definitions(
|
||||||
|
@ -30,16 +29,19 @@ impl<'a, 'b, 'tcx> DefCollector<'a, 'b, 'tcx> {
|
||||||
fn create_def(
|
fn create_def(
|
||||||
&mut self,
|
&mut self,
|
||||||
node_id: NodeId,
|
node_id: NodeId,
|
||||||
data: DefPathData,
|
name: Symbol,
|
||||||
def_kind: DefKind,
|
def_kind: DefKind,
|
||||||
span: Span,
|
span: Span,
|
||||||
) -> LocalDefId {
|
) -> LocalDefId {
|
||||||
let parent_def = self.parent_def;
|
let parent_def = self.parent_def;
|
||||||
debug!("create_def(node_id={:?}, data={:?}, parent_def={:?})", node_id, data, parent_def);
|
debug!(
|
||||||
|
"create_def(node_id={:?}, def_kind={:?}, parent_def={:?})",
|
||||||
|
node_id, def_kind, parent_def
|
||||||
|
);
|
||||||
self.resolver.create_def(
|
self.resolver.create_def(
|
||||||
parent_def,
|
parent_def,
|
||||||
node_id,
|
node_id,
|
||||||
data,
|
name,
|
||||||
def_kind,
|
def_kind,
|
||||||
self.expansion.to_expn_id(),
|
self.expansion.to_expn_id(),
|
||||||
span.with_parent(None),
|
span.with_parent(None),
|
||||||
|
@ -76,8 +78,7 @@ impl<'a, 'b, 'tcx> DefCollector<'a, 'b, 'tcx> {
|
||||||
self.visit_macro_invoc(field.id);
|
self.visit_macro_invoc(field.id);
|
||||||
} else {
|
} else {
|
||||||
let name = field.ident.map_or_else(|| sym::integer(index(self)), |ident| ident.name);
|
let name = field.ident.map_or_else(|| sym::integer(index(self)), |ident| ident.name);
|
||||||
let def =
|
let def = self.create_def(field.id, name, DefKind::Field, field.span);
|
||||||
self.create_def(field.id, DefPathData::ValueNs(name), DefKind::Field, field.span);
|
|
||||||
self.with_parent(def, |this| visit::walk_field_def(this, field));
|
self.with_parent(def, |this| visit::walk_field_def(this, field));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -97,40 +98,36 @@ impl<'a, 'b, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'b, 'tcx> {
|
||||||
// Pick the def data. This need not be unique, but the more
|
// Pick the def data. This need not be unique, but the more
|
||||||
// information we encapsulate into, the better
|
// information we encapsulate into, the better
|
||||||
let mut opt_macro_data = None;
|
let mut opt_macro_data = None;
|
||||||
let ty_data = DefPathData::TypeNs(i.ident.name);
|
let def_kind = match &i.kind {
|
||||||
let value_data = DefPathData::ValueNs(i.ident.name);
|
ItemKind::Impl(i) => DefKind::Impl { of_trait: i.of_trait.is_some() },
|
||||||
let (def_data, def_kind) = match &i.kind {
|
ItemKind::ForeignMod(..) => DefKind::ForeignMod,
|
||||||
ItemKind::Impl(i) => {
|
ItemKind::Mod(..) => DefKind::Mod,
|
||||||
(DefPathData::Impl, DefKind::Impl { of_trait: i.of_trait.is_some() })
|
ItemKind::Trait(..) => DefKind::Trait,
|
||||||
}
|
ItemKind::TraitAlias(..) => DefKind::TraitAlias,
|
||||||
ItemKind::ForeignMod(..) => (DefPathData::ForeignMod, DefKind::ForeignMod),
|
ItemKind::Enum(..) => DefKind::Enum,
|
||||||
ItemKind::Mod(..) => (ty_data, DefKind::Mod),
|
ItemKind::Struct(..) => DefKind::Struct,
|
||||||
ItemKind::Trait(..) => (ty_data, DefKind::Trait),
|
ItemKind::Union(..) => DefKind::Union,
|
||||||
ItemKind::TraitAlias(..) => (ty_data, DefKind::TraitAlias),
|
ItemKind::ExternCrate(..) => DefKind::ExternCrate,
|
||||||
ItemKind::Enum(..) => (ty_data, DefKind::Enum),
|
ItemKind::TyAlias(..) => DefKind::TyAlias,
|
||||||
ItemKind::Struct(..) => (ty_data, DefKind::Struct),
|
ItemKind::Static(s) => DefKind::Static(s.mutability),
|
||||||
ItemKind::Union(..) => (ty_data, DefKind::Union),
|
ItemKind::Const(..) => DefKind::Const,
|
||||||
ItemKind::ExternCrate(..) => (ty_data, DefKind::ExternCrate),
|
ItemKind::Fn(..) => DefKind::Fn,
|
||||||
ItemKind::TyAlias(..) => (ty_data, DefKind::TyAlias),
|
|
||||||
ItemKind::Static(s) => (value_data, DefKind::Static(s.mutability)),
|
|
||||||
ItemKind::Const(..) => (value_data, DefKind::Const),
|
|
||||||
ItemKind::Fn(..) => (value_data, DefKind::Fn),
|
|
||||||
ItemKind::MacroDef(..) => {
|
ItemKind::MacroDef(..) => {
|
||||||
let macro_data = self.resolver.compile_macro(i, self.resolver.tcx.sess.edition());
|
let macro_data = self.resolver.compile_macro(i, self.resolver.tcx.sess.edition());
|
||||||
let macro_kind = macro_data.ext.macro_kind();
|
let macro_kind = macro_data.ext.macro_kind();
|
||||||
opt_macro_data = Some(macro_data);
|
opt_macro_data = Some(macro_data);
|
||||||
(DefPathData::MacroNs(i.ident.name), DefKind::Macro(macro_kind))
|
DefKind::Macro(macro_kind)
|
||||||
}
|
}
|
||||||
ItemKind::MacCall(..) => {
|
ItemKind::MacCall(..) => {
|
||||||
visit::walk_item(self, i);
|
visit::walk_item(self, i);
|
||||||
return self.visit_macro_invoc(i.id);
|
return self.visit_macro_invoc(i.id);
|
||||||
}
|
}
|
||||||
ItemKind::GlobalAsm(..) => (DefPathData::GlobalAsm, DefKind::GlobalAsm),
|
ItemKind::GlobalAsm(..) => DefKind::GlobalAsm,
|
||||||
ItemKind::Use(..) => {
|
ItemKind::Use(..) => {
|
||||||
return visit::walk_item(self, i);
|
return visit::walk_item(self, i);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let def_id = self.create_def(i.id, def_data, def_kind, i.span);
|
let def_id = self.create_def(i.id, i.ident.name, def_kind, i.span);
|
||||||
|
|
||||||
if let Some(macro_data) = opt_macro_data {
|
if let Some(macro_data) = opt_macro_data {
|
||||||
self.resolver.macro_map.insert(def_id.to_def_id(), macro_data);
|
self.resolver.macro_map.insert(def_id.to_def_id(), macro_data);
|
||||||
|
@ -144,7 +141,7 @@ impl<'a, 'b, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'b, 'tcx> {
|
||||||
if let Some((ctor_kind, ctor_node_id)) = CtorKind::from_ast(struct_def) {
|
if let Some((ctor_kind, ctor_node_id)) = CtorKind::from_ast(struct_def) {
|
||||||
this.create_def(
|
this.create_def(
|
||||||
ctor_node_id,
|
ctor_node_id,
|
||||||
DefPathData::Ctor,
|
kw::Empty,
|
||||||
DefKind::Ctor(CtorOf::Struct, ctor_kind),
|
DefKind::Ctor(CtorOf::Struct, ctor_kind),
|
||||||
i.span,
|
i.span,
|
||||||
);
|
);
|
||||||
|
@ -174,12 +171,8 @@ impl<'a, 'b, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'b, 'tcx> {
|
||||||
// then the closure_def will never be used, and we should avoid generating a
|
// then the closure_def will never be used, and we should avoid generating a
|
||||||
// def-id for it.
|
// def-id for it.
|
||||||
if let Some(body) = body {
|
if let Some(body) = body {
|
||||||
let closure_def = self.create_def(
|
let closure_def =
|
||||||
closure_id,
|
self.create_def(closure_id, kw::Empty, DefKind::Closure, span);
|
||||||
DefPathData::ClosureExpr,
|
|
||||||
DefKind::Closure,
|
|
||||||
span,
|
|
||||||
);
|
|
||||||
self.with_parent(closure_def, |this| this.visit_block(body));
|
self.with_parent(closure_def, |this| this.visit_block(body));
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
@ -190,21 +183,19 @@ impl<'a, 'b, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'b, 'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_use_tree(&mut self, use_tree: &'a UseTree, id: NodeId, _nested: bool) {
|
fn visit_use_tree(&mut self, use_tree: &'a UseTree, id: NodeId, _nested: bool) {
|
||||||
self.create_def(id, DefPathData::Use, DefKind::Use, use_tree.span);
|
self.create_def(id, kw::Empty, DefKind::Use, use_tree.span);
|
||||||
visit::walk_use_tree(self, use_tree, id);
|
visit::walk_use_tree(self, use_tree, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_foreign_item(&mut self, fi: &'a ForeignItem) {
|
fn visit_foreign_item(&mut self, fi: &'a ForeignItem) {
|
||||||
let (def_data, def_kind) = match fi.kind {
|
let def_kind = match fi.kind {
|
||||||
ForeignItemKind::Static(_, mt, _) => {
|
ForeignItemKind::Static(_, mt, _) => DefKind::Static(mt),
|
||||||
(DefPathData::ValueNs(fi.ident.name), DefKind::Static(mt))
|
ForeignItemKind::Fn(_) => DefKind::Fn,
|
||||||
}
|
ForeignItemKind::TyAlias(_) => DefKind::ForeignTy,
|
||||||
ForeignItemKind::Fn(_) => (DefPathData::ValueNs(fi.ident.name), DefKind::Fn),
|
|
||||||
ForeignItemKind::TyAlias(_) => (DefPathData::TypeNs(fi.ident.name), DefKind::ForeignTy),
|
|
||||||
ForeignItemKind::MacCall(_) => return self.visit_macro_invoc(fi.id),
|
ForeignItemKind::MacCall(_) => return self.visit_macro_invoc(fi.id),
|
||||||
};
|
};
|
||||||
|
|
||||||
let def = self.create_def(fi.id, def_data, def_kind, fi.span);
|
let def = self.create_def(fi.id, fi.ident.name, def_kind, fi.span);
|
||||||
|
|
||||||
self.with_parent(def, |this| visit::walk_foreign_item(this, fi));
|
self.with_parent(def, |this| visit::walk_foreign_item(this, fi));
|
||||||
}
|
}
|
||||||
|
@ -213,13 +204,12 @@ impl<'a, 'b, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'b, 'tcx> {
|
||||||
if v.is_placeholder {
|
if v.is_placeholder {
|
||||||
return self.visit_macro_invoc(v.id);
|
return self.visit_macro_invoc(v.id);
|
||||||
}
|
}
|
||||||
let def =
|
let def = self.create_def(v.id, v.ident.name, DefKind::Variant, v.span);
|
||||||
self.create_def(v.id, DefPathData::TypeNs(v.ident.name), DefKind::Variant, v.span);
|
|
||||||
self.with_parent(def, |this| {
|
self.with_parent(def, |this| {
|
||||||
if let Some((ctor_kind, ctor_node_id)) = CtorKind::from_ast(&v.data) {
|
if let Some((ctor_kind, ctor_node_id)) = CtorKind::from_ast(&v.data) {
|
||||||
this.create_def(
|
this.create_def(
|
||||||
ctor_node_id,
|
ctor_node_id,
|
||||||
DefPathData::Ctor,
|
kw::Empty,
|
||||||
DefKind::Ctor(CtorOf::Variant, ctor_kind),
|
DefKind::Ctor(CtorOf::Variant, ctor_kind),
|
||||||
v.span,
|
v.span,
|
||||||
);
|
);
|
||||||
|
@ -242,15 +232,12 @@ impl<'a, 'b, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'b, 'tcx> {
|
||||||
self.visit_macro_invoc(param.id);
|
self.visit_macro_invoc(param.id);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let name = param.ident.name;
|
let def_kind = match param.kind {
|
||||||
let (def_path_data, def_kind) = match param.kind {
|
GenericParamKind::Lifetime { .. } => DefKind::LifetimeParam,
|
||||||
GenericParamKind::Lifetime { .. } => {
|
GenericParamKind::Type { .. } => DefKind::TyParam,
|
||||||
(DefPathData::LifetimeNs(name), DefKind::LifetimeParam)
|
GenericParamKind::Const { .. } => DefKind::ConstParam,
|
||||||
}
|
|
||||||
GenericParamKind::Type { .. } => (DefPathData::TypeNs(name), DefKind::TyParam),
|
|
||||||
GenericParamKind::Const { .. } => (DefPathData::ValueNs(name), DefKind::ConstParam),
|
|
||||||
};
|
};
|
||||||
self.create_def(param.id, def_path_data, def_kind, param.ident.span);
|
self.create_def(param.id, param.ident.name, def_kind, param.ident.span);
|
||||||
|
|
||||||
// impl-Trait can happen inside generic parameters, like
|
// impl-Trait can happen inside generic parameters, like
|
||||||
// ```
|
// ```
|
||||||
|
@ -264,14 +251,14 @@ impl<'a, 'b, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'b, 'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_assoc_item(&mut self, i: &'a AssocItem, ctxt: visit::AssocCtxt) {
|
fn visit_assoc_item(&mut self, i: &'a AssocItem, ctxt: visit::AssocCtxt) {
|
||||||
let (def_data, def_kind) = match &i.kind {
|
let def_kind = match &i.kind {
|
||||||
AssocItemKind::Fn(..) => (DefPathData::ValueNs(i.ident.name), DefKind::AssocFn),
|
AssocItemKind::Fn(..) => DefKind::AssocFn,
|
||||||
AssocItemKind::Const(..) => (DefPathData::ValueNs(i.ident.name), DefKind::AssocConst),
|
AssocItemKind::Const(..) => DefKind::AssocConst,
|
||||||
AssocItemKind::Type(..) => (DefPathData::TypeNs(i.ident.name), DefKind::AssocTy),
|
AssocItemKind::Type(..) => DefKind::AssocTy,
|
||||||
AssocItemKind::MacCall(..) => return self.visit_macro_invoc(i.id),
|
AssocItemKind::MacCall(..) => return self.visit_macro_invoc(i.id),
|
||||||
};
|
};
|
||||||
|
|
||||||
let def = self.create_def(i.id, def_data, def_kind, i.span);
|
let def = self.create_def(i.id, i.ident.name, def_kind, i.span);
|
||||||
self.with_parent(def, |this| visit::walk_assoc_item(this, i, ctxt));
|
self.with_parent(def, |this| visit::walk_assoc_item(this, i, ctxt));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -283,12 +270,7 @@ impl<'a, 'b, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'b, 'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_anon_const(&mut self, constant: &'a AnonConst) {
|
fn visit_anon_const(&mut self, constant: &'a AnonConst) {
|
||||||
let def = self.create_def(
|
let def = self.create_def(constant.id, kw::Empty, DefKind::AnonConst, constant.value.span);
|
||||||
constant.id,
|
|
||||||
DefPathData::AnonConst,
|
|
||||||
DefKind::AnonConst,
|
|
||||||
constant.value.span,
|
|
||||||
);
|
|
||||||
self.with_parent(def, |this| visit::walk_anon_const(this, constant));
|
self.with_parent(def, |this| visit::walk_anon_const(this, constant));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -298,25 +280,21 @@ impl<'a, 'b, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'b, 'tcx> {
|
||||||
ExprKind::Closure(ref closure) => {
|
ExprKind::Closure(ref closure) => {
|
||||||
// Async closures desugar to closures inside of closures, so
|
// Async closures desugar to closures inside of closures, so
|
||||||
// we must create two defs.
|
// we must create two defs.
|
||||||
let closure_def =
|
let closure_def = self.create_def(expr.id, kw::Empty, DefKind::Closure, expr.span);
|
||||||
self.create_def(expr.id, DefPathData::ClosureExpr, DefKind::Closure, expr.span);
|
|
||||||
match closure.asyncness {
|
match closure.asyncness {
|
||||||
Async::Yes { closure_id, .. } => self.create_def(
|
Async::Yes { closure_id, .. } => {
|
||||||
closure_id,
|
self.create_def(closure_id, kw::Empty, DefKind::Closure, expr.span)
|
||||||
DefPathData::ClosureExpr,
|
}
|
||||||
DefKind::Closure,
|
|
||||||
expr.span,
|
|
||||||
),
|
|
||||||
Async::No => closure_def,
|
Async::No => closure_def,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ExprKind::Gen(_, _, _) => {
|
ExprKind::Gen(_, _, _) => {
|
||||||
self.create_def(expr.id, DefPathData::ClosureExpr, DefKind::Closure, expr.span)
|
self.create_def(expr.id, kw::Empty, DefKind::Closure, expr.span)
|
||||||
}
|
}
|
||||||
ExprKind::ConstBlock(ref constant) => {
|
ExprKind::ConstBlock(ref constant) => {
|
||||||
let def = self.create_def(
|
let def = self.create_def(
|
||||||
constant.id,
|
constant.id,
|
||||||
DefPathData::AnonConst,
|
kw::Empty,
|
||||||
DefKind::InlineConst,
|
DefKind::InlineConst,
|
||||||
constant.value.span,
|
constant.value.span,
|
||||||
);
|
);
|
||||||
|
|
|
@ -45,7 +45,6 @@ use rustc_hir::def::NonMacroAttrKind;
|
||||||
use rustc_hir::def::{self, CtorOf, DefKind, DocLinkResMap, LifetimeRes, PartialRes, PerNS};
|
use rustc_hir::def::{self, CtorOf, DefKind, DocLinkResMap, LifetimeRes, PartialRes, PerNS};
|
||||||
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, LocalDefIdMap, LocalDefIdSet};
|
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, LocalDefIdMap, LocalDefIdSet};
|
||||||
use rustc_hir::def_id::{CRATE_DEF_ID, LOCAL_CRATE};
|
use rustc_hir::def_id::{CRATE_DEF_ID, LOCAL_CRATE};
|
||||||
use rustc_hir::definitions::DefPathData;
|
|
||||||
use rustc_hir::{PrimTy, TraitCandidate};
|
use rustc_hir::{PrimTy, TraitCandidate};
|
||||||
use rustc_index::IndexVec;
|
use rustc_index::IndexVec;
|
||||||
use rustc_metadata::creader::{CStore, CrateLoader};
|
use rustc_metadata::creader::{CStore, CrateLoader};
|
||||||
|
@ -1212,11 +1211,12 @@ impl<'tcx> Resolver<'_, 'tcx> {
|
||||||
&mut self,
|
&mut self,
|
||||||
parent: LocalDefId,
|
parent: LocalDefId,
|
||||||
node_id: ast::NodeId,
|
node_id: ast::NodeId,
|
||||||
data: DefPathData,
|
name: Symbol,
|
||||||
def_kind: DefKind,
|
def_kind: DefKind,
|
||||||
expn_id: ExpnId,
|
expn_id: ExpnId,
|
||||||
span: Span,
|
span: Span,
|
||||||
) -> LocalDefId {
|
) -> LocalDefId {
|
||||||
|
let data = def_kind.def_path_data(name);
|
||||||
assert!(
|
assert!(
|
||||||
!self.node_id_to_def_id.contains_key(&node_id),
|
!self.node_id_to_def_id.contains_key(&node_id),
|
||||||
"adding a def'n for node-id {:?} and data {:?} but a previous def'n exists: {:?}",
|
"adding a def'n for node-id {:?} and data {:?} but a previous def'n exists: {:?}",
|
||||||
|
|
|
@ -379,14 +379,13 @@ fn encode_ty_name(tcx: TyCtxt<'_>, def_id: DefId) -> String {
|
||||||
hir::definitions::DefPathData::ForeignMod => "F", // Not specified in v0's <namespace>
|
hir::definitions::DefPathData::ForeignMod => "F", // Not specified in v0's <namespace>
|
||||||
hir::definitions::DefPathData::TypeNs(..) => "t",
|
hir::definitions::DefPathData::TypeNs(..) => "t",
|
||||||
hir::definitions::DefPathData::ValueNs(..) => "v",
|
hir::definitions::DefPathData::ValueNs(..) => "v",
|
||||||
hir::definitions::DefPathData::ClosureExpr => "C",
|
hir::definitions::DefPathData::Closure => "C",
|
||||||
hir::definitions::DefPathData::Ctor => "c",
|
hir::definitions::DefPathData::Ctor => "c",
|
||||||
hir::definitions::DefPathData::AnonConst => "k",
|
hir::definitions::DefPathData::AnonConst => "k",
|
||||||
hir::definitions::DefPathData::ImplTrait => "i",
|
hir::definitions::DefPathData::OpaqueTy => "i",
|
||||||
hir::definitions::DefPathData::CrateRoot
|
hir::definitions::DefPathData::CrateRoot
|
||||||
| hir::definitions::DefPathData::Use
|
| hir::definitions::DefPathData::Use
|
||||||
| hir::definitions::DefPathData::GlobalAsm
|
| hir::definitions::DefPathData::GlobalAsm
|
||||||
| hir::definitions::DefPathData::ImplTraitAssocTy
|
|
||||||
| hir::definitions::DefPathData::MacroNs(..)
|
| hir::definitions::DefPathData::MacroNs(..)
|
||||||
| hir::definitions::DefPathData::LifetimeNs(..) => {
|
| hir::definitions::DefPathData::LifetimeNs(..) => {
|
||||||
bug!("encode_ty_name: unexpected `{:?}`", disambiguated_data.data);
|
bug!("encode_ty_name: unexpected `{:?}`", disambiguated_data.data);
|
||||||
|
|
|
@ -770,17 +770,16 @@ impl<'tcx> Printer<'tcx> for SymbolMangler<'tcx> {
|
||||||
// Uppercase categories are more stable than lowercase ones.
|
// Uppercase categories are more stable than lowercase ones.
|
||||||
DefPathData::TypeNs(_) => 't',
|
DefPathData::TypeNs(_) => 't',
|
||||||
DefPathData::ValueNs(_) => 'v',
|
DefPathData::ValueNs(_) => 'v',
|
||||||
DefPathData::ClosureExpr => 'C',
|
DefPathData::Closure => 'C',
|
||||||
DefPathData::Ctor => 'c',
|
DefPathData::Ctor => 'c',
|
||||||
DefPathData::AnonConst => 'k',
|
DefPathData::AnonConst => 'k',
|
||||||
DefPathData::ImplTrait => 'i',
|
DefPathData::OpaqueTy => 'i',
|
||||||
|
|
||||||
// These should never show up as `path_append` arguments.
|
// These should never show up as `path_append` arguments.
|
||||||
DefPathData::CrateRoot
|
DefPathData::CrateRoot
|
||||||
| DefPathData::Use
|
| DefPathData::Use
|
||||||
| DefPathData::GlobalAsm
|
| DefPathData::GlobalAsm
|
||||||
| DefPathData::Impl
|
| DefPathData::Impl
|
||||||
| DefPathData::ImplTraitAssocTy
|
|
||||||
| DefPathData::MacroNs(_)
|
| DefPathData::MacroNs(_)
|
||||||
| DefPathData::LifetimeNs(_) => {
|
| DefPathData::LifetimeNs(_) => {
|
||||||
bug!("symbol_names: unexpected DefPathData: {:?}", disambiguated_data.data)
|
bug!("symbol_names: unexpected DefPathData: {:?}", disambiguated_data.data)
|
||||||
|
|
|
@ -2,7 +2,6 @@ use rustc_data_structures::fx::FxIndexSet;
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::def::DefKind;
|
use rustc_hir::def::DefKind;
|
||||||
use rustc_hir::def_id::{DefId, DefIdMap, LocalDefId};
|
use rustc_hir::def_id::{DefId, DefIdMap, LocalDefId};
|
||||||
use rustc_hir::definitions::DefPathData;
|
|
||||||
use rustc_hir::intravisit::{self, Visitor};
|
use rustc_hir::intravisit::{self, Visitor};
|
||||||
use rustc_middle::query::Providers;
|
use rustc_middle::query::Providers;
|
||||||
use rustc_middle::ty::{self, GenericArgs, ImplTraitInTraitData, Ty, TyCtxt};
|
use rustc_middle::ty::{self, GenericArgs, ImplTraitInTraitData, Ty, TyCtxt};
|
||||||
|
@ -254,8 +253,7 @@ fn associated_type_for_impl_trait_in_trait(
|
||||||
assert_eq!(tcx.def_kind(trait_def_id), DefKind::Trait);
|
assert_eq!(tcx.def_kind(trait_def_id), DefKind::Trait);
|
||||||
|
|
||||||
let span = tcx.def_span(opaque_ty_def_id);
|
let span = tcx.def_span(opaque_ty_def_id);
|
||||||
let trait_assoc_ty =
|
let trait_assoc_ty = tcx.at(span).create_def(trait_def_id, kw::Empty, DefKind::AssocTy);
|
||||||
tcx.at(span).create_def(trait_def_id, DefPathData::ImplTraitAssocTy, DefKind::AssocTy);
|
|
||||||
|
|
||||||
let local_def_id = trait_assoc_ty.def_id();
|
let local_def_id = trait_assoc_ty.def_id();
|
||||||
let def_id = local_def_id.to_def_id();
|
let def_id = local_def_id.to_def_id();
|
||||||
|
@ -356,8 +354,7 @@ fn associated_type_for_impl_trait_in_impl(
|
||||||
hir::FnRetTy::DefaultReturn(_) => tcx.def_span(impl_fn_def_id),
|
hir::FnRetTy::DefaultReturn(_) => tcx.def_span(impl_fn_def_id),
|
||||||
hir::FnRetTy::Return(ty) => ty.span,
|
hir::FnRetTy::Return(ty) => ty.span,
|
||||||
};
|
};
|
||||||
let impl_assoc_ty =
|
let impl_assoc_ty = tcx.at(span).create_def(impl_local_def_id, kw::Empty, DefKind::AssocTy);
|
||||||
tcx.at(span).create_def(impl_local_def_id, DefPathData::ImplTraitAssocTy, DefKind::AssocTy);
|
|
||||||
|
|
||||||
let local_def_id = impl_assoc_ty.def_id();
|
let local_def_id = impl_assoc_ty.def_id();
|
||||||
let def_id = local_def_id.to_def_id();
|
let def_id = local_def_id.to_def_id();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue