Skip to content

Commit

Permalink
document guarantee about evaluation of associated consts
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed May 10, 2024
1 parent 5e8b3f6 commit 52b889c
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/expressions/path-expr.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ let push_integer = Vec::<i32>::push;
let slice_reverse = <[i32]>::reverse;
```

If the path denotes an associated constant, and if the function containing the expression is executed at runtime,
then the associated constant is guaranteed to be evaluated. This is true even if the path expression occurs in dead code.
In particular, unsafe code inside a function can rely on the fact that all associated constants syntactically
occurring in the function have successfully evaluated (and not panicked).
Note that this is only guaranteed for all currently existing syntactic constructs; in the future, a new
kind of block may be introduced such that constants inside that block are *not* unconditionally guaranteed to be evaluated.
If the function is not executed at runtime, associated constants inside of it may or may not be evaluated.

[_PathInExpression_]: ../paths.md#paths-in-expressions
[_QualifiedPathInExpression_]: ../paths.md#qualified-paths
[place expressions]: ../expressions.md#place-expressions-and-value-expressions
Expand Down

0 comments on commit 52b889c

Please sign in to comment.