Skip to content

Commit fc67af1

Browse files
committedAug 25, 2021
Do not reexport macros that are already at the crate root.
1 parent 3646bc2 commit fc67af1

File tree

3 files changed

+19
-11
lines changed

3 files changed

+19
-11
lines changed
 

‎compiler/rustc_metadata/src/rmeta/decoder.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1102,9 +1102,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
11021102
let def_id = self.local_def_id(child_index);
11031103
let res = Res::Def(kind, def_id);
11041104

1105-
if !kind.is_macro() {
1106-
callback(Export { res, ident, vis, span });
1107-
}
1105+
callback(Export { res, ident, vis, span });
11081106

11091107
// For non-re-export structs and variants add their constructors to children.
11101108
// Re-export lists automatically contain constructors when necessary.

‎compiler/rustc_resolve/src/imports.rs

+18-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use rustc_data_structures::fx::FxHashSet;
1616
use rustc_data_structures::ptr_key::PtrKey;
1717
use rustc_errors::{pluralize, struct_span_err, Applicability};
1818
use rustc_hir::def::{self, PartialRes};
19-
use rustc_hir::def_id::DefId;
19+
use rustc_hir::def_id::{DefId, CRATE_DEF_INDEX};
2020
use rustc_middle::hir::exports::Export;
2121
use rustc_middle::span_bug;
2222
use rustc_middle::ty;
@@ -1392,9 +1392,23 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
13921392
// FIXME: Implement actual cross-crate hygiene.
13931393
let is_good_import =
13941394
binding.is_import() && !binding.is_ambiguity() && !ident.span.from_expansion();
1395-
if is_good_import || binding.is_macro_def() {
1396-
let res = binding.res().map_id(|id| this.local_def_id(id));
1397-
if res != def::Res::Err {
1395+
let res = binding.res();
1396+
if res == Res::Err {
1397+
// Do not insert failed resolutions.
1398+
return;
1399+
} else if is_good_import {
1400+
let res = res.map_id(|id| this.local_def_id(id));
1401+
reexports.push(Export { ident, res, span: binding.span, vis: binding.vis });
1402+
} else if let NameBindingKind::Res(Res::Def(def_kind, macro_def_id), true) =
1403+
binding.kind
1404+
{
1405+
let macro_is_at_root = macro_def_id
1406+
.as_local()
1407+
.and_then(|macro_def_id| this.definitions.def_key(macro_def_id).parent)
1408+
== Some(CRATE_DEF_INDEX);
1409+
// Insert a re-export at crate root for exported macro_rules defined elsewhere.
1410+
if module.parent.is_none() && !macro_is_at_root {
1411+
let res = def::Res::Def(def_kind, macro_def_id);
13981412
reexports.push(Export { ident, res, span: binding.span, vis: binding.vis });
13991413
}
14001414
}

‎compiler/rustc_resolve/src/lib.rs

-4
Original file line numberDiff line numberDiff line change
@@ -815,10 +815,6 @@ impl<'a> NameBinding<'a> {
815815
)
816816
}
817817

818-
fn is_macro_def(&self) -> bool {
819-
matches!(self.kind, NameBindingKind::Res(Res::Def(DefKind::Macro(..), _), _))
820-
}
821-
822818
fn macro_kind(&self) -> Option<MacroKind> {
823819
self.res().macro_kind()
824820
}

0 commit comments

Comments
 (0)
Please sign in to comment.