This attribute would control how various constant expressions are displayed in documentation, such as values of generic const parameters, C-style enum discriminants, and the RHS of static and const items. It would also apply to the default value of struct fields, if/when those are implemented.
It could appear on any item (module, struct, impl block, etc.) and would affect that item and any nested items (note that to affect associated items of a struct, you need to tag the impl block). The innermost #[doc(consts)] attribute would take priority, allowing you to set a full-crate default and then override it for specific items or modules.
There are three main values for it (names subject to bikeshedding):
"fold": show constants in their fully evaluated form
"expr": show constants as-written
"hide": do not show constants, replacing them with _
Future possibilities include a fold_hex value to display integer constants in hexadecimal.
I like this idea. It lets documentation authors control a sometimes-important part of their documentation, where they are currently stuck with rustdoc having exactly one behavior (which sometimes exposes implementation details). All three options are appropriate in different situations.
I believe the default interpretation is "everything not in the documentation is semver-excempt", with a few explicit exceptions, such as lifetime variance.
Lack of formal guidelines for semver comparability is a separate issue, and should be addressed separately (ideally, each library would document guarantees for what it considers a breaking change, but we do not live in an ideal world)
This issue can be worked around by crates that use this attribute for semver compatibility reasons having a line in their documentation that the values of hidden constant expressions are semver exempt.
no. the entire reason this is a discussion is that rustdoc used to show constants as-written, but that was changed because it was leaking implementation details.
This is still less useful than knowing it is usize::MAX >> 3 here because even the hex value is a lie if I'm looking at docs.rs but developing for a 32bit platform. I think this is really best if it is author-controlled rather than working around heuristics.
Is this something that needs an RFC (seems like it to me)? Anyone want to draft one up? I might be able to help with some implementation and/or review (I've done some attribute stuff in rustc before, but it has been a while).