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

#[doc(consts)] #3770

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft

Conversation

lolbinarycat
Copy link
Contributor

@lolbinarycat lolbinarycat commented Feb 10, 2025

@fmease fmease added the T-rustdoc Relevant to rustdoc team, which will review and decide on the RFC. label Feb 10, 2025

The `#[doc(consts)]` attribute can be placed on any item to control how contained constant expressions are displayed in rustdoc-generated documentation.

* `#[doc(consts = "fold")]` will show them in their fully-evaluated state.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about "eval" for fully evaluated item and "as-is" for item as written?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"constant folding" is a well established term used for this exact process, and "eval" is much more general (future display modes would likely also involve evaluating the expression).

on the other hand, i don't feel strongly about "expr", but my second choice would probably be "verbatim".

Copy link
Contributor

@tgross35 tgross35 Feb 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does Rust ever refer to CTFE as constant folding? The docs use evaluation https://doc.rust-lang.org/reference/const_eval.html, and to me "const folding" is an identify+transform optimization pass (as opposed to compile-time evaluation that must unconditionally be run).

Different crates and items have conflicting requirements for their constants.
For some, [the exact value of a constant is platform dependant](https://internals.rust-lang.org/t/pre-rfc-doc-consts-attribute/21987/9).
For others, [constant folding obsurces the meaning of values](https://github.com/rust-lang/rust/issues/128347).
Hovever, [showing a constant as written may leak implementation details],

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a link missing here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, it's one of the linked issues in rust-lang/rust#99688 (i'll go dig through it in a bit)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-rustdoc Relevant to rustdoc team, which will review and decide on the RFC.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants