Skip to content

Conversation

@RalfJung
Copy link
Member

This is the docs part for rust-lang/rust#148967.

I had no idea where to put it. Putting it in "const-expr" is odd since that is generally a compositional notion (the subexpressions of a const expression must be const expressions), whereas the limitation I am describing here only applies at the top level, i.e. for the final value of a const/static initializer.

@rustbot rustbot added the S-waiting-on-review Status: The marked PR is awaiting review from a maintainer label Jan 19, 2026
if a byte has provenance but is not part of an adjacent group of bytes that form an entire pointer, compilation will fail.

If a byte in the representation of the final value is uninitialized, then it *may* end up having provenance, which can cause compilation to fail.
As a quality-of-implementation concern, the compiler should only actually fail if the initializer copied or overwrite parts of a pointer and that memory ends up in the final value.
Copy link
Contributor

@traviscross traviscross Jan 19, 2026

Choose a reason for hiding this comment

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

Suggested change
As a quality-of-implementation concern, the compiler should only actually fail if the initializer copied or overwrite parts of a pointer and that memory ends up in the final value.
As a quality-of-implementation concern, the compiler should only actually fail if the initializer copies or overwrites parts of a pointer and that memory ends up in the final value.

(And we'll want to unwrap the lines.)

Copy link
Member Author

Choose a reason for hiding this comment

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

The lines aren't wrapped...?

Copy link
Contributor

@traviscross traviscross Jan 20, 2026

Choose a reason for hiding this comment

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

We'll remove the line break between lines 239 and 240 and between 236 and 237.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, you don't want to break for colons? Okay, sure.

@traviscross
Copy link
Contributor

I had no idea where to put it. Putting it in "const-expr" is odd since that is generally a compositional notion (the subexpressions of a const expression must be const expressions), whereas the limitation I am describing here only applies at the top level, i.e. for the final value of a const/static initializer.

Good question. We had put the restrictions on the final value of a const in the chapter on const items, but given that this applies to static items as well that'd be maybe a bit more annoying.

Maybe @ehuss will have a good idea on this.

@traviscross traviscross added the I-lang-docs-nominated Nominated for discussion during a lang-docs team meeting. label Jan 19, 2026
@RalfJung RalfJung force-pushed the const-eval-final-value-byte-provenance branch 2 times, most recently from 5b019ef to 76556a2 Compare January 20, 2026 15:57
RalfJung and others added 2 commits January 20, 2026 21:33
The text here is describing a restriction on the final value of a
constant or static initializer.  We could put this in the chapters for
constant and static items, but then we'd have to duplicate it.  At the
same time, it doesn't make sense to be in the section for constant
expressions since this is not a restriction on those expressions.

Let's solve this, for now, by keeping it in the chapter on constant
evaluation but putting it in a new "constant initializers" section.

We'll move the second paragraph, which states what a compiler should
do as a "quality-of-implementation" matter, into an admonition, and
we'll reword this a bit to talk about what `rustc` does (but does not
guarantee) to match the style we use for this in other places.

We also add links to the appropriate chapters and sections for
constant and static initializers.
@traviscross traviscross force-pushed the const-eval-final-value-byte-provenance branch from 76556a2 to a5410c9 Compare January 20, 2026 21:33
@rustbot
Copy link
Collaborator

rustbot commented Jan 20, 2026

This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@ehuss ehuss removed the I-lang-docs-nominated Nominated for discussion during a lang-docs team meeting. label Jan 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: The marked PR is awaiting review from a maintainer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants