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

rustdoc: When rendering const values, show ADTs in addition to primitives. #87038

Open
Aaron1011 opened this issue Jul 10, 2021 · 3 comments
Open
Assignees
Labels
A-rustdoc-ui Area: Rustdoc UI (generated HTML) C-enhancement Category: An issue proposing an enhancement or a PR with one. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@Aaron1011
Copy link
Member

Aaron1011 commented Jul 10, 2021

When rustdoc renders a const item, it will print the actual (evaluated) value for primitives. For example, https://doc.rust-lang.org/std/i32/constant.MAX.html:

const_val

It would be useful to do the same for ADT values (structs, enums, and unions). For example:

struct Foo { val: bool }
const fn make_foo() { Foo { val: true } }`
const FOO: Foo = make_foo()

would print something like:

Foo {
    val: true
}

on the page for FOO.

@Aaron1011 Aaron1011 added C-enhancement Category: An issue proposing an enhancement or a PR with one. A-rustdoc-ui Area: Rustdoc UI (generated HTML) labels Jul 10, 2021
@Aaron1011 Aaron1011 changed the title rustdoc: When rendering const values, show ADS in addition to primitives. rustdoc: When rendering const values, show ADTs in addition to primitives. Jul 10, 2021
Aaron1011 added a commit to Aaron1011/rust that referenced this issue Jul 10, 2021
All of the `provide` functions are made `const`, allowing
us to compute the default local and extern query providers
entirely at compile-time.

In addition to moving runtime work to compile-time, this will
allow our internal documentation to show all query implementations,
once rust-lang#87038 is implemented.
@jonas-schievink jonas-schievink added the T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. label Jul 10, 2021
@Stupremee
Copy link
Member

@rustbot claim

Should the struct just be printed in one line like the integers currently? That seems like the simplest solution and closest to the number constants but may be really messy for larger structs.

@RalfJung
Copy link
Member

Does rustdoc have its own printing code for constants or is it using the MIR pretty-printer?

@nerditation
Copy link

is this feature still being worked on? can we first make the simple cases work, where the type of the constant is a transparent wrapper of primitive types, this pattern is used by many bitflag types and ffi binding types.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-rustdoc-ui Area: Rustdoc UI (generated HTML) C-enhancement Category: An issue proposing an enhancement or a PR with one. 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

5 participants