Skip to content

Commit 2b5d973

Browse files
committed
Add identifier syntax to attributes.type_system
1 parent 0657657 commit 2b5d973

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/attributes/type_system.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,26 @@
11
# Type system attributes
22

3+
r[attributes.type-system]
4+
35
The following [attributes] are used for changing how a type can be used.
46

57
## The `non_exhaustive` attribute
68

9+
r[attributes.type-system.non_exhaustive]
10+
11+
12+
r[attributes.type-system.non_exhaustive.general]
713
The *`non_exhaustive` attribute* indicates that a type or variant may have
8-
more fields or variants added in the future. It can be applied to
9-
[`struct`s][struct], [`enum`s][enum], and `enum` variants.
14+
more fields or variants added in the future.
15+
16+
r[attributes.type-system.non_exhaustive.restriction]
17+
It can be applied to [`struct`s][struct], [`enum`s][enum], and `enum` variants.
1018

19+
r[attributes.type-system.non_exhaustive.syntax]
1120
The `non_exhaustive` attribute uses the [_MetaWord_] syntax and thus does not
1221
take any inputs.
1322

23+
r[attributes.type-system.non_exhaustive.same-crate]
1424
Within the defining crate, `non_exhaustive` has no effect.
1525

1626
```rust
@@ -65,9 +75,11 @@ match message {
6575
}
6676
```
6777

78+
r[attributes.type-system.non_exhaustive.external-crate]
6879
Outside of the defining crate, types annotated with `non_exhaustive` have limitations that
6980
preserve backwards compatibility when new fields or variants are added.
7081

82+
r[attributes.type-system.non_exhaustive.construction]
7183
Non-exhaustive types cannot be constructed outside of the defining crate:
7284

7385
- Non-exhaustive variants ([`struct`][struct] or [`enum` variant][enum]) cannot be constructed
@@ -119,6 +131,7 @@ let message = Message::Reaction(0);
119131
let message = Message::Quit;
120132
```
121133

134+
r[attributes.type-system.non_exhaustive.match]
122135
There are limitations when matching on non-exhaustive types outside of the defining crate:
123136

124137
- When pattern matching on a non-exhaustive variant ([`struct`][struct] or [`enum` variant][enum]),

0 commit comments

Comments
 (0)