Skip to content

Commit a5410c9

Browse files
committed
Revise text on initializer provenance restriction
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.
1 parent e77ce18 commit a5410c9

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/const_eval.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,11 +232,13 @@ r[const-eval.const-expr.loop]
232232
r[const-eval.const-expr.if-match]
233233
* [if] and [match] expressions.
234234

235+
## Const initializers
236+
235237
r[const-eval.const-expr.final-value-provenance]
236-
The representation of the final value of a constant or static initializer must only contain provenance in whole-pointer groups: if a byte has provenance but is not part of an adjacent group of bytes that form an entire pointer, compilation will fail.
238+
The representation of the final value of a [constant][constant initializer] or [static initializer] must only contain bytes with provenance in whole-pointer groups. If a byte has provenance but is not part of an adjacent group of bytes that form an entire pointer, compilation will fail.
237239

238-
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.
239-
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.
240+
> [!NOTE]
241+
> 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. `rustc` tries (but does not guarantee) to only actually fail if the initializer copies or overwrites parts of a pointer and those bytes appear in the final value.
240242
241243
r[const-eval.const-context]
242244
## Const context
@@ -313,6 +315,7 @@ The types of a const function's parameters and return type are restricted to tho
313315
[const generic argument]: items/generics.md#const-generics
314316
[const generic parameters]: items/generics.md#const-generics
315317
[constant expressions]: #constant-expressions
318+
[constant initializer]: items.const
316319
[constants]: items/constant-items.md
317320
[Const parameters]: items/generics.md
318321
[dereference expression]: expr.deref
@@ -342,6 +345,7 @@ The types of a const function's parameters and return type are restricted to tho
342345
[promoted]: destructors.md#constant-promotion
343346
[range expressions]: expressions/range-expr.md
344347
[slice]: types/slice.md
348+
[static initializer]: items.static.init
345349
[statics]: items/static-items.md
346350
[Struct expressions]: expressions/struct-expr.md
347351
[temporary lifetime extension]: destructors.scope.lifetime-extension

0 commit comments

Comments
 (0)