File tree Expand file tree Collapse file tree 1 file changed +16
-18
lines changed Expand file tree Collapse file tree 1 file changed +16
-18
lines changed Original file line number Diff line number Diff line change @@ -296,6 +296,22 @@ type. It is written the same as a [constant item].
296296Unlike [ free] constants, associated constant definitions undergo
297297[ constant evaluation] only when referenced.
298298
299+ ``` rust
300+ struct Struct ;
301+
302+ impl Struct {
303+ const ID : i32 = 1 ;
304+ // Definition not immediately evaluated
305+ const PANIC : () = panic! (" compile-time panic" );
306+ }
307+
308+ fn main () {
309+ assert_eq! (1 , Struct :: ID );
310+ // Referencing Struct::PANIC causes compilation error
311+ // let _ = Struct::PANIC;
312+ }
313+ ```
314+
299315### Associated Constants Examples
300316
301317A basic example:
@@ -338,24 +354,6 @@ fn main() {
338354}
339355```
340356
341- [ Constant evaluation] timing:
342-
343- ``` rust
344- struct Struct ;
345-
346- impl Struct {
347- const ID : i32 = 1 ;
348- // Definition not immediately evaluated
349- const PANIC : () = panic! (" compile-time panic" );
350- }
351-
352- fn main () {
353- assert_eq! (1 , Struct :: ID );
354- // Referencing Struct::PANIC causes compilation error
355- // let _ = Struct::PANIC;
356- }
357- ```
358-
359357[ _ConstantItem_ ] : constant-items.md
360358[ _Function_ ] : functions.md
361359[ _MacroInvocationSemi_ ] : ../macros.md#macro-invocation
You can’t perform that action at this time.
0 commit comments