Skip to content

Links in doc comments to proc_macro_attribute functions cause rustdoc panic #55399

Closed
@antonok-edm

Description

@antonok-edm

The following code builds successfully but causes a compiler panic when running cargo doc:
src/lib.rs

extern crate proc_macro;

/// [function_name]
#[proc_macro_attribute]
pub fn function_name(_attr: proc_macro::TokenStream, item: proc_macro::TokenStream) -> proc_macro::TokenStream {
    item
}

Cargo.toml

[package]
name = "causes-rustdoc-panic"
version = "0.1.0"

[lib]
proc-macro = true

Compiler error

thread '<unnamed>' panicked at 'called `Option::unwrap()` on a `None` value', libcore/option.rs:355:21

Toolchain

rustc 1.31.0-nightly (4bd4e4130 2018-10-25) running on x86_64-unknown-linux-gnu

Changing function_name to another name, either in the doc comment or the actual function name (but not both), causes cargo doc to succeed with a warning that the link cannot be resolved, as expected.

Using a normal public function in a non-proc_macro library also does not cause a panic, e.g.

/// [function_name]
#[inline]
pub fn function_name(_attr: u8, item: u8) -> u8 {
    item
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-decl-macros-1-2Area: Declarative macros 1.2A-intra-doc-linksArea: Intra-doc links, the ability to link to items in docs by nameI-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️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