rust-lang / rust-lang/rust

custom inner attributes remove source view for module

Open
#158,768 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-rust-for-linux C-bug F-custom_inner_attributes T-rustdoc
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

Code

When a procedural macro is used as an inner attribute (via #![feature(custom_inner_attributes)]), rustdoc omits that module's source file from the HTML source browser view. When clicking the source view of that module, it jumps to the mod module; declaration. The json output also reports the wrong definition span (the one for the mod module;).

Here's a minimal reproducer:

  • In macros/src/lib.rs:
    // In macros/src/lib.rs
    #[proc_macro_attribute]
    pub fn identity(_args: TokenStream, input: TokenStream) -> TokenStream {
        input
    }
    
  • In src/lib.rs (of course with macros.path = "./macros" in [dependencies]):
    #![feature(custom_inner_attributes, proc_macro_hygiene)]
    pub mod demo;
    
  • In src/demo.rs:
    #![macros::identity]
    
    //! This is the demo module!
    

Expected Outcome

  • When clicking on the source button inside the docs of the reproducer::demo module, I expected to be brought to the file view of src/demo.rs, but it instead shows src/lib.rs.
  • The source view sidebar does not contain src/demo.rs at all.
  • The json output reports that the span of reproducer::demo is inside of src/lib.rs

When the inner attribute macro is removed, all of these behave correctly again.

Actual Output

Image
cat target/doc/reproducer.json | jq '.index'
{
  "0": {
    "id": 0,
    "crate_id": 0,
    "name": "demo",
    "span": {
      "filename": "src/lib.rs",
      "begin": [
        2,
        1
      ],
      "end": [
        2,
        14
      ]
    },
    "visibility": "public",
    "docs": "This is the demo module!",
    "links": {},
    "attrs": [],
    "deprecation": null,
    "inner": {
      "module": {
        "is_crate": false,
        "items": [],
        "is_stripped": false
      }
    }
  },
  "1": {
    "id": 1,
    "crate_id": 0,
    "name": "reproducer",
    "span": {
      "filename": "src/lib.rs",
      "begin": [
        1,
        1
      ],
      "end": [
        2,
        14
      ]
    },
    "visibility": "public",
    "docs": null,
    "links": {},
    "attrs": [
      {
        "other": "#[attr = Feature([custom_inner_attributes#0, proc_macro_hygiene#0])]"
      }
    ],
    "deprecation": null,
    "inner": {
      "module": {
        "is_crate": true,
        "items": [
          0
        ],
        "is_stripped": false
      }
    }
  }
}

Version

rustdoc 1.98.0-nightly (f428d123a 2026-06-19)

@rustbot label +F-custom_inner_attributes

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue with macros/src/lib.rs, src/lib.rs, and src/demo.rs, then inspect rustdoc's generated source view and JSON output for the demo module. Done means src/demo.rs appears in the source sidebar, the source link opens that file, and the JSON span points to it rather than src/lib.rs.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers, documentation
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.