File tree 2 files changed +11
-3
lines changed
2 files changed +11
-3
lines changed Original file line number Diff line number Diff line change @@ -138,7 +138,7 @@ fn foo<T>() -> usize {
138
138
}
139
139
```
140
140
141
- is equivalent to:
141
+ is roughly equivalent to:
142
142
143
143
``` rust
144
144
fn foo <T >() -> usize {
@@ -152,8 +152,13 @@ fn foo<T>() -> usize {
152
152
}
153
153
```
154
154
155
- This also means that const blocks are treated similarly to associated constants.
156
- For example, they are not guaranteed to be evaluated when the enclosing function is unused.
155
+ If the function containing the const block is executed at runtime,
156
+ then the const block is guaranteed to be evaluated. This is true even if the const block occurs in dead code.
157
+ In particular, unsafe code inside a function can rely on the fact that all const blocks syntactically
158
+ occurring in the function have successfully evaluated (and not panicked).
159
+ Note that this is only guaranteed for all currently existing syntactic constructs; in the future, a new
160
+ kind of block may be introduced such that constants inside that block are * not* unconditionally guaranteed to be evaluated.
161
+ If the function is not executed at runtime, const blocks inside of it may or may not be evaluated.
157
162
158
163
## ` unsafe ` blocks
159
164
Original file line number Diff line number Diff line change @@ -23,10 +23,13 @@ let push_integer = Vec::<i32>::push;
23
23
let slice_reverse = <[i32 ]>:: reverse ;
24
24
```
25
25
26
+ Evaluation of associated constants is handled the same way as [ ` const ` blocks] .
27
+
26
28
[ _PathInExpression_ ] : ../paths.md#paths-in-expressions
27
29
[ _QualifiedPathInExpression_ ] : ../paths.md#qualified-paths
28
30
[ place expressions ] : ../expressions.md#place-expressions-and-value-expressions
29
31
[ value expressions ] : ../expressions.md#place-expressions-and-value-expressions
30
32
[ path ] : ../paths.md
31
33
[ `static mut` ] : ../items/static-items.md#mutable-statics
32
34
[ `unsafe` block ] : block-expr.md#unsafe-blocks
35
+ [ `const` blocks ] : block-expr.md#const-blocks
You can’t perform that action at this time.
0 commit comments