Skip to content

Commit 4805ac9

Browse files
committed
Update attributes template per review changes
In reviewing and revising the work to move all attributes to the new template, some patterns have emerged in editing. Let's capture these in the template.
1 parent 682e8c9 commit 4805ac9

File tree

1 file changed

+74
-14
lines changed

1 file changed

+74
-14
lines changed

docs/attribute-template.md

Lines changed: 74 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ The *`example` [attribute][attributes]* ...give a high level description.
1515

1616
> [!EXAMPLE]
1717
> ```rust
18-
> // This should be a very basic example showing the attribute used in some way.
18+
> // This should be a very basic example showing the attribute
19+
> // used in some way.
1920
> #[example]
2021
> fn some_meaningful_name() {}
2122
> ```
@@ -25,19 +26,70 @@ Describe the accepted syntax of this attribute. You can either explain that it u
2526
2627
----
2728
28-
The `example` attribute uses the [MetaWord] syntax and thus does not take any inputs.
29+
The `example` attribute uses the [MetaWord] syntax.
2930
3031
----
3132
3233
The `example` attribute uses the [MetaListPaths] syntax to specify a list of ...
3334
3435
----
3536
37+
The `example` attribute uses the [MetaWord] and [MetaNameValueStr] syntaxes.
38+
39+
----
40+
41+
The `example` attribute uses the [MetaWord], [MetaListPaths], and [MetaNameValueStr] syntaxes.
42+
43+
----
44+
45+
The `example` attribute uses the [MetaNameValueStr] syntax. Accepted values are `"X"` and `"Y"`.
46+
47+
----
48+
49+
The `example` attribute uses the [MetaNameValueStr] syntax. The value in the string must be ...
50+
51+
----
52+
53+
The `example` attribute has these forms:
54+
55+
- [MetaWord]
56+
> [!EXAMPLE]
57+
> ```rust
58+
> #[example]
59+
> fn f() {}
60+
> ```
61+
62+
- [MetaNameValueStr] --- The given string must ...
63+
> [!EXAMPLE]
64+
> ```rust
65+
> #[example = "example"]
66+
> fn f() {}
67+
> ```
68+
69+
- [MetaListNameValueStr] --- As with the [MetaNameValueStr] syntax, the given string must ...
70+
> [!EXAMPLE]
71+
> ```rust
72+
> #[example(inner = "example")]
73+
> fn f() {}
74+
> ```
75+
76+
----
77+
3678
The syntax for the `example` attribute is:
3779
3880
```grammar,attributes
3981
@root ExampleAttribute -> `example` `(` ... `)`
4082
```
83+
----
84+
85+
r[PARENT.example.syntax.foo]
86+
The [MetaNameValueStr] form of the `example` attribute provides a way to specify the foo.
87+
88+
> [!EXAMPLE]
89+
> ```rust
90+
> #[example = "example"]
91+
> fn some_meaningful_name() {}
92+
> ```
4193
4294
r[PARENT.example.allowed-positions]
4395
Explain the valid positions where this attribute may be used.
@@ -61,10 +113,7 @@ The `example` attribute is allowed anywhere attributes are allowed.
61113
If there are unused attribute warnings, or if rustc is incorrectly accepting some positions, include a note about these.
62114
63115
> [!NOTE]
64-
> `rustc` currently warns in other positions, but this may be rejected in the future.
65-
66-
> [!NOTE]
67-
> `rustc` currently warns on some positions where it is ignored, but this may become an error in the future.
116+
> `rustc` ignores use in other positions but lints against it. This may become an error in the future.
68117
69118
----
70119
@@ -73,29 +122,40 @@ Explain the behavior if the attribute is specified multiple times on an element.
73122
74123
----
75124
76-
Duplicate instances of the `example` attribute on the same ... have no effect.
125+
The `example` attribute may be used any number of times on a form.
77126
78127
----
79128
80-
The `example` attribute may only be specified once on a [THING].
129+
Using `example` more than once on a form has the same effect as using it once.
81130
82131
----
83132
84-
Only the first instance of `example` on an item is honored. Subsequent `example` attributes are ignored.
133+
The `example` attribute may be used only once on ...
134+
135+
----
136+
137+
Only the first use of `example` on an item has effect.
138+
139+
> [!NOTE]
140+
> `rustc` lints against any use following the first. This may become an error in the future.
85141
86142
> [!NOTE]
87-
> `rustc` currently warns on subsequent duplicate `example` attributes. This may become an error in the future.
143+
> `rustc` lints against any use following the first with a future-compatibility warning. This may become an error in the future.
88144
89145
----
90146
91-
Only the last instance of `example` on an item is honored. Previous `example` attributes are ignored.
147+
Only the last use of `example` on an item has effect.
92148
93149
> [!NOTE]
94-
> `rustc` currently warns on preceding duplicate `example` attributes. This may become an error in the future.
150+
> `rustc` lints against any use preceding the last. This may become an error in the future.
95151
96-
---
152+
----
153+
154+
Only the last use of `example` on an item is used to ...
155+
156+
----
97157
98-
If the `example` attribute is specified multiple times on an item, then the combination of all the specified values is used as ...explain how they are merged.
158+
If the `example` attribute is used more than once on an item, then the combination of all the specified values is used as ...explain how they are merged.
99159
100160
----
101161

0 commit comments

Comments
 (0)