Skip to content

Commit

Permalink
exclude unexported macro bindings from extern crate
Browse files Browse the repository at this point in the history
  • Loading branch information
bvanjoi committed Dec 28, 2023
1 parent 928b3da commit 10d266b
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
3 changes: 2 additions & 1 deletion compiler/rustc_resolve/src/build_reduced_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1071,7 +1071,8 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
let import = macro_use_import(self, span);
self.r.potentially_unused_imports.push(import);
module.for_each_child(self, |this, ident, ns, binding| {
if ns == MacroNS {
if ns == MacroNS && this.r.is_accessible_from(binding.vis, this.parent_scope.module)
{
let imported_binding = this.r.import(binding, import);
this.add_macro_use_binding(ident.name, imported_binding, span, allow_shadowing);
}
Expand Down
2 changes: 2 additions & 0 deletions tests/ui/extern/auxiliary/issue-80074-macro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@

macro_rules! foo_ { () => {}; }
use foo_ as foo;

macro_rules! bar { () => {}; }
4 changes: 3 additions & 1 deletion tests/ui/extern/issue-80074.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
// edition:2018
// build-pass
// aux-crate:issue_80074=issue-80074-macro.rs

#[macro_use]
extern crate issue_80074;

fn main() {
foo!();
//~^ ERROR: cannot find macro `foo` in this scope
bar!();
//~^ ERROR: cannot find macro `bar` in this scope
}
14 changes: 14 additions & 0 deletions tests/ui/extern/issue-80074.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
error: cannot find macro `bar` in this scope
--> $DIR/issue-80074.rs:10:5
|
LL | bar!();
| ^^^

error: cannot find macro `foo` in this scope
--> $DIR/issue-80074.rs:8:5
|
LL | foo!();
| ^^^

error: aborting due to 2 previous errors

0 comments on commit 10d266b

Please sign in to comment.