Skip to content

Commit

Permalink
resolve: Do not resolve visibilities on proc macro definitions twice
Browse files Browse the repository at this point in the history
  • Loading branch information
petrochenkov committed Mar 23, 2020
1 parent 37c945d commit c3c0a09
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/librustc_resolve/build_reduced_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1149,7 +1149,14 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
}))
} else {
let module = parent_scope.module;
let vis = self.resolve_visibility(&item.vis);
let vis = match item.kind {
// Visibilities must not be resolved non-speculatively twice
// and we already resolved this one as a `fn` item visibility.
ItemKind::Fn(..) => self
.resolve_visibility_speculative(&item.vis, true)
.unwrap_or(ty::Visibility::Public),
_ => self.resolve_visibility(&item.vis),
};
if vis != ty::Visibility::Public {
self.insert_unused_macro(ident, item.id, span);
}
Expand Down
25 changes: 25 additions & 0 deletions src/test/ui/proc-macro/visibility-path.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Proc macro defined with `pub(path)` doesn't ICEs due to resolving the `path` (issue #68921).

// force-host
// no-prefer-dynamic

#![crate_type = "proc-macro"]

extern crate proc_macro;
use proc_macro::*;

#[proc_macro]
pub(self) fn outer(input: TokenStream) -> TokenStream {
//~^ ERROR functions tagged with `#[proc_macro]` must be `pub`
input
}

mod m {
use proc_macro::*;

#[proc_macro]
pub(super) fn inner(input: TokenStream) -> TokenStream {
//~^ ERROR functions tagged with `#[proc_macro]` must currently reside in the root
input
}
}
14 changes: 14 additions & 0 deletions src/test/ui/proc-macro/visibility-path.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
error: functions tagged with `#[proc_macro]` must be `pub`
--> $DIR/visibility-path.rs:12:1
|
LL | pub(self) fn outer(input: TokenStream) -> TokenStream {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: functions tagged with `#[proc_macro]` must currently reside in the root of the crate
--> $DIR/visibility-path.rs:21:5
|
LL | pub(super) fn inner(input: TokenStream) -> TokenStream {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 2 previous errors

0 comments on commit c3c0a09

Please sign in to comment.