Skip to content

doc does not correctly display macro match arms if they are created inside of a proc macro #43759

Closed

Description

@lcnr

When creating a macro tagged with #[macro_export] inside of a proc_macro_derive the documentation incorrectly displays the name of the derive instead of the match pattern.

I tried this code: (everything is the same as here except for "main.rs" and "impl_hello_world()").

main.rs:

#[macro_use]
extern crate hello_world_derive;

#[derive(HelloWorld)]
struct Foo {
}

fn main() {
    Foo!("Hi");
}

hello-world-derive/src/lib.rs:

/* ... */

fn impl_hello_world(ast: &syn::DeriveInput) -> quote::Tokens {
    let name = &ast.ident;
    quote! {
        #[macro_export]
        macro_rules! #name {
            ($expr:expr) => {
                println!("expr: {}", $expr);
            }
        }
    }
}

When opening the automatic documentation(cargo doc --open) I expected Foo! to look like this:

macro_rules! Foo {
    ($expr:expr) => { ... };
}

Instead, Foo looked like this: ( the name of the derive instead of the actual match pattern.)

macro_rules! Foo {
    HelloWorld => { ... };
}

In case the created macro has more than 1 match arm it looks like this:

macro_rules! Foo {
    HelloWorld => { ... };
    HelloWorld => { ... };
}

Meta

rustc --version --verbose:

rustc 1.19.0 (0ade339 2017-07-17)
binary: rustc
commit-hash: 0ade339
commit-date: 2017-07-17
host: x86_64-pc-windows-msvc
release: 1.19.0
LLVM version: 4.0

Activity

  1. changed the title [-]doc does not correctly display macro match arms if they are created inside of a proc macro-[/-] [+]doc does not correctly display macro match arms if they are created inside of a proc macro[/+] on Aug 9, 2017
  2. added
    T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.
    C-bugCategory: This is a bug.
    T-dev-toolsRelevant to the dev-tools subteam, which will review and decide on the PR/issue.
    on Aug 10, 2017
  3. removed
    T-dev-toolsRelevant to the dev-tools subteam, which will review and decide on the PR/issue.
    on Jan 18, 2022
  4. camelid commented on May 22, 2024

    @camelid
    Member

    I tested this, and it is fixed now. I believe it was fixed in #86282.

    Updated proc-macro code based on modern Rust:

    use proc_macro::TokenStream;
    use quote::quote;
    
    #[proc_macro_derive(HelloWorld)]
    pub fn impl_hello_world(input: TokenStream) -> TokenStream {
        let ast: syn::DeriveInput = syn::parse(input).unwrap();
        let name = &ast.ident;
        quote! {
            #[macro_export]
            macro_rules! #name {
                ($expr:expr) => {
                    println!("expr: {}", $expr);
                }
            }
        }.into()
    }

    image

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

    C-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