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 @@ -67,6 +67,30 @@ surrounding generic parameters: such an expression must either be a single bare
6767const generic parameter, or an arbitrary expression not making use of any
6868generics.
6969
70+ ## Permitted use of ` static ` s
71+
72+ Within the constant evaluation context, items that ultimately contain no mutable memory or data that is
73+ capable of interior mutability can be used, borrowed or taken address of.
74+ Among those are the ` static ` items as long as they are not actually ` mut ` items.
75+
76+ ``` rust
77+ const fn allowed () -> & 'static u32 {
78+ static VALUE : u32 = 0 ;
79+ & VALUE
80+ }
81+ const A_CONST : & 'static u32 = allowed ();
82+ ```
83+
84+ On the contrary, for example, ` static mut ` and types embedding an ` UnsafeCell ` is not allowed.
85+
86+ ``` rust,edition2021,compile_fail
87+ const fn not_allowed() -> &'static u32 {
88+ static mut VALUE: u32 = 0;
89+ &VALUE
90+ }
91+ const WILL_FAIL: &'static u32 = not_allowed();
92+ ```
93+
7094## Const Functions
7195
7296A _ 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