rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
96.76k stars 12.5k forks source link

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

Open Aaron1011 opened 3 years ago

Aaron1011 commented 3 years ago

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.

Stupremee commented 3 years ago

@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 commented 3 years ago

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

nerditation commented 9 months ago

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.