Move example closer to explaination
@@ -296,6 +296,22 @@ type. It is written the same as a [constant item].
Unlike [free] constants, associated constant definitions undergo
[constant evaluation] only when referenced.
+```rust
+struct Struct;
+
+impl Struct {
+ const ID: i32 = 1;
+ // Definition not immediately evaluated
+ const PANIC: () = panic!("compile-time panic");
+}
+
+fn main() {
+ assert_eq!(1, Struct::ID);
+ // Referencing Struct::PANIC causes compilation error
+ // let _ = Struct::PANIC;
+}
+```
+
### Associated Constants Examples
A basic example:
@@ -338,24 +354,6 @@ fn main() {
}
```
-[Constant evaluation] timing:
-
-```rust
-struct Struct;
-
-impl Struct {
- const ID: i32 = 1;
- // Definition not immediately evaluated
- const PANIC: () = panic!("compile-time panic");
-}
-
-fn main() {
- assert_eq!(1, Struct::ID);
- // Referencing Struct::PANIC causes compilation error
- // let _ = Struct::PANIC;
-}
-```
-
[_ConstantItem_]: constant-items.md
[_Function_]: functions.md
[_MacroInvocationSemi_]: ../macros.md#macro-invocation
