Skip to content

Commit

Permalink
Clarify that unnamed constants are always evaluated at compile time
Browse files Browse the repository at this point in the history
See rust-lang/rust#93838
It seems like everyone is onboard with blessing this behavior as stable.
  • Loading branch information
XrXr committed Feb 3, 2023
1 parent b9ccb09 commit 86691a1
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/items/constant-items.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,17 @@ m!(const _: () = (););
// const _: () = ();
```

Unnamed constants are always [evaluated][const_eval] at compile-time to surface
panics. This happens even within an unused function:

```rust,compile_fail
fn unused_generic_function<T>() {
// A failing compile-time assertion
const _: () = assert!(usize::BITS == 0);
}
```

[const_eval]: ../const_eval.md
[associated constant]: ../items/associated-items.md#associated-constants
[constant value]: ../const_eval.md#constant-expressions
[free]: ../glossary.md#free-item
Expand Down

0 comments on commit 86691a1

Please sign in to comment.