diff --git a/src/const_eval.md b/src/const_eval.md index 779b00354e..1aaec8c891 100644 --- a/src/const_eval.md +++ b/src/const_eval.md @@ -232,6 +232,14 @@ 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][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. + +> [!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 [const context]: #const-context @@ -307,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 @@ -336,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