Skip to content

Commit 86691a1

Browse files
committed
Clarify that unnamed constants are always evaluated at compile time
See rust-lang/rust#93838 It seems like everyone is onboard with blessing this behavior as stable.
1 parent b9ccb09 commit 86691a1

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/items/constant-items.md

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

92+
Unnamed constants are always [evaluated][const_eval] at compile-time to surface
93+
panics. This happens even within an unused function:
94+
95+
```rust,compile_fail
96+
fn unused_generic_function<T>() {
97+
// A failing compile-time assertion
98+
const _: () = assert!(usize::BITS == 0);
99+
}
100+
```
101+
102+
[const_eval]: ../const_eval.md
92103
[associated constant]: ../items/associated-items.md#associated-constants
93104
[constant value]: ../const_eval.md#constant-expressions
94105
[free]: ../glossary.md#free-item

0 commit comments

Comments
 (0)