Skip to content

Commit 011cbb6

Browse files
committed
Move the same-crate example into the same-crate rule
1 parent fc0f4e5 commit 011cbb6

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

src/attributes/type_system.md

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,22 @@ more fields or variants added in the future.
3737
> #[non_exhaustive] Reaction(u32),
3838
> #[non_exhaustive] Quit,
3939
> }
40+
> ```
41+
42+
r[attributes.type-system.non_exhaustive.allowed-positions]
43+
It can be applied to [`struct`s][struct], [`enum`s][enum], and `enum` variants.
44+
45+
r[attributes.type-system.non_exhaustive.syntax]
46+
The `non_exhaustive` attribute uses the [MetaWord] syntax and thus does not
47+
take any inputs.
48+
49+
r[attributes.type-system.non_exhaustive.same-crate]
50+
Within the defining crate, `non_exhaustive` has no effect.
51+
52+
> [!EXAMPLE]
53+
> Using the definitions from [above][attributes.type-system.non_exhaustive.intro], the following examples when used within the same crate are allowed without restrictions.
4054
>
55+
> ```rust,ignore
4156
> // Non-exhaustive structs can be constructed as normal within the defining crate.
4257
> let config = Config { window_width: 640, window_height: 480 };
4358
> let token = Token;
@@ -65,15 +80,6 @@ more fields or variants added in the future.
6580
> }
6681
> ```
6782
68-
r[attributes.type-system.non_exhaustive.allowed-positions]
69-
It can be applied to [`struct`s][struct], [`enum`s][enum], and `enum` variants.
70-
71-
r[attributes.type-system.non_exhaustive.syntax]
72-
The `non_exhaustive` attribute uses the [MetaWord] syntax and thus does not
73-
take any inputs.
74-
75-
r[attributes.type-system.non_exhaustive.same-crate]
76-
Within the defining crate, `non_exhaustive` has no effect.
7783
7884
r[attributes.type-system.non_exhaustive.external-crate]
7985
Outside of the defining crate, types annotated with `non_exhaustive` have limitations that

0 commit comments

Comments
 (0)