Skip to content

Macro parameters are not substituted in docs for const generics #82978

Closed
@Flying-Toast

Description

@Flying-Toast
Contributor

The generated documentation for const generic expressions generated by macros doesn't substitute macro parameters.

The docs for this code:

pub trait ConstGeneric<const N: usize> {}

macro_rules! trait_impl {
    ($typ:ty) => {
        impl ConstGeneric<{core::mem::size_of::<$typ>()}> for $typ {}
    }
}

trait_impl!(i64);

Look like this:
screenshot

Note that the $typ macro parameter shows up literally in the const expression of the generic. This bug only happens if the macro parameter is in a const expression within the const generic; other occurrences of the macro parameter are properly substituted.

Produced on rustdoc 1.52.0-nightly (3a5d45f68 2021-03-09) and rustdoc 1.51.0-beta.4 (4d25f4607 2021-03-05)

Activity

added
A-const-genericsArea: const generics (parameters and arguments)
T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.
on Mar 10, 2021
jyn514

jyn514 commented on Mar 10, 2021

@jyn514
Member

This looks like a duplicate of #82852.

Flying-Toast

Flying-Toast commented on Mar 10, 2021

@Flying-Toast
ContributorAuthor

@jyn514 I think #82852 is a bit different - that’s about substituting const values, this is relating to substitution of macro parameters.

Unless the intended behavior is for rustdoc to show impl ConstGeneric<8> for i64?

jyn514

jyn514 commented on Mar 10, 2021

@jyn514
Member

Unless the intended behavior is for rustdoc to show impl ConstGeneric<8> for i64?

I think that's what it should show, yes. I'm ok with keeping this issue open for the intermediate step of impl ConstGeneric<{core::mem::size_of::<i64>()}> for i64 {}, but I think in practice it will be easier to fix both at once.

Flying-Toast

Flying-Toast commented on Mar 10, 2021

@Flying-Toast
ContributorAuthor

Ok, makes sense. I’ll close this since it’s really just a subset of #82852 and I don’t want to clutter the issue tracker.

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

    A-const-genericsArea: const generics (parameters and arguments)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

        Participants

        @jonas-schievink@jyn514@Flying-Toast

        Issue actions

          Macro parameters are not substituted in docs for const generics · Issue #82978 · rust-lang/rust