Skip to content

Commit 24a4f32

Browse files
committed
allow constants to refer to mutable/external memory, but reject such constants as patterns
1 parent ce4d0e0 commit 24a4f32

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

src/items/constant-items.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,6 @@ const BITS_N_STRINGS: BitsNStrings<'static> = BitsNStrings {
4848
};
4949
```
5050

51-
r[items.const.final-value-immutable]
52-
The final value of a `const` item cannot contain references to anything mutable.
53-
5451
r[items.const.expr-omission]
5552
The constant expression may only be omitted in a [trait definition].
5653

src/patterns.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -975,6 +975,9 @@ r[patterns.const.generic]
975975
In particular, the value of `C` must be known at pattern-building time (which is pre-monomorphization).
976976
This means that associated consts that involve generic parameters cannot be used as patterns.
977977

978+
r[patterns.const.immutable]
979+
Finally, the value of `C` must not contain any references to mutable statics (`static mut` or interior mutable) or `extern` statics.
980+
978981
r[patterns.const.translation]
979982
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.
980983
In particular, it fully participates in exhaustiveness checking.

0 commit comments

Comments
 (0)