Skip to content

Proc macro fn cannot be exported except from the crate root #124068

@workingjubilee

Description

@workingjubilee
Member

...that's all I've got, tbh.

it's mentioned as a limitation but I have no idea why. I genuinely looked for an issue about this but couldn't find one? maybe my issue-finding-fu is just weakened by this late hour. this makes me feel obligated to open a bug.

   Compiling pgrx-macros v0.12.0-alpha.1 (/home/jubilee/pgrx/pgrx-macros)
error: functions tagged with `#[proc_macro_attribute]` must currently reside in the root of the crate
  --> pgrx-macros/src/operators.rs:20:1
   |
20 | pub fn opname(_attr: TokenStream, item: TokenStream) -> TokenStream {
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: could not compile `pgrx-macros` (lib) due to 1 previous error
warning: build failed, waiting for other jobs to finish...
error: could not compile `pgrx-macros` (lib) due to 1 previous error

why this?

I have a macro crate with 1200 lines in its lib.rs already! and it's only 1200 because half of the macros have poor-to-zero documentation!

Meta

rustc --version --verbose:

rustc 1.77.2 (25ef9e3d8 2024-04-09)
binary: rustc
commit-hash: 25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04
commit-date: 2024-04-09
host: x86_64-unknown-linux-gnu
release: 1.77.2
LLVM version: 17.0.6

Activity

added
A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)
C-bugCategory: This is a bug.
on Apr 17, 2024
added
needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.
on Apr 17, 2024
ChayimFriedman2

ChayimFriedman2 commented on Apr 17, 2024

@ChayimFriedman2
Contributor

The usual workaround is to put only the macro declarations in lib.rs and the implementation in modules.

workingjubilee

workingjubilee commented on Apr 17, 2024

@workingjubilee
MemberAuthor

@ChayimFriedman2 I'm aware there are workarounds, of course! What I'm asking about is why I am forced to use this software architecture?

added and removed
needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.
on Apr 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)A-proc-macrosArea: Procedural macrosC-bugCategory: This is a bug.WG-macrosWorking group: Macros

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @saethlin@ChayimFriedman2@workingjubilee@rustbot

        Issue actions

          Proc macro fn cannot be exported except from the crate root · Issue #124068 · rust-lang/rust