From e77ce185045d069b4a811426f22661408c3ea50a Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Mon, 19 Jan 2026 11:02:16 +0100 Subject: [PATCH 1/2] const-eval: explain the final-value-byte-provenance restriction --- src/const_eval.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/const_eval.md b/src/const_eval.md index 779b00354e..295be5c1ae 100644 --- a/src/const_eval.md +++ b/src/const_eval.md @@ -232,6 +232,12 @@ r[const-eval.const-expr.loop] r[const-eval.const-expr.if-match] * [if] and [match] expressions. +r[const-eval.const-expr.final-value-provenance] +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. + +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 copies or overwrites parts of a pointer and that memory ends up in the final value. + r[const-eval.const-context] ## Const context [const context]: #const-context From a5410c91b37a619fe0664793eec62bdafb6b5493 Mon Sep 17 00:00:00 2001 From: Travis Cross Date: Tue, 20 Jan 2026 21:15:34 +0000 Subject: [PATCH 2/2] 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. --- src/const_eval.md | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/const_eval.md b/src/const_eval.md index 295be5c1ae..1aaec8c891 100644 --- a/src/const_eval.md +++ b/src/const_eval.md @@ -232,11 +232,13 @@ r[const-eval.const-expr.loop] r[const-eval.const-expr.if-match] * [if] and [match] expressions. +## Const initializers + r[const-eval.const-expr.final-value-provenance] -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. +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. -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 copies or overwrites parts of a pointer and that memory ends up in the final value. +> [!NOTE] +> 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. r[const-eval.const-context] ## Const context @@ -313,6 +315,7 @@ The types of a const function's parameters and return type are restricted to tho [const generic argument]: items/generics.md#const-generics [const generic parameters]: items/generics.md#const-generics [constant expressions]: #constant-expressions +[constant initializer]: items.const [constants]: items/constant-items.md [Const parameters]: items/generics.md [dereference expression]: expr.deref @@ -342,6 +345,7 @@ The types of a const function's parameters and return type are restricted to tho [promoted]: destructors.md#constant-promotion [range expressions]: expressions/range-expr.md [slice]: types/slice.md +[static initializer]: items.static.init [statics]: items/static-items.md [Struct expressions]: expressions/struct-expr.md [temporary lifetime extension]: destructors.scope.lifetime-extension