Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
lcnr opened this issue Aug 9, 2017 · 1 comment
Labels
C-bug Category: This is a bug. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@lcnr
Copy link
Contributor

lcnr commented Aug 9, 2017

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

@lcnr lcnr 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 Aug 9, 2017
@Mark-Simulacrum Mark-Simulacrum added T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. C-bug Category: This is a bug. T-dev-tools Relevant to the dev-tools subteam, which will review and decide on the PR/issue. labels Aug 10, 2017
@ehuss ehuss removed the T-dev-tools Relevant to the dev-tools subteam, which will review and decide on the PR/issue. label Jan 18, 2022
@camelid
Copy link
Member

camelid commented May 22, 2024

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

@camelid camelid closed this as completed May 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants