Skip to content

Switch proc macro docs to be on re-exports so we can have doc links to outer crate items #247

@sam0x17

Description

@sam0x17

Right now the frame proc macros (especially the pallet:: ones) follow the pattern of documenting proc macros inside their corresponding inner proc macro crates (i.e. frame_support_procedural). I standardized this in a number of places in paritytech/substrate#12333 / paritytech/substrate#12334.

A major reason for this is tools like rust-analyzer right now do not conform with the cargo doc behavior of prepending docs that are attached to re-exported items (i.e. macros, functions, traits, etc) and in fact completely ignore docs on re-exports (see my companion issue in rust-analyzer: rust-lang/rust-analyzer#13431).

This is why in paritytech/substrate#12334 I ended up switching all of the pallet:: macros to have their docs inside frame_support_procedural because then rust-analyzer will actually pick them up upon mouse-over.

The problem with this is inner crates can only generate doc links to items that are visible from the inner crate. For non-proc-macro crates the workaround is easy -- simply set up a circular reference between the inner crate and the outer crate so the outer crate items are visible/linkable from the inner crate. This doesn't work for proc macro crates, however, because rust restricts proc macro crates so that they are only allowed to publicly export proc macros (no other items are allowed), so even if we pub use outer_crate::* to make all the outer crate's items accessible within the inner crate, this will fail to compile since we are trying to export something other than a proc macro in a proc macro crate.

Thus we are at a bit of a stand-still. Ideally rust-analyzer would handle docs on re-exports properly the way cargo doc does and we would switch to only documenting proc macros where their re-exports are defined in the outer crate.

So this is blocked until rust-lang/rust-analyzer#13431 is addressed in rust-analyzer or some other solution (like better support for inter-crate doc linking) is added to rust.

One possible alternative solution would be to link directly to the docs.rs links for the outer items from the inner macro declarations. This has some obvious downsides (like rust-analyzer will open a web browser instead of following the links inline), but if this issue sits for a long period of time this might be the way to go.

Note: the one thing I haven't tried is trying to pub use the outer crate items in the inner proc macro crate while gating this with a #[cfg(doc)] directive. I doubt it will compile but it's the only thing I haven't tried so would be cool if someone could confirm (or if someone knows) that this doesn't work.

Related Issues

Related PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    C1-mentorA task where a mentor is available. Please indicate in the issue who the mentor could be.D0-easyCan be fixed primarily by duplicating and adapting code by an intermediate coder.T1-FRAMEThis PR/Issue is related to core FRAME, the framework.

    Type

    No type

    Projects

    Status

    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions