From cb74f784c05c15d946158b699f2d175a74bb004e Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sun, 22 Sep 2024 08:01:50 +0200 Subject: [PATCH] do not talk about the 'address of a constant' --- src/items/constant-items.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/items/constant-items.md b/src/items/constant-items.md index 9fb218519..f6ba8da73 100644 --- a/src/items/constant-items.md +++ b/src/items/constant-items.md @@ -14,13 +14,12 @@ guaranteed to refer to the same memory address. The constant declaration defines the constant value in the [value namespace] of the module or block where it is located. Constants must be explicitly typed. The type must have a `'static` lifetime: any -references in the initializer must have `'static` lifetimes. +references in the initializer must have `'static` lifetimes. References +in the type of a constant default to `'static` lifetime; see [static lifetime +elision]. -Constants may refer to the address of other constants, in which case the -address will have elided lifetimes where applicable, otherwise -- in most cases --- defaulting to the `static` lifetime. (See [static lifetime -elision].) The compiler is, however, still at liberty to translate the constant -many times, so the address referred to may not be stable. +A reference to a constant will have `'static` lifetime if the constant value is eligible for +[promotion]; otherwise, a temporary will be created. ```rust const BIT1: u32 = 1 << 0; @@ -118,3 +117,4 @@ fn unused_generic_function() { [_Expression_]: ../expressions.md [`Copy`]: ../special-types-and-traits.md#copy [value namespace]: ../names/namespaces.md +[promotion]: ../destructors.md#constant-promotion