File tree 1 file changed +24
-0
lines changed
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
67
67
const generic parameter, or an arbitrary expression not making use of any
68
68
generics.
69
69
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
+
70
94
## Const Functions
71
95
72
96
A _ 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