Skip to content

Commit c3c0a09

Browse files
committed
resolve: Do not resolve visibilities on proc macro definitions twice
1 parent 37c945d commit c3c0a09

File tree

3 files changed

+47
-1
lines changed

3 files changed

+47
-1
lines changed

src/librustc_resolve/build_reduced_graph.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -1149,7 +1149,14 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
11491149
}))
11501150
} else {
11511151
let module = parent_scope.module;
1152-
let vis = self.resolve_visibility(&item.vis);
1152+
let vis = match item.kind {
1153+
// Visibilities must not be resolved non-speculatively twice
1154+
// and we already resolved this one as a `fn` item visibility.
1155+
ItemKind::Fn(..) => self
1156+
.resolve_visibility_speculative(&item.vis, true)
1157+
.unwrap_or(ty::Visibility::Public),
1158+
_ => self.resolve_visibility(&item.vis),
1159+
};
11531160
if vis != ty::Visibility::Public {
11541161
self.insert_unused_macro(ident, item.id, span);
11551162
}
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Proc macro defined with `pub(path)` doesn't ICEs due to resolving the `path` (issue #68921).
2+
3+
// force-host
4+
// no-prefer-dynamic
5+
6+
#![crate_type = "proc-macro"]
7+
8+
extern crate proc_macro;
9+
use proc_macro::*;
10+
11+
#[proc_macro]
12+
pub(self) fn outer(input: TokenStream) -> TokenStream {
13+
//~^ ERROR functions tagged with `#[proc_macro]` must be `pub`
14+
input
15+
}
16+
17+
mod m {
18+
use proc_macro::*;
19+
20+
#[proc_macro]
21+
pub(super) fn inner(input: TokenStream) -> TokenStream {
22+
//~^ ERROR functions tagged with `#[proc_macro]` must currently reside in the root
23+
input
24+
}
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error: functions tagged with `#[proc_macro]` must be `pub`
2+
--> $DIR/visibility-path.rs:12:1
3+
|
4+
LL | pub(self) fn outer(input: TokenStream) -> TokenStream {
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
7+
error: functions tagged with `#[proc_macro]` must currently reside in the root of the crate
8+
--> $DIR/visibility-path.rs:21:5
9+
|
10+
LL | pub(super) fn inner(input: TokenStream) -> TokenStream {
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12+
13+
error: aborting due to 2 previous errors
14+

0 commit comments

Comments
 (0)