resolve/metadata: Stop encoding macros as reexports
This commit is contained in:
parent
50568b8ee5
commit
179ce18c5c
6 changed files with 47 additions and 23 deletions
|
@ -1077,6 +1077,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
|
||||||
res,
|
res,
|
||||||
vis: ty::Visibility::Public,
|
vis: ty::Visibility::Public,
|
||||||
span: ident.span,
|
span: ident.span,
|
||||||
|
macro_rules: false,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1088,17 +1089,19 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
|
||||||
for child_index in children.decode((self, sess)) {
|
for child_index in children.decode((self, sess)) {
|
||||||
if let Some(ident) = self.opt_item_ident(child_index, sess) {
|
if let Some(ident) = self.opt_item_ident(child_index, sess) {
|
||||||
let kind = self.def_kind(child_index);
|
let kind = self.def_kind(child_index);
|
||||||
if matches!(kind, DefKind::Macro(..)) {
|
|
||||||
// FIXME: Macros are currently encoded twice, once as items and once as
|
|
||||||
// reexports. We ignore the items here and only use the reexports.
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
let def_id = self.local_def_id(child_index);
|
let def_id = self.local_def_id(child_index);
|
||||||
let res = Res::Def(kind, def_id);
|
let res = Res::Def(kind, def_id);
|
||||||
let vis = self.get_visibility(child_index);
|
let vis = self.get_visibility(child_index);
|
||||||
let span = self.get_span(child_index, sess);
|
let span = self.get_span(child_index, sess);
|
||||||
|
let macro_rules = match kind {
|
||||||
|
DefKind::Macro(..) => match self.kind(child_index) {
|
||||||
|
EntryKind::MacroDef(_, macro_rules) => macro_rules,
|
||||||
|
_ => unreachable!(),
|
||||||
|
},
|
||||||
|
_ => false,
|
||||||
|
};
|
||||||
|
|
||||||
callback(ModChild { ident, res, vis, span });
|
callback(ModChild { ident, res, vis, span, macro_rules });
|
||||||
|
|
||||||
// For non-re-export structs and variants add their constructors to children.
|
// For non-re-export structs and variants add their constructors to children.
|
||||||
// Re-export lists automatically contain constructors when necessary.
|
// Re-export lists automatically contain constructors when necessary.
|
||||||
|
@ -1110,7 +1113,13 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
|
||||||
let ctor_res =
|
let ctor_res =
|
||||||
Res::Def(DefKind::Ctor(CtorOf::Struct, ctor_kind), ctor_def_id);
|
Res::Def(DefKind::Ctor(CtorOf::Struct, ctor_kind), ctor_def_id);
|
||||||
let vis = self.get_visibility(ctor_def_id.index);
|
let vis = self.get_visibility(ctor_def_id.index);
|
||||||
callback(ModChild { ident, res: ctor_res, vis, span });
|
callback(ModChild {
|
||||||
|
ident,
|
||||||
|
res: ctor_res,
|
||||||
|
vis,
|
||||||
|
span,
|
||||||
|
macro_rules: false,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
DefKind::Variant => {
|
DefKind::Variant => {
|
||||||
|
@ -1135,7 +1144,13 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
|
||||||
vis = ty::Visibility::Restricted(crate_def_id);
|
vis = ty::Visibility::Restricted(crate_def_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
callback(ModChild { ident, res: ctor_res, vis, span });
|
callback(ModChild {
|
||||||
|
ident,
|
||||||
|
res: ctor_res,
|
||||||
|
vis,
|
||||||
|
span,
|
||||||
|
macro_rules: false,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,4 +21,6 @@ pub struct ModChild {
|
||||||
pub vis: ty::Visibility,
|
pub vis: ty::Visibility,
|
||||||
/// Span of the item.
|
/// Span of the item.
|
||||||
pub span: Span,
|
pub span: Span,
|
||||||
|
/// A proper `macro_rules` item (not a reexport).
|
||||||
|
pub macro_rules: bool,
|
||||||
}
|
}
|
||||||
|
|
|
@ -133,7 +133,7 @@ impl<'r, 'ast> Visitor<'ast> for AccessLevelsVisitor<'ast, 'r> {
|
||||||
ast::ItemKind::Impl(..) => return,
|
ast::ItemKind::Impl(..) => return,
|
||||||
|
|
||||||
// Only exported `macro_rules!` items are public, but they always are
|
// Only exported `macro_rules!` items are public, but they always are
|
||||||
ast::ItemKind::MacroDef(..) => {
|
ast::ItemKind::MacroDef(ref macro_def) if macro_def.macro_rules => {
|
||||||
let is_macro_export =
|
let is_macro_export =
|
||||||
item.attrs.iter().any(|attr| attr.has_name(sym::macro_export));
|
item.attrs.iter().any(|attr| attr.has_name(sym::macro_export));
|
||||||
if is_macro_export { Some(AccessLevel::Public) } else { None }
|
if is_macro_export { Some(AccessLevel::Public) } else { None }
|
||||||
|
@ -155,7 +155,8 @@ impl<'r, 'ast> Visitor<'ast> for AccessLevelsVisitor<'ast, 'r> {
|
||||||
| ast::ItemKind::Struct(..)
|
| ast::ItemKind::Struct(..)
|
||||||
| ast::ItemKind::Union(..)
|
| ast::ItemKind::Union(..)
|
||||||
| ast::ItemKind::Trait(..)
|
| ast::ItemKind::Trait(..)
|
||||||
| ast::ItemKind::TraitAlias(..) => {
|
| ast::ItemKind::TraitAlias(..)
|
||||||
|
| ast::ItemKind::MacroDef(..) => {
|
||||||
if item.vis.kind.is_pub() {
|
if item.vis.kind.is_pub() {
|
||||||
self.prev_level
|
self.prev_level
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -940,7 +940,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
|
||||||
/// Builds the reduced graph for a single item in an external crate.
|
/// Builds the reduced graph for a single item in an external crate.
|
||||||
fn build_reduced_graph_for_external_crate_res(&mut self, child: ModChild) {
|
fn build_reduced_graph_for_external_crate_res(&mut self, child: ModChild) {
|
||||||
let parent = self.parent_scope.module;
|
let parent = self.parent_scope.module;
|
||||||
let ModChild { ident, res, vis, span } = child;
|
let ModChild { ident, res, vis, span, macro_rules } = child;
|
||||||
let res = res.expect_non_local();
|
let res = res.expect_non_local();
|
||||||
let expansion = self.parent_scope.expansion;
|
let expansion = self.parent_scope.expansion;
|
||||||
// Record primary definitions.
|
// Record primary definitions.
|
||||||
|
@ -972,7 +972,9 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
|
||||||
_,
|
_,
|
||||||
) => self.r.define(parent, ident, ValueNS, (res, vis, span, expansion)),
|
) => self.r.define(parent, ident, ValueNS, (res, vis, span, expansion)),
|
||||||
Res::Def(DefKind::Macro(..), _) | Res::NonMacroAttr(..) => {
|
Res::Def(DefKind::Macro(..), _) | Res::NonMacroAttr(..) => {
|
||||||
self.r.define(parent, ident, MacroNS, (res, vis, span, expansion))
|
if !macro_rules {
|
||||||
|
self.r.define(parent, ident, MacroNS, (res, vis, span, expansion))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Res::Def(
|
Res::Def(
|
||||||
DefKind::TyParam
|
DefKind::TyParam
|
||||||
|
|
|
@ -1399,14 +1399,22 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
|
||||||
let mut reexports = Vec::new();
|
let mut reexports = Vec::new();
|
||||||
|
|
||||||
module.for_each_child(self.r, |_, ident, _, binding| {
|
module.for_each_child(self.r, |_, ident, _, binding| {
|
||||||
// Filter away ambiguous imports and anything that has def-site hygiene.
|
// FIXME: Consider changing the binding inserted by `#[macro_export] macro_rules`
|
||||||
// FIXME: Implement actual cross-crate hygiene.
|
// into the crate root to actual `NameBindingKind::Import`.
|
||||||
let is_good_import =
|
if binding.is_import()
|
||||||
binding.is_import() && !binding.is_ambiguity() && !ident.span.from_expansion();
|
|| matches!(binding.kind, NameBindingKind::Res(_, _is_macro_export @ true))
|
||||||
if is_good_import || binding.is_macro_def() {
|
{
|
||||||
let res = binding.res().expect_non_local();
|
let res = binding.res().expect_non_local();
|
||||||
if res != def::Res::Err {
|
// Ambiguous imports are treated as errors at this point and are
|
||||||
reexports.push(ModChild { ident, res, vis: binding.vis, span: binding.span });
|
// not exposed to other crates (see #36837 for more details).
|
||||||
|
if res != def::Res::Err && !binding.is_ambiguity() {
|
||||||
|
reexports.push(ModChild {
|
||||||
|
ident,
|
||||||
|
res,
|
||||||
|
vis: binding.vis,
|
||||||
|
span: binding.span,
|
||||||
|
macro_rules: false,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -845,10 +845,6 @@ impl<'a> NameBinding<'a> {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_macro_def(&self) -> bool {
|
|
||||||
matches!(self.kind, NameBindingKind::Res(Res::Def(DefKind::Macro(..), _), _))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn macro_kind(&self) -> Option<MacroKind> {
|
fn macro_kind(&self) -> Option<MacroKind> {
|
||||||
self.res().macro_kind()
|
self.res().macro_kind()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue