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
|
|
@ -424,7 +424,7 @@ impl<'a> Resolver<'a> {
|
|||
|
||||
ItemKind::Mod(..) => {
|
||||
let def_id = self.definitions.local_def_id(item.id);
|
||||
let module_kind = ModuleKind::Def(Def::Mod(def_id), ident.name);
|
||||
let module_kind = ModuleKind::Def(Def::Def(DefKind::Mod, def_id), ident.name);
|
||||
let module = self.arenas.alloc_module(ModuleData {
|
||||
no_implicit_prelude: parent.no_implicit_prelude || {
|
||||
attr::contains_name(&item.attrs, "no_implicit_prelude")
|
||||
|
|
@ -443,29 +443,32 @@ impl<'a> Resolver<'a> {
|
|||
|
||||
// These items live in the value namespace.
|
||||
ItemKind::Static(..) => {
|
||||
let def = Def::Static(self.definitions.local_def_id(item.id));
|
||||
let def = Def::Def(DefKind::Static, self.definitions.local_def_id(item.id));
|
||||
self.define(parent, ident, ValueNS, (def, vis, sp, expansion));
|
||||
}
|
||||
ItemKind::Const(..) => {
|
||||
let def = Def::Const(self.definitions.local_def_id(item.id));
|
||||
let def = Def::Def(DefKind::Const, self.definitions.local_def_id(item.id));
|
||||
self.define(parent, ident, ValueNS, (def, vis, sp, expansion));
|
||||
}
|
||||
ItemKind::Fn(..) => {
|
||||
let def = Def::Fn(self.definitions.local_def_id(item.id));
|
||||
let def = Def::Def(DefKind::Fn, self.definitions.local_def_id(item.id));
|
||||
self.define(parent, ident, ValueNS, (def, vis, sp, expansion));
|
||||
|
||||
// Functions introducing procedural macros reserve a slot
|
||||
// in the macro namespace as well (see #52225).
|
||||
if attr::contains_name(&item.attrs, "proc_macro") ||
|
||||
attr::contains_name(&item.attrs, "proc_macro_attribute") {
|
||||
let def = Def::Macro(def.def_id(), MacroKind::ProcMacroStub);
|
||||
let def = Def::Def(DefKind::Macro(MacroKind::ProcMacroStub), def.def_id());
|
||||
self.define(parent, ident, MacroNS, (def, vis, sp, expansion));
|
||||
}
|
||||
if let Some(attr) = attr::find_by_name(&item.attrs, "proc_macro_derive") {
|
||||
if let Some(trait_attr) =
|
||||
attr.meta_item_list().and_then(|list| list.get(0).cloned()) {
|
||||
if let Some(ident) = trait_attr.ident() {
|
||||
let def = Def::Macro(def.def_id(), MacroKind::ProcMacroStub);
|
||||
let def = Def::Def(
|
||||
DefKind::Macro(MacroKind::ProcMacroStub),
|
||||
def.def_id(),
|
||||
);
|
||||
self.define(parent, ident, MacroNS, (def, vis, ident.span, expansion));
|
||||
}
|
||||
}
|
||||
|
|
@ -474,17 +477,17 @@ impl<'a> Resolver<'a> {
|
|||
|
||||
// These items live in the type namespace.
|
||||
ItemKind::Ty(..) => {
|
||||
let def = Def::TyAlias(self.definitions.local_def_id(item.id));
|
||||
let def = Def::Def(DefKind::TyAlias, self.definitions.local_def_id(item.id));
|
||||
self.define(parent, ident, TypeNS, (def, vis, sp, expansion));
|
||||
}
|
||||
|
||||
ItemKind::Existential(_, _) => {
|
||||
let def = Def::Existential(self.definitions.local_def_id(item.id));
|
||||
let def = Def::Def(DefKind::Existential, self.definitions.local_def_id(item.id));
|
||||
self.define(parent, ident, TypeNS, (def, vis, sp, expansion));
|
||||
}
|
||||
|
||||
ItemKind::Enum(ref enum_definition, _) => {
|
||||
let def = Def::Enum(self.definitions.local_def_id(item.id));
|
||||
let def = Def::Def(DefKind::Enum, self.definitions.local_def_id(item.id));
|
||||
let module_kind = ModuleKind::Def(def, ident.name);
|
||||
let module = self.new_module(parent,
|
||||
module_kind,
|
||||
|
|
@ -499,7 +502,7 @@ impl<'a> Resolver<'a> {
|
|||
}
|
||||
|
||||
ItemKind::TraitAlias(..) => {
|
||||
let def = Def::TraitAlias(self.definitions.local_def_id(item.id));
|
||||
let def = Def::Def(DefKind::TraitAlias, self.definitions.local_def_id(item.id));
|
||||
self.define(parent, ident, TypeNS, (def, vis, sp, expansion));
|
||||
}
|
||||
|
||||
|
|
@ -507,7 +510,7 @@ impl<'a> Resolver<'a> {
|
|||
ItemKind::Struct(ref struct_def, _) => {
|
||||
// Define a name in the type namespace.
|
||||
let def_id = self.definitions.local_def_id(item.id);
|
||||
let def = Def::Struct(def_id);
|
||||
let def = Def::Def(DefKind::Struct, def_id);
|
||||
self.define(parent, ident, TypeNS, (def, vis, sp, expansion));
|
||||
|
||||
let mut ctor_vis = vis;
|
||||
|
|
@ -534,16 +537,17 @@ impl<'a> Resolver<'a> {
|
|||
// If this is a tuple or unit struct, define a name
|
||||
// in the value namespace as well.
|
||||
if let Some(ctor_node_id) = struct_def.ctor_id() {
|
||||
let ctor_def = Def::Ctor(self.definitions.local_def_id(ctor_node_id),
|
||||
CtorOf::Struct,
|
||||
CtorKind::from_ast(struct_def));
|
||||
let ctor_def = Def::Def(
|
||||
DefKind::Ctor(CtorOf::Struct, CtorKind::from_ast(struct_def)),
|
||||
self.definitions.local_def_id(ctor_node_id),
|
||||
);
|
||||
self.define(parent, ident, ValueNS, (ctor_def, ctor_vis, sp, expansion));
|
||||
self.struct_constructors.insert(def.def_id(), (ctor_def, ctor_vis));
|
||||
}
|
||||
}
|
||||
|
||||
ItemKind::Union(ref vdata, _) => {
|
||||
let def = Def::Union(self.definitions.local_def_id(item.id));
|
||||
let def = Def::Def(DefKind::Union, self.definitions.local_def_id(item.id));
|
||||
self.define(parent, ident, TypeNS, (def, vis, sp, expansion));
|
||||
|
||||
// Record field names for error reporting.
|
||||
|
|
@ -561,7 +565,7 @@ impl<'a> Resolver<'a> {
|
|||
let def_id = self.definitions.local_def_id(item.id);
|
||||
|
||||
// Add all the items within to a new module.
|
||||
let module_kind = ModuleKind::Def(Def::Trait(def_id), ident.name);
|
||||
let module_kind = ModuleKind::Def(Def::Def(DefKind::Trait, def_id), ident.name);
|
||||
let module = self.new_module(parent,
|
||||
module_kind,
|
||||
parent.normal_ancestor_id,
|
||||
|
|
@ -586,7 +590,7 @@ impl<'a> Resolver<'a> {
|
|||
|
||||
// Define a name in the type namespace.
|
||||
let def_id = self.definitions.local_def_id(variant.node.id);
|
||||
let def = Def::Variant(def_id);
|
||||
let def = Def::Def(DefKind::Variant, def_id);
|
||||
self.define(parent, ident, TypeNS, (def, vis, variant.span, expansion));
|
||||
|
||||
// If the variant is marked as non_exhaustive then lower the visibility to within the
|
||||
|
|
@ -605,7 +609,7 @@ impl<'a> Resolver<'a> {
|
|||
let ctor_node_id = variant.node.data.ctor_id().unwrap_or(variant.node.id);
|
||||
let ctor_def_id = self.definitions.local_def_id(ctor_node_id);
|
||||
let ctor_kind = CtorKind::from_ast(&variant.node.data);
|
||||
let ctor_def = Def::Ctor(ctor_def_id, CtorOf::Variant, ctor_kind);
|
||||
let ctor_def = Def::Def(DefKind::Ctor(CtorOf::Variant, ctor_kind), ctor_def_id);
|
||||
self.define(parent, ident, ValueNS, (ctor_def, ctor_vis, variant.span, expansion));
|
||||
}
|
||||
|
||||
|
|
@ -613,13 +617,13 @@ impl<'a> Resolver<'a> {
|
|||
fn build_reduced_graph_for_foreign_item(&mut self, item: &ForeignItem, expansion: Mark) {
|
||||
let (def, ns) = match item.node {
|
||||
ForeignItemKind::Fn(..) => {
|
||||
(Def::Fn(self.definitions.local_def_id(item.id)), ValueNS)
|
||||
(Def::Def(DefKind::Fn, self.definitions.local_def_id(item.id)), ValueNS)
|
||||
}
|
||||
ForeignItemKind::Static(..) => {
|
||||
(Def::Static(self.definitions.local_def_id(item.id)), ValueNS)
|
||||
(Def::Def(DefKind::Static, self.definitions.local_def_id(item.id)), ValueNS)
|
||||
}
|
||||
ForeignItemKind::Ty => {
|
||||
(Def::ForeignTy(self.definitions.local_def_id(item.id)), TypeNS)
|
||||
(Def::Def(DefKind::ForeignTy, self.definitions.local_def_id(item.id)), TypeNS)
|
||||
}
|
||||
ForeignItemKind::Macro(_) => unreachable!(),
|
||||
};
|
||||
|
|
@ -654,7 +658,7 @@ impl<'a> Resolver<'a> {
|
|||
let ident = ident.gensym_if_underscore();
|
||||
let expansion = Mark::root(); // FIXME(jseyfried) intercrate hygiene
|
||||
match def {
|
||||
Def::Mod(def_id) | Def::Enum(def_id) => {
|
||||
Def::Def(DefKind::Mod, def_id) | Def::Def(DefKind::Enum, def_id) => {
|
||||
let module = self.new_module(parent,
|
||||
ModuleKind::Def(def, ident.name),
|
||||
def_id,
|
||||
|
|
@ -662,15 +666,22 @@ impl<'a> Resolver<'a> {
|
|||
span);
|
||||
self.define(parent, ident, TypeNS, (module, vis, DUMMY_SP, expansion));
|
||||
}
|
||||
Def::Variant(..) | Def::TyAlias(..) | Def::ForeignTy(..) | Def::Existential(..) |
|
||||
Def::TraitAlias(..) | Def::PrimTy(..) | Def::ToolMod => {
|
||||
Def::Def(DefKind::Variant, _)
|
||||
| Def::Def(DefKind::TyAlias, _)
|
||||
| Def::Def(DefKind::ForeignTy, _)
|
||||
| Def::Def(DefKind::Existential, _)
|
||||
| Def::Def(DefKind::TraitAlias, _)
|
||||
| Def::PrimTy(..)
|
||||
| Def::ToolMod => {
|
||||
self.define(parent, ident, TypeNS, (def, vis, DUMMY_SP, expansion));
|
||||
}
|
||||
Def::Fn(..) | Def::Static(..) | Def::Const(..) |
|
||||
Def::Ctor(_, CtorOf::Variant, ..) => {
|
||||
Def::Def(DefKind::Fn, _)
|
||||
| Def::Def(DefKind::Static, _)
|
||||
| Def::Def(DefKind::Const, _)
|
||||
| Def::Def(DefKind::Ctor(CtorOf::Variant, ..), _) => {
|
||||
self.define(parent, ident, ValueNS, (def, vis, DUMMY_SP, expansion));
|
||||
}
|
||||
Def::Ctor(def_id, CtorOf::Struct, ..) => {
|
||||
Def::Def(DefKind::Ctor(CtorOf::Struct, ..), def_id) => {
|
||||
self.define(parent, ident, ValueNS, (def, vis, DUMMY_SP, expansion));
|
||||
|
||||
if let Some(struct_def_id) =
|
||||
|
|
@ -679,7 +690,7 @@ impl<'a> Resolver<'a> {
|
|||
self.struct_constructors.insert(struct_def_id, (def, vis));
|
||||
}
|
||||
}
|
||||
Def::Trait(def_id) => {
|
||||
Def::Def(DefKind::Trait, def_id) => {
|
||||
let module_kind = ModuleKind::Def(def, ident.name);
|
||||
let module = self.new_module(parent,
|
||||
module_kind,
|
||||
|
|
@ -690,7 +701,9 @@ impl<'a> Resolver<'a> {
|
|||
|
||||
for child in self.cstore.item_children_untracked(def_id, self.session) {
|
||||
let def = child.def.map_id(|_| panic!("unexpected id"));
|
||||
let ns = if let Def::AssociatedTy(..) = def { TypeNS } else { ValueNS };
|
||||
let ns = if let Def::Def(DefKind::AssociatedTy, _) = def {
|
||||
TypeNS
|
||||
} else { ValueNS };
|
||||
self.define(module, child.ident, ns,
|
||||
(def, ty::Visibility::Public, DUMMY_SP, expansion));
|
||||
|
||||
|
|
@ -701,14 +714,14 @@ impl<'a> Resolver<'a> {
|
|||
}
|
||||
module.populated.set(true);
|
||||
}
|
||||
Def::Struct(def_id) | Def::Union(def_id) => {
|
||||
Def::Def(DefKind::Struct, def_id) | Def::Def(DefKind::Union, def_id) => {
|
||||
self.define(parent, ident, TypeNS, (def, vis, DUMMY_SP, expansion));
|
||||
|
||||
// Record field names for error reporting.
|
||||
let field_names = self.cstore.struct_field_names_untracked(def_id);
|
||||
self.insert_field_names(def_id, field_names);
|
||||
}
|
||||
Def::Macro(..) | Def::NonMacroAttr(..) => {
|
||||
Def::Def(DefKind::Macro(..), _) | Def::NonMacroAttr(..) => {
|
||||
self.define(parent, ident, MacroNS, (def, vis, DUMMY_SP, expansion));
|
||||
}
|
||||
_ => bug!("unexpected definition: {:?}", def)
|
||||
|
|
@ -733,7 +746,7 @@ impl<'a> Resolver<'a> {
|
|||
Some(self.get_module(DefId { index: def_key.parent.unwrap(), ..def_id })))
|
||||
};
|
||||
|
||||
let kind = ModuleKind::Def(Def::Mod(def_id), name.as_symbol());
|
||||
let kind = ModuleKind::Def(Def::Def(DefKind::Mod, def_id), name.as_symbol());
|
||||
let module =
|
||||
self.arenas.alloc_module(ModuleData::new(parent, kind, def_id, Mark::root(), DUMMY_SP));
|
||||
self.extern_module_map.insert((def_id, macros_only), module);
|
||||
|
|
@ -754,11 +767,11 @@ impl<'a> Resolver<'a> {
|
|||
|
||||
pub fn get_macro(&mut self, def: Def) -> Lrc<SyntaxExtension> {
|
||||
let def_id = match def {
|
||||
Def::Macro(def_id, ..) => def_id,
|
||||
Def::Def(DefKind::Macro(..), def_id) => def_id,
|
||||
Def::NonMacroAttr(attr_kind) => return Lrc::new(SyntaxExtension::NonMacroAttr {
|
||||
mark_used: attr_kind == NonMacroAttrKind::Tool,
|
||||
}),
|
||||
_ => panic!("expected `Def::Macro` or `Def::NonMacroAttr`"),
|
||||
_ => panic!("expected `DefKind::Macro` or `Def::NonMacroAttr`"),
|
||||
};
|
||||
if let Some(ext) = self.macro_map.get(&def_id) {
|
||||
return ext.clone();
|
||||
|
|
@ -1016,14 +1029,14 @@ impl<'a, 'b> Visitor<'a> for BuildReducedGraphVisitor<'a, 'b> {
|
|||
// Add the item to the trait info.
|
||||
let item_def_id = self.resolver.definitions.local_def_id(item.id);
|
||||
let (def, ns) = match item.node {
|
||||
TraitItemKind::Const(..) => (Def::AssociatedConst(item_def_id), ValueNS),
|
||||
TraitItemKind::Const(..) => (Def::Def(DefKind::AssociatedConst, item_def_id), ValueNS),
|
||||
TraitItemKind::Method(ref sig, _) => {
|
||||
if sig.decl.has_self() {
|
||||
self.resolver.has_self.insert(item_def_id);
|
||||
}
|
||||
(Def::Method(item_def_id), ValueNS)
|
||||
(Def::Def(DefKind::Method, item_def_id), ValueNS)
|
||||
}
|
||||
TraitItemKind::Type(..) => (Def::AssociatedTy(item_def_id), TypeNS),
|
||||
TraitItemKind::Type(..) => (Def::Def(DefKind::AssociatedTy, item_def_id), TypeNS),
|
||||
TraitItemKind::Macro(_) => bug!(), // handled above
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ use std::cmp::Reverse;
|
|||
|
||||
use errors::{Applicability, DiagnosticBuilder, DiagnosticId};
|
||||
use log::debug;
|
||||
use rustc::hir::def::{self, CtorKind, Namespace::*};
|
||||
use rustc::hir::def::{self, DefKind, CtorKind, Namespace::*};
|
||||
use rustc::hir::def_id::{CRATE_DEF_INDEX, DefId};
|
||||
use rustc::session::{Session, config::nightly_options};
|
||||
use syntax::ast::{self, Expr, ExprKind, Ident};
|
||||
|
|
@ -31,7 +31,9 @@ impl<'a> Resolver<'a> {
|
|||
let ident_span = path.last().map_or(span, |ident| ident.ident.span);
|
||||
let ns = source.namespace();
|
||||
let is_expected = &|def| source.is_expected(def);
|
||||
let is_enum_variant = &|def| if let Def::Variant(..) = def { true } else { false };
|
||||
let is_enum_variant = &|def| {
|
||||
if let Def::Def(DefKind::Variant, _) = def { true } else { false }
|
||||
};
|
||||
|
||||
// Make the base error.
|
||||
let expected = source.descr_expected();
|
||||
|
|
@ -117,7 +119,8 @@ impl<'a> Resolver<'a> {
|
|||
}
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
if candidates.is_empty() && is_expected(Def::Enum(DefId::local(CRATE_DEF_INDEX))) {
|
||||
let crate_def_id = DefId::local(CRATE_DEF_INDEX);
|
||||
if candidates.is_empty() && is_expected(Def::Def(DefKind::Enum, crate_def_id)) {
|
||||
let enum_candidates =
|
||||
self.lookup_import_candidates(ident, ns, is_enum_variant);
|
||||
let mut enum_candidates = enum_candidates.iter()
|
||||
|
|
@ -362,7 +365,7 @@ impl<'a> Resolver<'a> {
|
|||
};
|
||||
|
||||
match (def, source) {
|
||||
(Def::Macro(..), _) => {
|
||||
(Def::Def(DefKind::Macro(..), _), _) => {
|
||||
err.span_suggestion(
|
||||
span,
|
||||
"use `!` to invoke the macro",
|
||||
|
|
@ -373,17 +376,19 @@ impl<'a> Resolver<'a> {
|
|||
err.note("if you want the `try` keyword, you need to be in the 2018 edition");
|
||||
}
|
||||
}
|
||||
(Def::TyAlias(..), PathSource::Trait(_)) => {
|
||||
(Def::Def(DefKind::TyAlias, _), PathSource::Trait(_)) => {
|
||||
err.span_label(span, "type aliases cannot be used as traits");
|
||||
if nightly_options::is_nightly_build() {
|
||||
err.note("did you mean to use a trait alias?");
|
||||
}
|
||||
}
|
||||
(Def::Mod(..), PathSource::Expr(Some(parent))) => if !path_sep(err, &parent) {
|
||||
return false;
|
||||
},
|
||||
(Def::Enum(..), PathSource::TupleStruct)
|
||||
| (Def::Enum(..), PathSource::Expr(..)) => {
|
||||
(Def::Def(DefKind::Mod, _), PathSource::Expr(Some(parent))) => {
|
||||
if !path_sep(err, &parent) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
(Def::Def(DefKind::Enum, _), PathSource::TupleStruct)
|
||||
| (Def::Def(DefKind::Enum, _), PathSource::Expr(..)) => {
|
||||
if let Some(variants) = self.collect_enum_variants(def) {
|
||||
if !variants.is_empty() {
|
||||
let msg = if variants.len() == 1 {
|
||||
|
|
@ -403,7 +408,7 @@ impl<'a> Resolver<'a> {
|
|||
err.note("did you mean to use one of the enum's variants?");
|
||||
}
|
||||
},
|
||||
(Def::Struct(def_id), _) if ns == ValueNS => {
|
||||
(Def::Def(DefKind::Struct, def_id), _) if ns == ValueNS => {
|
||||
if let Some((ctor_def, ctor_vis))
|
||||
= self.struct_constructors.get(&def_id).cloned() {
|
||||
let accessible_ctor = self.is_accessible(ctor_vis);
|
||||
|
|
@ -417,16 +422,17 @@ impl<'a> Resolver<'a> {
|
|||
bad_struct_syntax_suggestion();
|
||||
}
|
||||
}
|
||||
(Def::Union(..), _) |
|
||||
(Def::Variant(..), _) |
|
||||
(Def::Ctor(_, _, CtorKind::Fictive), _) if ns == ValueNS => {
|
||||
(Def::Def(DefKind::Union, _), _) |
|
||||
(Def::Def(DefKind::Variant, _), _) |
|
||||
(Def::Def(DefKind::Ctor(_, CtorKind::Fictive), _), _) if ns == ValueNS => {
|
||||
bad_struct_syntax_suggestion();
|
||||
}
|
||||
(Def::SelfTy(..), _) if ns == ValueNS => {
|
||||
err.span_label(span, fallback_label);
|
||||
err.note("can't use `Self` as a constructor, you must use the implemented struct");
|
||||
}
|
||||
(Def::TyAlias(_), _) | (Def::AssociatedTy(..), _) if ns == ValueNS => {
|
||||
(Def::Def(DefKind::TyAlias, _), _)
|
||||
| (Def::Def(DefKind::AssociatedTy, _), _) if ns == ValueNS => {
|
||||
err.note("can't use a type alias as a constructor");
|
||||
}
|
||||
_ => return false,
|
||||
|
|
@ -622,7 +628,7 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
|
|||
let resolutions = crate_module.resolutions.borrow();
|
||||
let resolution = resolutions.get(&(ident, MacroNS))?;
|
||||
let binding = resolution.borrow().binding()?;
|
||||
if let Def::Macro(_, MacroKind::Bang) = binding.def() {
|
||||
if let Def::Def(DefKind::Macro(MacroKind::Bang), _) = binding.def() {
|
||||
let module_name = crate_module.kind.name().unwrap();
|
||||
let import = match directive.subclass {
|
||||
ImportDirectiveSubclass::SingleImport { source, target, .. } if source != target =>
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ use rustc::middle::cstore::CrateStore;
|
|||
use rustc::session::Session;
|
||||
use rustc::lint;
|
||||
use rustc::hir::def::{
|
||||
self, PathResolution, CtorKind, CtorOf, NonMacroAttrKind, DefMap, ImportMap, ExportMap
|
||||
self, DefKind, PathResolution, CtorKind, CtorOf, NonMacroAttrKind, DefMap, ImportMap, ExportMap
|
||||
};
|
||||
use rustc::hir::def::Namespace::*;
|
||||
use rustc::hir::def_id::{CRATE_DEF_INDEX, LOCAL_CRATE, DefId};
|
||||
|
|
@ -236,19 +236,19 @@ fn resolve_struct_error<'sess, 'a>(resolver: &'sess Resolver<'_>,
|
|||
}
|
||||
return err;
|
||||
},
|
||||
Def::TyParam(def_id) => {
|
||||
Def::Def(DefKind::TyParam, def_id) => {
|
||||
if let Some(span) = resolver.definitions.opt_span(def_id) {
|
||||
err.span_label(span, "type parameter from outer function");
|
||||
}
|
||||
}
|
||||
Def::ConstParam(def_id) => {
|
||||
Def::Def(DefKind::ConstParam, def_id) => {
|
||||
if let Some(span) = resolver.definitions.opt_span(def_id) {
|
||||
err.span_label(span, "const parameter from outer function");
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
bug!("GenericParamsFromOuterFunction should only be used with Def::SelfTy, \
|
||||
Def::TyParam");
|
||||
DefKind::TyParam");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -570,7 +570,7 @@ impl<'a> PathSource<'a> {
|
|||
MacroNS => bug!("associated macro"),
|
||||
},
|
||||
PathSource::Expr(parent) => match parent.map(|p| &p.node) {
|
||||
// "function" here means "anything callable" rather than `Def::Fn`,
|
||||
// "function" here means "anything callable" rather than `DefKind::Fn`,
|
||||
// this is not precise but usually more helpful than just "value".
|
||||
Some(&ExprKind::Call(..)) => "function",
|
||||
_ => "value",
|
||||
|
|
@ -581,50 +581,70 @@ impl<'a> PathSource<'a> {
|
|||
fn is_expected(self, def: Def) -> bool {
|
||||
match self {
|
||||
PathSource::Type => match def {
|
||||
Def::Struct(..) | Def::Union(..) | Def::Enum(..) |
|
||||
Def::Trait(..) | Def::TraitAlias(..) | Def::TyAlias(..) |
|
||||
Def::AssociatedTy(..) | Def::PrimTy(..) | Def::TyParam(..) |
|
||||
Def::SelfTy(..) | Def::Existential(..) | Def::ForeignTy(..) => true,
|
||||
Def::Def(DefKind::Struct, _)
|
||||
| Def::Def(DefKind::Union, _)
|
||||
| Def::Def(DefKind::Enum, _)
|
||||
| Def::Def(DefKind::Trait, _)
|
||||
| Def::Def(DefKind::TraitAlias, _)
|
||||
| Def::Def(DefKind::TyAlias, _)
|
||||
| Def::Def(DefKind::AssociatedTy, _)
|
||||
| Def::PrimTy(..)
|
||||
| Def::Def(DefKind::TyParam, _)
|
||||
| Def::SelfTy(..)
|
||||
| Def::Def(DefKind::Existential, _)
|
||||
| Def::Def(DefKind::ForeignTy, _) => true,
|
||||
_ => false,
|
||||
},
|
||||
PathSource::Trait(AliasPossibility::No) => match def {
|
||||
Def::Trait(..) => true,
|
||||
Def::Def(DefKind::Trait, _) => true,
|
||||
_ => false,
|
||||
},
|
||||
PathSource::Trait(AliasPossibility::Maybe) => match def {
|
||||
Def::Trait(..) => true,
|
||||
Def::TraitAlias(..) => true,
|
||||
Def::Def(DefKind::Trait, _) => true,
|
||||
Def::Def(DefKind::TraitAlias, _) => true,
|
||||
_ => false,
|
||||
},
|
||||
PathSource::Expr(..) => match def {
|
||||
Def::Ctor(_, _, CtorKind::Const) | Def::Ctor(_, _, CtorKind::Fn) |
|
||||
Def::Const(..) | Def::Static(..) | Def::Local(..) | Def::Upvar(..) |
|
||||
Def::Fn(..) | Def::Method(..) | Def::AssociatedConst(..) |
|
||||
Def::SelfCtor(..) | Def::ConstParam(..) => true,
|
||||
Def::Def(DefKind::Ctor(_, CtorKind::Const), _)
|
||||
| Def::Def(DefKind::Ctor(_, CtorKind::Fn), _)
|
||||
| Def::Def(DefKind::Const, _)
|
||||
| Def::Def(DefKind::Static, _)
|
||||
| Def::Local(..)
|
||||
| Def::Upvar(..)
|
||||
| Def::Def(DefKind::Fn, _)
|
||||
| Def::Def(DefKind::Method, _)
|
||||
| Def::Def(DefKind::AssociatedConst, _)
|
||||
| Def::SelfCtor(..)
|
||||
| Def::Def(DefKind::ConstParam, _) => true,
|
||||
_ => false,
|
||||
},
|
||||
PathSource::Pat => match def {
|
||||
Def::Ctor(_, _, CtorKind::Const) |
|
||||
Def::Const(..) | Def::AssociatedConst(..) |
|
||||
Def::Def(DefKind::Ctor(_, CtorKind::Const), _) |
|
||||
Def::Def(DefKind::Const, _) | Def::Def(DefKind::AssociatedConst, _) |
|
||||
Def::SelfCtor(..) => true,
|
||||
_ => false,
|
||||
},
|
||||
PathSource::TupleStruct => match def {
|
||||
Def::Ctor(_, _, CtorKind::Fn) | Def::SelfCtor(..) => true,
|
||||
Def::Def(DefKind::Ctor(_, CtorKind::Fn), _) | Def::SelfCtor(..) => true,
|
||||
_ => false,
|
||||
},
|
||||
PathSource::Struct => match def {
|
||||
Def::Struct(..) | Def::Union(..) | Def::Variant(..) |
|
||||
Def::TyAlias(..) | Def::AssociatedTy(..) | Def::SelfTy(..) => true,
|
||||
Def::Def(DefKind::Struct, _)
|
||||
| Def::Def(DefKind::Union, _)
|
||||
| Def::Def(DefKind::Variant, _)
|
||||
| Def::Def(DefKind::TyAlias, _)
|
||||
| Def::Def(DefKind::AssociatedTy, _)
|
||||
| Def::SelfTy(..) => true,
|
||||
_ => false,
|
||||
},
|
||||
PathSource::TraitItem(ns) => match def {
|
||||
Def::AssociatedConst(..) | Def::Method(..) if ns == ValueNS => true,
|
||||
Def::AssociatedTy(..) if ns == TypeNS => true,
|
||||
Def::Def(DefKind::AssociatedConst, _)
|
||||
| Def::Def(DefKind::Method, _) if ns == ValueNS => true,
|
||||
Def::Def(DefKind::AssociatedTy, _) if ns == TypeNS => true,
|
||||
_ => false,
|
||||
},
|
||||
PathSource::Visibility => match def {
|
||||
Def::Mod(..) => true,
|
||||
Def::Def(DefKind::Mod, _) => true,
|
||||
_ => false,
|
||||
},
|
||||
}
|
||||
|
|
@ -1263,14 +1283,14 @@ impl<'a> ModuleData<'a> {
|
|||
// `self` resolves to the first module ancestor that `is_normal`.
|
||||
fn is_normal(&self) -> bool {
|
||||
match self.kind {
|
||||
ModuleKind::Def(Def::Mod(_), _) => true,
|
||||
ModuleKind::Def(Def::Def(DefKind::Mod, _), _) => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
fn is_trait(&self) -> bool {
|
||||
match self.kind {
|
||||
ModuleKind::Def(Def::Trait(_), _) => true,
|
||||
ModuleKind::Def(Def::Def(DefKind::Trait, _), _) => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
|
@ -1443,8 +1463,8 @@ impl<'a> NameBinding<'a> {
|
|||
|
||||
fn is_variant(&self) -> bool {
|
||||
match self.kind {
|
||||
NameBindingKind::Def(Def::Variant(..), _) |
|
||||
NameBindingKind::Def(Def::Ctor(_, CtorOf::Variant, ..), _) => true,
|
||||
NameBindingKind::Def(Def::Def(DefKind::Variant, _), _) |
|
||||
NameBindingKind::Def(Def::Def(DefKind::Ctor(CtorOf::Variant, ..), _), _) => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
|
@ -1457,7 +1477,7 @@ impl<'a> NameBinding<'a> {
|
|||
}, ..
|
||||
} => true,
|
||||
NameBindingKind::Module(
|
||||
&ModuleData { kind: ModuleKind::Def(Def::Mod(def_id), _), .. }
|
||||
&ModuleData { kind: ModuleKind::Def(Def::Def(DefKind::Mod, def_id), _), .. }
|
||||
) => def_id.index == CRATE_DEF_INDEX,
|
||||
_ => false,
|
||||
}
|
||||
|
|
@ -1479,21 +1499,23 @@ impl<'a> NameBinding<'a> {
|
|||
|
||||
fn is_importable(&self) -> bool {
|
||||
match self.def() {
|
||||
Def::AssociatedConst(..) | Def::Method(..) | Def::AssociatedTy(..) => false,
|
||||
Def::Def(DefKind::AssociatedConst, _)
|
||||
| Def::Def(DefKind::Method, _)
|
||||
| Def::Def(DefKind::AssociatedTy, _) => false,
|
||||
_ => true,
|
||||
}
|
||||
}
|
||||
|
||||
fn is_macro_def(&self) -> bool {
|
||||
match self.kind {
|
||||
NameBindingKind::Def(Def::Macro(..), _) => true,
|
||||
NameBindingKind::Def(Def::Def(DefKind::Macro(..), _), _) => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
fn macro_kind(&self) -> Option<MacroKind> {
|
||||
match self.def() {
|
||||
Def::Macro(_, kind) => Some(kind),
|
||||
Def::Def(DefKind::Macro(kind), _) => Some(kind),
|
||||
Def::NonMacroAttr(..) => Some(MacroKind::Attr),
|
||||
_ => None,
|
||||
}
|
||||
|
|
@ -1915,7 +1937,10 @@ impl<'a> Resolver<'a> {
|
|||
arenas: &'a ResolverArenas<'a>)
|
||||
-> Resolver<'a> {
|
||||
let root_def_id = DefId::local(CRATE_DEF_INDEX);
|
||||
let root_module_kind = ModuleKind::Def(Def::Mod(root_def_id), keywords::Invalid.name());
|
||||
let root_module_kind = ModuleKind::Def(
|
||||
Def::Def(DefKind::Mod, root_def_id),
|
||||
keywords::Invalid.name(),
|
||||
);
|
||||
let graph_root = arenas.alloc_module(ModuleData {
|
||||
no_implicit_prelude: attr::contains_name(&krate.attrs, "no_implicit_prelude"),
|
||||
..ModuleData::new(None, root_module_kind, root_def_id, Mark::root(), krate.span)
|
||||
|
|
@ -2663,8 +2688,11 @@ impl<'a> Resolver<'a> {
|
|||
}
|
||||
seen_bindings.entry(ident).or_insert(param.ident.span);
|
||||
|
||||
// Plain insert (no renaming).
|
||||
let def = Def::TyParam(self.definitions.local_def_id(param.id));
|
||||
// Plain insert (no renaming).
|
||||
let def = Def::Def(
|
||||
DefKind::TyParam,
|
||||
self.definitions.local_def_id(param.id),
|
||||
);
|
||||
function_type_rib.bindings.insert(ident, def);
|
||||
self.record_def(param.id, PathResolution::new(def));
|
||||
}
|
||||
|
|
@ -2682,7 +2710,10 @@ impl<'a> Resolver<'a> {
|
|||
}
|
||||
seen_bindings.entry(ident).or_insert(param.ident.span);
|
||||
|
||||
let def = Def::ConstParam(self.definitions.local_def_id(param.id));
|
||||
let def = Def::Def(
|
||||
DefKind::ConstParam,
|
||||
self.definitions.local_def_id(param.id),
|
||||
);
|
||||
function_value_rib.bindings.insert(ident, def);
|
||||
self.record_def(param.id, PathResolution::new(def));
|
||||
}
|
||||
|
|
@ -3175,14 +3206,16 @@ impl<'a> Resolver<'a> {
|
|||
let is_syntactic_ambiguity = opt_pat.is_none() &&
|
||||
bmode == BindingMode::ByValue(Mutability::Immutable);
|
||||
match def {
|
||||
Def::Ctor(_, _, CtorKind::Const) |
|
||||
Def::Const(..) if is_syntactic_ambiguity => {
|
||||
Def::Def(DefKind::Ctor(_, CtorKind::Const), _) |
|
||||
Def::Def(DefKind::Const, _) if is_syntactic_ambiguity => {
|
||||
// Disambiguate in favor of a unit struct/variant
|
||||
// or constant pattern.
|
||||
self.record_use(ident, ValueNS, binding.unwrap(), false);
|
||||
Some(PathResolution::new(def))
|
||||
}
|
||||
Def::Ctor(..) | Def::Const(..) | Def::Static(..) => {
|
||||
Def::Def(DefKind::Ctor(..), _)
|
||||
| Def::Def(DefKind::Const, _)
|
||||
| Def::Def(DefKind::Static, _) => {
|
||||
// This is unambiguously a fresh binding, either syntactically
|
||||
// (e.g., `IDENT @ PAT` or `ref IDENT`) or because `IDENT` resolves
|
||||
// to something unusable as a pattern (e.g., constructor function),
|
||||
|
|
@ -3196,7 +3229,7 @@ impl<'a> Resolver<'a> {
|
|||
);
|
||||
None
|
||||
}
|
||||
Def::Fn(..) | Def::Err => {
|
||||
Def::Def(DefKind::Fn, _) | Def::Err => {
|
||||
// These entities are explicitly allowed
|
||||
// to be shadowed by fresh bindings.
|
||||
None
|
||||
|
|
@ -3310,7 +3343,7 @@ impl<'a> Resolver<'a> {
|
|||
// Add a temporary hack to smooth the transition to new struct ctor
|
||||
// visibility rules. See #38932 for more details.
|
||||
let mut res = None;
|
||||
if let Def::Struct(def_id) = resolution.base_def() {
|
||||
if let Def::Def(DefKind::Struct, def_id) = resolution.base_def() {
|
||||
if let Some((ctor_def, ctor_vis))
|
||||
= self.struct_constructors.get(&def_id).cloned() {
|
||||
if is_expected(ctor_def) && self.is_accessible(ctor_vis) {
|
||||
|
|
@ -3501,9 +3534,10 @@ impl<'a> Resolver<'a> {
|
|||
self.macro_use_prelude.get(&path[0].ident.name).cloned()
|
||||
.and_then(NameBinding::macro_kind) == Some(MacroKind::Bang)) {
|
||||
// Return some dummy definition, it's enough for error reporting.
|
||||
return Some(
|
||||
PathResolution::new(Def::Macro(DefId::local(CRATE_DEF_INDEX), MacroKind::Bang))
|
||||
);
|
||||
return Some(PathResolution::new(Def::Def(
|
||||
DefKind::Macro(MacroKind::Bang),
|
||||
DefId::local(CRATE_DEF_INDEX),
|
||||
)));
|
||||
}
|
||||
fin_res
|
||||
}
|
||||
|
|
@ -3536,7 +3570,7 @@ impl<'a> Resolver<'a> {
|
|||
// trait to resolve. In that case, we leave the `B`
|
||||
// segment to be resolved by type-check.
|
||||
return Some(PathResolution::with_unresolved_segments(
|
||||
Def::Mod(DefId::local(CRATE_DEF_INDEX)), path.len()
|
||||
Def::Def(DefKind::Mod, DefId::local(CRATE_DEF_INDEX)), path.len()
|
||||
));
|
||||
}
|
||||
|
||||
|
|
@ -3862,7 +3896,9 @@ impl<'a> Resolver<'a> {
|
|||
_ => None,
|
||||
};
|
||||
let (label, suggestion) = if module_def == self.graph_root.def() {
|
||||
let is_mod = |def| match def { Def::Mod(..) => true, _ => false };
|
||||
let is_mod = |def| {
|
||||
match def { Def::Def(DefKind::Mod, _) => true, _ => false }
|
||||
};
|
||||
let mut candidates =
|
||||
self.lookup_import_candidates(ident, TypeNS, is_mod);
|
||||
candidates.sort_by_cached_key(|c| {
|
||||
|
|
@ -4059,7 +4095,7 @@ impl<'a> Resolver<'a> {
|
|||
return Def::Err;
|
||||
}
|
||||
}
|
||||
Def::TyParam(..) | Def::SelfTy(..) => {
|
||||
Def::Def(DefKind::TyParam, _) | Def::SelfTy(..) => {
|
||||
for rib in ribs {
|
||||
match rib.kind {
|
||||
NormalRibKind | TraitOrImplItemRibKind | ClosureRibKind(..) |
|
||||
|
|
@ -4081,7 +4117,7 @@ impl<'a> Resolver<'a> {
|
|||
}
|
||||
}
|
||||
}
|
||||
Def::ConstParam(..) => {
|
||||
Def::Def(DefKind::ConstParam, _) => {
|
||||
let mut ribs = ribs.iter().peekable();
|
||||
if let Some(Rib { kind: FnItemRibKind, .. }) = ribs.peek() {
|
||||
// When declaring const parameters inside function signatures, the first rib
|
||||
|
|
@ -4132,7 +4168,7 @@ impl<'a> Resolver<'a> {
|
|||
// Look for a field with the same name in the current self_type.
|
||||
if let Some(resolution) = self.def_map.get(&node_id) {
|
||||
match resolution.base_def() {
|
||||
Def::Struct(did) | Def::Union(did)
|
||||
Def::Def(DefKind::Struct, did) | Def::Def(DefKind::Union, did)
|
||||
if resolution.unresolved_segments() == 0 => {
|
||||
if let Some(field_names) = self.field_names.get(&did) {
|
||||
if field_names.iter().any(|&field_name| ident.name == field_name) {
|
||||
|
|
@ -4223,10 +4259,13 @@ impl<'a> Resolver<'a> {
|
|||
self.crate_loader
|
||||
.maybe_process_path_extern(ident.name, ident.span)
|
||||
.and_then(|crate_id| {
|
||||
let crate_mod = Def::Mod(DefId {
|
||||
krate: crate_id,
|
||||
index: CRATE_DEF_INDEX,
|
||||
});
|
||||
let crate_mod = Def::Def(
|
||||
DefKind::Mod,
|
||||
DefId {
|
||||
krate: crate_id,
|
||||
index: CRATE_DEF_INDEX,
|
||||
},
|
||||
);
|
||||
|
||||
if !ident.name.is_gensymed() && filter_fn(crate_mod) {
|
||||
Some(TypoSuggestion {
|
||||
|
|
@ -4566,8 +4605,8 @@ impl<'a> Resolver<'a> {
|
|||
module.for_each_child(|name, ns, binding| {
|
||||
if ns != TypeNS { return }
|
||||
match binding.def() {
|
||||
Def::Trait(_) |
|
||||
Def::TraitAlias(_) => collected_traits.push((name, binding)),
|
||||
Def::Def(DefKind::Trait, _) |
|
||||
Def::Def(DefKind::TraitAlias, _) => collected_traits.push((name, binding)),
|
||||
_ => (),
|
||||
}
|
||||
});
|
||||
|
|
@ -4602,7 +4641,7 @@ impl<'a> Resolver<'a> {
|
|||
let trait_def_id = module.def_id().unwrap();
|
||||
found_traits.push(TraitCandidate { def_id: trait_def_id, import_id });
|
||||
}
|
||||
} else if let Def::TraitAlias(_) = binding.def() {
|
||||
} else if let Def::Def(DefKind::TraitAlias, _) = binding.def() {
|
||||
// For now, just treat all trait aliases as possible candidates, since we don't
|
||||
// know if the ident is somewhere in the transitive bounds.
|
||||
|
||||
|
|
@ -4677,7 +4716,7 @@ impl<'a> Resolver<'a> {
|
|||
// outside crate private modules => no need to check this)
|
||||
if !in_module_is_extern || name_binding.vis == ty::Visibility::Public {
|
||||
let did = match def {
|
||||
Def::Ctor(did, ..) => self.parent(did),
|
||||
Def::Def(DefKind::Ctor(..), did) => self.parent(did),
|
||||
_ => def.opt_def_id(),
|
||||
};
|
||||
candidates.push(ImportSuggestion { did, path });
|
||||
|
|
@ -4793,7 +4832,7 @@ impl<'a> Resolver<'a> {
|
|||
}
|
||||
|
||||
fn collect_enum_variants(&mut self, enum_def: Def) -> Option<Vec<Path>> {
|
||||
if let Def::Enum(..) = enum_def {} else {
|
||||
if let Def::Def(DefKind::Enum, _) = enum_def {} else {
|
||||
panic!("Non-enum def passed to collect_enum_variants: {:?}", enum_def)
|
||||
}
|
||||
|
||||
|
|
@ -4802,7 +4841,7 @@ impl<'a> Resolver<'a> {
|
|||
|
||||
let mut variants = Vec::new();
|
||||
enum_module.for_each_child_stable(|ident, _, name_binding| {
|
||||
if let Def::Variant(..) = name_binding.def() {
|
||||
if let Def::Def(DefKind::Variant, _) = name_binding.def() {
|
||||
let mut segms = enum_import_suggestion.path.segments.clone();
|
||||
segms.push(ast::PathSegment::from_ident(ident));
|
||||
variants.push(Path {
|
||||
|
|
@ -5050,8 +5089,8 @@ impl<'a> Resolver<'a> {
|
|||
}
|
||||
|
||||
let container = match parent.kind {
|
||||
ModuleKind::Def(Def::Mod(_), _) => "module",
|
||||
ModuleKind::Def(Def::Trait(_), _) => "trait",
|
||||
ModuleKind::Def(Def::Def(DefKind::Mod, _), _) => "module",
|
||||
ModuleKind::Def(Def::Def(DefKind::Trait, _), _) => "trait",
|
||||
ModuleKind::Block(..) => "block",
|
||||
_ => "enum",
|
||||
};
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ use crate::build_reduced_graph::{BuildReducedGraphVisitor, IsMacroExport};
|
|||
use crate::resolve_imports::ImportResolver;
|
||||
use rustc::hir::def_id::{DefId, CRATE_DEF_INDEX, DefIndex,
|
||||
CrateNum, DefIndexAddressSpace};
|
||||
use rustc::hir::def::{self, NonMacroAttrKind};
|
||||
use rustc::hir::def::{self, DefKind, NonMacroAttrKind};
|
||||
use rustc::hir::map::{self, DefCollector};
|
||||
use rustc::{ty, lint};
|
||||
use rustc::{bug, span_bug};
|
||||
|
|
@ -179,7 +179,7 @@ impl<'a> base::Resolver for Resolver<'a> {
|
|||
let kind = ext.kind();
|
||||
self.macro_map.insert(def_id, ext);
|
||||
let binding = self.arenas.alloc_name_binding(NameBinding {
|
||||
kind: NameBindingKind::Def(Def::Macro(def_id, kind), false),
|
||||
kind: NameBindingKind::Def(Def::Def(DefKind::Macro(kind), def_id), false),
|
||||
ambiguity: None,
|
||||
span: DUMMY_SP,
|
||||
vis: ty::Visibility::Public,
|
||||
|
|
@ -218,7 +218,7 @@ impl<'a> base::Resolver for Resolver<'a> {
|
|||
Err(determinacy) => return Err(determinacy),
|
||||
};
|
||||
|
||||
if let Def::Macro(def_id, _) = def {
|
||||
if let Def::Def(DefKind::Macro(_), def_id) = def {
|
||||
if after_derive {
|
||||
self.session.span_err(invoc.span(),
|
||||
"macro attributes must be placed before `#[derive]`");
|
||||
|
|
@ -297,7 +297,7 @@ impl<'a> Resolver<'a> {
|
|||
let def = def?;
|
||||
|
||||
match def {
|
||||
Def::Macro(def_id, macro_kind) => {
|
||||
Def::Def(DefKind::Macro(macro_kind), def_id) => {
|
||||
self.unused_macros.remove(&def_id);
|
||||
if macro_kind == MacroKind::ProcMacroStub {
|
||||
let msg = "can't use a procedural macro from the same crate that defines it";
|
||||
|
|
@ -341,7 +341,7 @@ impl<'a> Resolver<'a> {
|
|||
Def::Err => {
|
||||
return Err(Determinacy::Determined);
|
||||
}
|
||||
_ => panic!("expected `Def::Macro` or `Def::NonMacroAttr`"),
|
||||
_ => panic!("expected `DefKind::Macro` or `Def::NonMacroAttr`"),
|
||||
}
|
||||
|
||||
Ok((def, self.get_macro(def)))
|
||||
|
|
@ -1028,7 +1028,7 @@ impl<'a> Resolver<'a> {
|
|||
// Then check modules.
|
||||
}).or_else(|| {
|
||||
let is_macro = |def| {
|
||||
if let Def::Macro(_, def_kind) = def {
|
||||
if let Def::Def(DefKind::Macro(def_kind), _) = def {
|
||||
def_kind == kind
|
||||
} else {
|
||||
false
|
||||
|
|
@ -1107,7 +1107,7 @@ impl<'a> Resolver<'a> {
|
|||
if def.legacy {
|
||||
let ident = ident.modern();
|
||||
self.macro_names.insert(ident);
|
||||
let def = Def::Macro(def_id, MacroKind::Bang);
|
||||
let def = Def::Def(DefKind::Macro(MacroKind::Bang), def_id);
|
||||
let is_macro_export = attr::contains_name(&item.attrs, "macro_export");
|
||||
let vis = if is_macro_export {
|
||||
ty::Visibility::Public
|
||||
|
|
@ -1133,7 +1133,7 @@ impl<'a> Resolver<'a> {
|
|||
}
|
||||
} else {
|
||||
let module = self.current_module;
|
||||
let def = Def::Macro(def_id, MacroKind::Bang);
|
||||
let def = Def::Def(DefKind::Macro(MacroKind::Bang), def_id);
|
||||
let vis = self.resolve_visibility(&item.vis);
|
||||
if vis != ty::Visibility::Public {
|
||||
self.unused_macros.insert(def_id);
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ use rustc::lint::builtin::{
|
|||
UNUSED_IMPORTS,
|
||||
};
|
||||
use rustc::hir::def_id::{CrateNum, DefId};
|
||||
use rustc::hir::def::{self, PathResolution, Export};
|
||||
use rustc::hir::def::{self, DefKind, PathResolution, Export};
|
||||
use rustc::session::DiagnosticMessageId;
|
||||
use rustc::util::nodemap::FxHashSet;
|
||||
use rustc::{bug, span_bug};
|
||||
|
|
@ -1224,7 +1224,7 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
|
|||
// purposes it's good enough to just favor one over the other.
|
||||
self.per_ns(|this, ns| if let Some(binding) = source_bindings[ns].get().ok() {
|
||||
let mut def = binding.def();
|
||||
if let Def::Macro(def_id, _) = def {
|
||||
if let Def::Def(DefKind::Macro(_), def_id) = def {
|
||||
// `DefId`s from the "built-in macro crate" should not leak from resolve because
|
||||
// later stages are not ready to deal with them and produce lots of ICEs. Replace
|
||||
// them with `Def::Err` until some saner scheme is implemented for built-in macros.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue