Skip to content

Commit be49428

Browse files
committed
Move example closer to explaination
#1120 (comment)
1 parent 77387cb commit be49428

File tree

1 file changed

+16
-18
lines changed

1 file changed

+16
-18
lines changed

src/items/associated-items.md

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,22 @@ type. It is written the same as a [constant item].
296296
Unlike [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

301317
A 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

0 commit comments

Comments
 (0)