From 24a4f323f4fee7fb525821a2dddb65c48ce950f3 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sat, 14 Jun 2025 08:24:32 +0200 Subject: [PATCH] allow constants to refer to mutable/external memory, but reject such constants as patterns --- src/items/constant-items.md | 3 --- src/patterns.md | 3 +++ 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/items/constant-items.md b/src/items/constant-items.md index be94be6cb..269d10aec 100644 --- a/src/items/constant-items.md +++ b/src/items/constant-items.md @@ -48,9 +48,6 @@ const BITS_N_STRINGS: BitsNStrings<'static> = BitsNStrings { }; ``` -r[items.const.final-value-immutable] -The final value of a `const` item cannot contain references to anything mutable. - r[items.const.expr-omission] The constant expression may only be omitted in a [trait definition]. diff --git a/src/patterns.md b/src/patterns.md index 60cfb21c4..df9c7c0c3 100644 --- a/src/patterns.md +++ b/src/patterns.md @@ -975,6 +975,9 @@ r[patterns.const.generic] In particular, the value of `C` must be known at pattern-building time (which is pre-monomorphization). This means that associated consts that involve generic parameters cannot be used as patterns. +r[patterns.const.immutable] +Finally, the value of `C` must not contain any references to mutable statics (`static mut` or interior mutable) or `extern` statics. + r[patterns.const.translation] After ensuring all conditions are met, the constant value is translated into a pattern, and now behaves exactly as-if that pattern had been written directly. In particular, it fully participates in exhaustiveness checking.