Skip to content

proc_macro_attribute dependency #866

Closed
@exellian

Description

@exellian

Let's assume you have two user defined proc_macro_attributes in the following order:

struct Test {}

#[depends_on_inner]
impl Test {

    #[inner]
    fn test() {

    }
}

Is there any way to hand over information between these two macro executions, so that depends_on_inner knows that impl Test has a function with a #[inner] attribute?

Activity

ehuss

ehuss commented on Jul 31, 2020

@ehuss
Contributor

I'm uncertain if there's a common way to relay information. depends_on_inner can parse its input and notice the presence of the inner attribute, but I'm uncertain if that's guaranteed (see #692 and its linked issues).

Questions like these should be asked on one of the user forums, like https://users.rust-lang.org/.

exellian

exellian commented on Aug 1, 2020

@exellian
Author

Ok thanks!

Caellian

Caellian commented on Sep 28, 2023

@Caellian

For future reference if anyone stumbles upon this issue:

Instead of defining #[inner] as a separate macro, process it (assuming you're using syn) by detecting it from ImplItem::attributes and then passing it to the same processor fn you otherwise would. If you need #[inner] to work on its own you must name the version bound to #[depends_on_inner] differently as order of expansion is not guaranteed and might change depending on target/version.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @ehuss@Caellian@exellian

        Issue actions

          proc_macro_attribute dependency · Issue #866 · rust-lang/reference