File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -71,6 +71,30 @@ surrounding generic parameters: such an expression must either be a single bare
7171const generic parameter, or an arbitrary expression not making use of any
7272generics.
7373
74+ ## Permitted use of ` static ` s
75+
76+ Within the constant evaluation context, items that ultimately contain no mutable memory or data that is
77+ capable of interior mutability can be used, borrowed or taken address of.
78+ Among those are the ` static ` items as long as they are not actually ` mut ` items.
79+
80+ ``` rust
81+ const fn allowed () -> & 'static u32 {
82+ static VALUE : u32 = 0 ;
83+ & VALUE
84+ }
85+ const A_CONST : & 'static u32 = allowed ();
86+ ```
87+
88+ On the contrary, for example, ` static mut ` and types embedding an ` UnsafeCell ` is not allowed.
89+
90+ ``` rust,edition2021,compile_fail
91+ const fn not_allowed() -> &'static u32 {
92+ static mut VALUE: u32 = 0;
93+ &VALUE
94+ }
95+ const WILL_FAIL: &'static u32 = not_allowed();
96+ ```
97+
7498## Const Functions
7599
76100A _ const fn_ is a function that one is permitted to call from a const context. Declaring a function
You can’t perform that action at this time.
0 commit comments