Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 10d266b

Browse files
committedDec 28, 2023
exclude unexported macro bindings from extern crate
1 parent 928b3da commit 10d266b

File tree

4 files changed

+21
-2
lines changed

4 files changed

+21
-2
lines changed
 

‎compiler/rustc_resolve/src/build_reduced_graph.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1071,7 +1071,8 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
10711071
let import = macro_use_import(self, span);
10721072
self.r.potentially_unused_imports.push(import);
10731073
module.for_each_child(self, |this, ident, ns, binding| {
1074-
if ns == MacroNS {
1074+
if ns == MacroNS && this.r.is_accessible_from(binding.vis, this.parent_scope.module)
1075+
{
10751076
let imported_binding = this.r.import(binding, import);
10761077
this.add_macro_use_binding(ident.name, imported_binding, span, allow_shadowing);
10771078
}

‎tests/ui/extern/auxiliary/issue-80074-macro.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@
22

33
macro_rules! foo_ { () => {}; }
44
use foo_ as foo;
5+
6+
macro_rules! bar { () => {}; }

‎tests/ui/extern/issue-80074.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
// edition:2018
2-
// build-pass
32
// aux-crate:issue_80074=issue-80074-macro.rs
43

54
#[macro_use]
65
extern crate issue_80074;
76

87
fn main() {
98
foo!();
9+
//~^ ERROR: cannot find macro `foo` in this scope
10+
bar!();
11+
//~^ ERROR: cannot find macro `bar` in this scope
1012
}

‎tests/ui/extern/issue-80074.stderr

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error: cannot find macro `bar` in this scope
2+
--> $DIR/issue-80074.rs:10:5
3+
|
4+
LL | bar!();
5+
| ^^^
6+
7+
error: cannot find macro `foo` in this scope
8+
--> $DIR/issue-80074.rs:8:5
9+
|
10+
LL | foo!();
11+
| ^^^
12+
13+
error: aborting due to 2 previous errors
14+

0 commit comments

Comments
 (0)
Please sign in to comment.