From 86691a19e84f74481a1ff8574c146ac5150047bb Mon Sep 17 00:00:00 2001 From: Alan Wu Date: Fri, 3 Feb 2023 15:25:57 -0500 Subject: [PATCH] Clarify that unnamed constants are always evaluated at compile time See https://github.com/rust-lang/rust/issues/93838 It seems like everyone is onboard with blessing this behavior as stable. --- src/items/constant-items.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/items/constant-items.md b/src/items/constant-items.md index bf315932f..258c0ce5d 100644 --- a/src/items/constant-items.md +++ b/src/items/constant-items.md @@ -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() { + // 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