Stream: rustdoc

Topic: Rendering the actual value of a `const`


view this post on Zulip Aaron Hill (Jul 10 2021 at 19:54):

I think it would be useful to render the actual (computed) value of a const item in the documentation. For example, pub const VAL: bool = my_const_fn() would render the actual boolean returned by my_const_fn()

view this post on Zulip Aaron Hill (Jul 10 2021 at 19:55):

Obviously, this could start to get tricky with more complex types (e.g. &Foo<Mutex<String>>), so we could start out by just rendering primitives

view this post on Zulip Aaron Hill (Jul 10 2021 at 19:57):

My hidden agenda is to get better rendering of query providers in the rustc internal documentation. If we make all of the provide functions const (which I think it doable on nightly), we could construct DEFAULT_QUERY_PROVIDERS at compile-time. When we 'rendered' the value, we would render each function-pointer field with a link to the actual function implementation

view this post on Zulip Aaron Hill (Jul 10 2021 at 19:57):

Which would allow compiler developers to go to the DEFAULT_QUERY_PROVIDERS page, and then jump to the actual definition of the query they're interested in

view this post on Zulip Aaron Hill (Jul 10 2021 at 20:10):

Oh, it looks like we already do this :laughing:

view this post on Zulip Aaron Hill (Jul 10 2021 at 20:30):

I openeed https://github.com/rust-lang/rust/issues/87038 to track doing this for ADTs in addition to primitives


Last updated: Oct 21 2021 at 22:01 UTC