Skip to content

Commit ebab1cd

Browse files
authored
Merge pull request #1328 from XrXr/unamed-const-eval-timing
Clarify that free constants are always evaluated at compile time
2 parents 24c87f6 + 021889f commit ebab1cd

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/items/constant-items.md

+16
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,22 @@ m!(const _: () = (););
8989
// const _: () = ();
9090
```
9191

92+
## Evaluation
93+
94+
[Free][free] constants are always [evaluated][const_eval] at compile-time to surface
95+
panics. This happens even within an unused function:
96+
97+
```rust,compile_fail
98+
// Compile-time panic
99+
const PANIC: () = std::unimplemented!();
100+
101+
fn unused_generic_function<T>() {
102+
// A failing compile-time assertion
103+
const _: () = assert!(usize::BITS == 0);
104+
}
105+
```
106+
107+
[const_eval]: ../const_eval.md
92108
[associated constant]: ../items/associated-items.md#associated-constants
93109
[constant value]: ../const_eval.md#constant-expressions
94110
[free]: ../glossary.md#free-item

0 commit comments

Comments
 (0)