Skip to content

Rustdoc generate wrong doc for declarative macro generated by derive macro. #79289

Description

@Evian-Zhang

First, write a derive macro which generates a declarative macro:

use quote::quote;

#[proc_macro_derive(MyDeriveMacro)]
pub fn derive_my_derive_macro(item: proc_macro::TokenStream) -> proc_macro::TokenStream {
    proc_macro::TokenStream::from(quote! {
        #[macro_export]
        macro_rules! my_generated_macro {
            ($my_macro_parameter: expr) => {};
        }
    })
}

Then in another crate, import this derive macro and use it:

#[derive(MyDeriveMacro)]
struct MyStruct {}

Then use

cargo doc

to generate the docs.

The doc for my_generated_macro should be

macro_rules! my_generated_macro {
    ($my_macro_parameter: expr) => {};
}

But instead, it turns out

macro_rules! my_generated_macro {
    MyDeriveMacro => {};
}

This is very confusing, since the parameters of the generated declarative macro are all missing, and instead is name of the derive macro which generated it.

Meta

rustc --version --verbose:

rustc 1.48.0 (7eac88abb 2020-11-16)
binary: rustc
commit-hash: 7eac88abb2e57e752f3302f02be5f3ce3d7adfb4
commit-date: 2020-11-16
host: x86_64-apple-darwin
release: 1.48.0
LLVM version: 11.0

Activity

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.T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions