Skip to content

Commit 88b3daf

Browse files
hack for RustEmbed with updated test
1 parent 079556e commit 88b3daf

File tree

6 files changed

+23
-44
lines changed

6 files changed

+23
-44
lines changed

compiler/rustc_resolve/src/imports.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,17 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
374374
module.underscore_disambiguator.update_unchecked(|d| d + 1);
375375
module.underscore_disambiguator.get()
376376
});
377+
// "Same res different import" ambiguity hack for macros introduced in #145108.
378+
// See related discussion for more info:
379+
// https://rust-lang.zulipchat.com/#narrow/channel/421156-gsoc/topic/Project.3A.20Parallel.20Macro.20Expansion/near/542057918.
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((module, def_id));
387+
}
377388
self.update_local_resolution(module, key, warn_ambiguity, |this, resolution| {
378389
if let Some(old_binding) = resolution.best_binding() {
379390
if res == Res::Err && old_binding.res() != Res::Err {
@@ -623,7 +634,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
623634
for (import, side_effect) in import_resolutions {
624635
let SideEffect { imported_module, bindings: side_effect_bindings } = side_effect;
625636
let parent = import.parent_scope.module;
626-
627637
match (&import.kind, side_effect_bindings) {
628638
(
629639
ImportKind::Single { target, bindings, .. },
@@ -1662,7 +1672,13 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
16621672
next_binding = binding;
16631673
}
16641674

1665-
children.push(ModChild { ident: ident.0, res, vis: binding.vis, reexport_chain });
1675+
let vis = match res.opt_def_id() {
1676+
Some(def_id) if self.macro_vis_hack_map.contains(&(module, def_id)) => {
1677+
Visibility::Public
1678+
}
1679+
Some(_) | None => binding.vis,
1680+
};
1681+
children.push(ModChild { ident: ident.0, res, vis, reexport_chain });
16661682
}
16671683
});
16681684

compiler/rustc_resolve/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1169,6 +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+
macro_vis_hack_map: FxIndexSet<(Module<'ra>, DefId)>,
11721173
/// When a type is re-exported that has an inaccessible constructor because it has fields that
11731174
/// are inaccessible from the import's scope, we mark that as the type won't be able to be built
11741175
/// through the re-export. We use this information to extend the existing diagnostic.
@@ -1593,6 +1594,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
15931594
glob_map: Default::default(),
15941595
used_imports: FxHashSet::default(),
15951596
maybe_unused_trait_imports: Default::default(),
1597+
macro_vis_hack_map: Default::default(),
15961598
inaccessible_ctor_reexport: Default::default(),
15971599

15981600
arenas,

src/tools/rust-analyzer/crates/hir-ty/src/mir/lower/as_place.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use hir_def::FunctionId;
44
use intern::sym;
5-
use rustc_type_ir::inherent::{AdtDef, Region as _, Ty as _};
5+
use rustc_type_ir::inherent::{AdtDef, Region as _};
66

77
use super::*;
88
use crate::{

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)