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

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

Closed
Flying-Toast opened this issue Mar 10, 2021 · 4 comments
Closed

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

Flying-Toast opened this issue Mar 10, 2021 · 4 comments
Labels
A-const-generics Area: const generics (parameters and arguments) C-bug Category: This is a bug. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@Flying-Toast
Copy link
Contributor

Flying-Toast commented Mar 10, 2021

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)

@Flying-Toast Flying-Toast added the C-bug Category: This is a bug. label Mar 10, 2021
@jonas-schievink jonas-schievink added A-const-generics Area: const generics (parameters and arguments) T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels Mar 10, 2021
@jyn514
Copy link
Member

jyn514 commented Mar 10, 2021

This looks like a duplicate of #82852.

@Flying-Toast
Copy link
Contributor Author

Flying-Toast commented Mar 10, 2021

@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
Copy link
Member

jyn514 commented Mar 10, 2021

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
Copy link
Contributor Author

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

3 participants