Skip to content

Commit 2e15db6

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 2e15db6

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/items/constant-items.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,18 @@ m!(const _: () = (););
8989
// const _: () = ();
9090
```
9191

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

0 commit comments

Comments
 (0)