Skip to content

Commit e3a3239

Browse files
change hack
1 parent d9f8981 commit e3a3239

File tree

2 files changed

+11
-23
lines changed

2 files changed

+11
-23
lines changed

compiler/rustc_resolve/src/imports.rs

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -374,21 +374,16 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
374374
module.underscore_disambiguator.update_unchecked(|d| d + 1);
375375
module.underscore_disambiguator.get()
376376
});
377-
let tcx = self.tcx();
378377
// "Same res different import" ambiguity hack for macros introduced in #145108.
379378
// See related discussion for more info:
380379
// https://rust-lang.zulipchat.com/#narrow/channel/421156-gsoc/topic/Project.3A.20Parallel.20Macro.20Expansion/near/542057918.
381-
if ns == MacroNS && binding.is_glob_import() {
382-
if let Some(def_id) = res.opt_def_id() {
383-
self.greatest_vis_map
384-
.entry(def_id)
385-
.and_modify(|vis| {
386-
if !vis.is_at_least(binding.vis, tcx) {
387-
*vis = binding.vis
388-
}
389-
})
390-
.or_insert(binding.vis);
391-
}
380+
if ns == MacroNS
381+
&& binding.is_glob_import()
382+
&& binding.vis.is_public() // is a glob that reexports a macro
383+
&& self.macro_use_prelude.contains_key(&ident.name) // which also lives in macro_use world
384+
&& let Some(def_id) = res.opt_def_id()
385+
{
386+
self.macro_vis_hack_map.insert(def_id);
392387
}
393388
self.update_local_resolution(module, key, warn_ambiguity, |this, resolution| {
394389
if let Some(old_binding) = resolution.best_binding() {
@@ -1678,14 +1673,8 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
16781673
}
16791674

16801675
let vis = match res.opt_def_id() {
1681-
Some(def_id) => {
1682-
let vis =
1683-
self.greatest_vis_map.get(&def_id).copied().unwrap_or(binding.vis);
1684-
// macros exported through `macro_export` are not placed in this map, so
1685-
// hack the hack and make sure we still keep the best visibility.
1686-
if !vis.is_at_least(binding.vis, self.tcx()) { binding.vis } else { vis }
1687-
}
1688-
None => binding.vis,
1676+
Some(def_id) if self.macro_vis_hack_map.contains(&def_id) => Visibility::Public,
1677+
Some(_) | None => binding.vis,
16891678
};
16901679
children.push(ModChild { ident: ident.0, res, vis, reexport_chain });
16911680
}

compiler/rustc_resolve/src/lib.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1169,8 +1169,7 @@ pub struct Resolver<'ra, 'tcx> {
11691169
/// Crate-local macro expanded `macro_export` referred to by a module-relative path.
11701170
macro_expanded_macro_export_errors: BTreeSet<(Span, Span)> = BTreeSet::new(),
11711171

1172-
// Hack
1173-
greatest_vis_map: FxIndexMap<DefId, Visibility<DefId>>,
1172+
macro_vis_hack_map: FxIndexSet<DefId>,
11741173
/// When a type is re-exported that has an inaccessible constructor because it has fields that
11751174
/// are inaccessible from the import's scope, we mark that as the type won't be able to be built
11761175
/// through the re-export. We use this information to extend the existing diagnostic.
@@ -1595,7 +1594,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
15951594
glob_map: Default::default(),
15961595
used_imports: FxHashSet::default(),
15971596
maybe_unused_trait_imports: Default::default(),
1598-
greatest_vis_map: Default::default(),
1597+
macro_vis_hack_map: Default::default(),
15991598
inaccessible_ctor_reexport: Default::default(),
16001599

16011600
arenas,

0 commit comments

Comments
 (0)