Skip to content

Commit 281641b

Browse files
hack for RustEmbed with updated test
1 parent 0fc36bf commit 281641b

File tree

5 files changed

+21
-47
lines changed

5 files changed

+21
-47
lines changed

compiler/rustc_resolve/src/imports.rs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,17 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
454454
module.underscore_disambiguator.update_unchecked(|d| d + 1);
455455
module.underscore_disambiguator.get()
456456
});
457+
// "Same res different import" ambiguity hack for macros introduced in #145108.
458+
// See related discussion for more info:
459+
// https://rust-lang.zulipchat.com/#narrow/channel/421156-gsoc/topic/Project.3A.20Parallel.20Macro.20Expansion/near/542057918.
460+
if ns == MacroNS
461+
&& decl.is_glob_import()
462+
&& decl.vis.get().is_public() // is a glob that reexports a macro
463+
&& self.macro_use_prelude.contains_key(&ident.name) // which also lives in macro_use world
464+
&& let Some(def_id) = res.opt_def_id()
465+
{
466+
self.macro_vis_hack_map.insert((module, def_id));
467+
}
457468
self.update_local_resolution(module, key, warn_ambiguity, |this, resolution| {
458469
if let Some(old_decl) = resolution.best_decl() {
459470
assert_ne!(decl, old_decl);
@@ -642,7 +653,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
642653
for (import, side_effect) in import_resolutions {
643654
let SideEffect { imported_module, decls: side_effect_bindings } = side_effect;
644655
let parent = import.parent_scope.module;
645-
646656
match (&import.kind, side_effect_bindings) {
647657
(
648658
ImportKind::Single { target, decls, .. },
@@ -1677,12 +1687,13 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
16771687
module.for_each_child(self, |this, ident, _, binding| {
16781688
let res = binding.res().expect_non_local();
16791689
if res != def::Res::Err {
1680-
let child = |reexport_chain| ModChild {
1681-
ident: ident.0,
1682-
res,
1683-
vis: binding.vis(),
1684-
reexport_chain,
1690+
let vis = match res.opt_def_id() {
1691+
Some(def_id) if self.macro_vis_hack_map.contains(&(module, def_id)) => {
1692+
Visibility::Public
1693+
}
1694+
Some(_) | None => binding.vis.get(),
16851695
};
1696+
let child = |reexport_chain| ModChild { ident: ident.0, res, vis, reexport_chain };
16861697
if let Some((ambig_binding1, ambig_binding2)) = binding.descent_to_ambiguity() {
16871698
let main = child(ambig_binding1.reexport_chain(this));
16881699
let second = ModChild {

compiler/rustc_resolve/src/lib.rs

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

1222+
macro_vis_hack_map: FxIndexSet<(Module<'ra>, DefId)>,
12221223
/// When a type is re-exported that has an inaccessible constructor because it has fields that
12231224
/// are inaccessible from the import's scope, we mark that as the type won't be able to be built
12241225
/// through the re-export. We use this information to extend the existing diagnostic.
@@ -1616,6 +1617,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
16161617

16171618
glob_map: Default::default(),
16181619
maybe_unused_trait_imports: Default::default(),
1620+
macro_vis_hack_map: Default::default(),
16191621

16201622
arenas,
16211623
dummy_decl: arenas.new_pub_def_decl(Res::Err, DUMMY_SP, LocalExpnId::ROOT),

tests/ui/imports/same-res-ambigious.fail.stderr

Lines changed: 0 additions & 20 deletions
This file was deleted.

tests/ui/imports/same-res-ambigious.pass.stderr

Lines changed: 0 additions & 20 deletions
This file was deleted.
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
//@ check-pass
12
//@ edition: 2018
23
//@ revisions: fail pass
34
//@[pass] aux-crate: ambigious_extern=same-res-ambigious-extern.rs
45
//@[fail] aux-crate: ambigious_extern=same-res-ambigious-extern-fail.rs
56
// see https://github.com/rust-lang/rust/pull/147196
67

7-
#[derive(ambigious_extern::Embed)] //~ ERROR: derive macro `Embed` is private
8+
#[derive(ambigious_extern::Embed)]
89
struct Foo{}
910

1011
fn main(){}

0 commit comments

Comments
 (0)