Skip to content

Commit 277c683

Browse files
committed
Convert all of the grammar to use the new grammar renderer
1 parent 1b213aa commit 277c683

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+1430
-1816
lines changed

src/abi.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ extern "C" fn foo() {}
8181

8282
The *`link_section` attribute* specifies the section of the object file that a
8383
[function] or [static]'s content will be placed into. It uses the
84-
[_MetaNameValueStr_] syntax to specify the section name.
84+
[MetaNameValueStr] syntax to specify the section name.
8585

8686
This attribute is unsafe as it allows users to place data and code into sections
8787
of memory not expecting them, such as mutable data into read-only areas.
@@ -99,7 +99,7 @@ pub static VAR1: u32 = 1;
9999
## The `export_name` attribute
100100

101101
The *`export_name` attribute* specifies the name of the symbol that will be
102-
exported on a [function] or [static]. It uses the [_MetaNameValueStr_] syntax
102+
exported on a [function] or [static]. It uses the [MetaNameValueStr] syntax
103103
to specify the symbol name.
104104

105105
This attribute is unsafe as a symbol with a custom name may collide with another
@@ -114,7 +114,6 @@ pub fn name_in_rust() { }
114114
> [!EDITION-2024]
115115
> Before the 2024 edition it is allowed to use the `export_name` attribute without the `unsafe` qualification.
116116
117-
[_MetaNameValueStr_]: attributes.md#meta-item-attribute-syntax
118117
[`static` items]: items/static-items.md
119118
[attribute]: attributes.md
120119
[extern functions]: items/functions.md#extern-function-qualifier

src/attributes.md

Lines changed: 42 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,19 @@ r[attributes]
33
# Attributes
44

55
r[attributes.syntax]
6-
> **<sup>Syntax</sup>**\
7-
> _InnerAttribute_ :\
8-
> &nbsp;&nbsp; `#` `!` `[` _Attr_ `]`
9-
>
10-
> _OuterAttribute_ :\
11-
> &nbsp;&nbsp; `#` `[` _Attr_ `]`
12-
>
13-
> _Attr_ :\
14-
> &nbsp;&nbsp; &nbsp;&nbsp; [_SimplePath_] _AttrInput_<sup>?</sup>\
15-
> &nbsp;&nbsp; | `unsafe` `(` [_SimplePath_] _AttrInput_<sup>?</sup> `)`
16-
>
17-
> _AttrInput_ :\
18-
> &nbsp;&nbsp; &nbsp;&nbsp; [_DelimTokenTree_]\
19-
> &nbsp;&nbsp; | `=` [_Expression_]
6+
```grammar,attributes
7+
InnerAttribute -> `#` `!` `[` Attr `]`
8+
9+
OuterAttribute -> `#` `[` Attr `]`
10+
11+
Attr ->
12+
SimplePath AttrInput?
13+
| `unsafe` `(` SimplePath AttrInput? `)`
14+
15+
AttrInput ->
16+
DelimTokenTree
17+
| `=` Expression
18+
```
2019

2120
r[attributes.intro]
2221
An _attribute_ is a general, free-form metadatum that is interpreted according
@@ -114,18 +113,19 @@ A "meta item" is the syntax used for the _Attr_ rule by most [built-in
114113
attributes]. It has the following grammar:
115114

116115
r[attributes.meta.syntax]
117-
> **<sup>Syntax</sup>**\
118-
> _MetaItem_ :\
119-
> &nbsp;&nbsp; &nbsp;&nbsp; [_SimplePath_]\
120-
> &nbsp;&nbsp; | [_SimplePath_] `=` [_Expression_]\
121-
> &nbsp;&nbsp; | [_SimplePath_] `(` _MetaSeq_<sup>?</sup> `)`
122-
>
123-
> _MetaSeq_ :\
124-
> &nbsp;&nbsp; _MetaItemInner_ ( `,` MetaItemInner )<sup>\*</sup> `,`<sup>?</sup>
125-
>
126-
> _MetaItemInner_ :\
127-
> &nbsp;&nbsp; &nbsp;&nbsp; _MetaItem_\
128-
> &nbsp;&nbsp; | [_Expression_]
116+
```grammar,attributes
117+
MetaItem ->
118+
SimplePath
119+
| SimplePath `=` Expression
120+
| SimplePath `(` MetaSeq? `)`
121+
122+
MetaSeq ->
123+
MetaItemInner ( `,` MetaItemInner )* `,`?
124+
125+
MetaItemInner ->
126+
MetaItem
127+
| Expression
128+
```
129129

130130
r[attributes.meta.literal-expr]
131131
Expressions in meta items must macro-expand to literal expressions, which must not
@@ -163,21 +163,22 @@ specify their inputs. The following grammar rules show some commonly used
163163
forms:
164164

165165
r[attributes.meta.builtin.syntax]
166-
> **<sup>Syntax</sup>**\
167-
> _MetaWord_:\
168-
> &nbsp;&nbsp; [IDENTIFIER]
169-
>
170-
> _MetaNameValueStr_:\
171-
> &nbsp;&nbsp; [IDENTIFIER] `=` ([STRING_LITERAL] | [RAW_STRING_LITERAL])
172-
>
173-
> _MetaListPaths_:\
174-
> &nbsp;&nbsp; [IDENTIFIER] `(` ( [_SimplePath_] (`,` [_SimplePath_])* `,`<sup>?</sup> )<sup>?</sup> `)`
175-
>
176-
> _MetaListIdents_:\
177-
> &nbsp;&nbsp; [IDENTIFIER] `(` ( [IDENTIFIER] (`,` [IDENTIFIER])* `,`<sup>?</sup> )<sup>?</sup> `)`
178-
>
179-
> _MetaListNameValueStr_:\
180-
> &nbsp;&nbsp; [IDENTIFIER] `(` ( _MetaNameValueStr_ (`,` _MetaNameValueStr_)* `,`<sup>?</sup> )<sup>?</sup> `)`
166+
```grammar,attributes
167+
MetaWord ->
168+
IDENTIFIER
169+
170+
MetaNameValueStr ->
171+
IDENTIFIER `=` (STRING_LITERAL | RAW_STRING_LITERAL)
172+
173+
MetaListPaths ->
174+
IDENTIFIER `(` ( SimplePath (`,` SimplePath)* `,`? )? `)`
175+
176+
MetaListIdents ->
177+
IDENTIFIER `(` ( IDENTIFIER (`,` IDENTIFIER)* `,`? )? `)`
178+
179+
MetaListNameValueStr ->
180+
IDENTIFIER `(` ( MetaNameValueStr (`,` MetaNameValueStr)* `,`? )? `)`
181+
```
181182

182183
Some examples of meta items are:
183184

@@ -331,14 +332,8 @@ The following is an index of all built-in attributes.
331332
[ECMA-334]: https://www.ecma-international.org/publications-and-standards/standards/ecma-334/
332333
[ECMA-335]: https://www.ecma-international.org/publications-and-standards/standards/ecma-335/
333334
[Expression Attributes]: expressions.md#expression-attributes
334-
[IDENTIFIER]: identifiers.md
335-
[RAW_STRING_LITERAL]: tokens.md#raw-string-literals
336-
[STRING_LITERAL]: tokens.md#string-literals
337335
[The Rustdoc Book]: ../rustdoc/the-doc-attribute.html
338336
[The Unstable Book]: ../unstable-book/index.html
339-
[_DelimTokenTree_]: macros.md
340-
[_Expression_]: expressions.md
341-
[_SimplePath_]: paths.md#simple-paths
342337
[`allow`]: attributes/diagnostics.md#lint-check-attributes
343338
[`automatically_derived`]: attributes/derive.md#the-automatically_derived-attribute
344339
[`cfg_attr`]: conditional-compilation.md#the-cfg_attr-attribute

src/attributes/codegen.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ r[attributes.codegen.target_feature]
5959
r[attributes.codegen.target_feature.intro]
6060
The *`target_feature` [attribute]* may be applied to a function to
6161
enable code generation of that function for specific platform architecture
62-
features. It uses the [_MetaListNameValueStr_] syntax with a single key of
62+
features. It uses the [MetaListNameValueStr] syntax with a single key of
6363
`enable` whose value is a string of comma-separated feature names to enable.
6464

6565
```rust
@@ -495,7 +495,6 @@ trait object whose methods are attributed.
495495
> [!NOTE]
496496
> The aforementioned shim for function pointers is necessary because `rustc` implements `track_caller` in a codegen context by appending an implicit parameter to the function ABI, but this would be unsound for an indirect call because the parameter is not a part of the function's type and a given function pointer type may or may not refer to a function with the attribute. The creation of a shim hides the implicit parameter from callers of the function pointer, preserving soundness.
497497
498-
[_MetaListNameValueStr_]: ../attributes.md#meta-item-attribute-syntax
499498
[`-C target-cpu`]: ../../rustc/codegen-options/index.html#target-cpu
500499
[`-C target-feature`]: ../../rustc/codegen-options/index.html#target-feature
501500
[`is_x86_feature_detected`]: ../../std/arch/macro.is_x86_feature_detected.html

src/attributes/debugger.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ The *`debugger_visualizer` attribute* can be used to embed a debugger visualizer
1111
This enables an improved debugger experience for displaying values in the debugger.
1212

1313
r[attributes.debugger.debugger_visualizer.syntax]
14-
It uses the [_MetaListNameValueStr_] syntax to specify its inputs, and must be specified as a crate attribute.
14+
It uses the [MetaListNameValueStr] syntax to specify its inputs, and must be specified as a crate attribute.
1515

1616
r[attributes.debugger.debugger_visualizer.natvis]
1717
### Using `debugger_visualizer` with Natvis
@@ -150,7 +150,6 @@ When the crate's debug executable is passed into GDB[^rust-gdb], `print bob` wil
150150
[attributes]: ../attributes.md
151151
[Natvis documentation]: https://docs.microsoft.com/en-us/visualstudio/debugger/create-custom-views-of-native-objects
152152
[pretty printing documentation]: https://sourceware.org/gdb/onlinedocs/gdb/Pretty-Printing.html
153-
[_MetaListNameValueStr_]: ../attributes.md#meta-item-attribute-syntax
154153

155154
r[attributes.debugger.collapse_debuginfo]
156155
## The `collapse_debuginfo` attribute
@@ -160,7 +159,7 @@ The *`collapse_debuginfo` [attribute]* controls whether code locations from a ma
160159
when generating debuginfo for code calling this macro.
161160

162161
r[attributes.debugger.collapse_debuginfo.syntax]
163-
The attribute uses the [_MetaListIdents_] syntax to specify its inputs, and can only be applied to macro definitions.
162+
The attribute uses the [MetaListIdents] syntax to specify its inputs, and can only be applied to macro definitions.
164163

165164
r[attributes.debugger.collapse_debuginfo.options]
166165
Accepted options:
@@ -185,4 +184,3 @@ macro_rules! example {
185184
```
186185

187186
[attribute]: ../attributes.md
188-
[_MetaListIdents_]: ../attributes.md#meta-item-attribute-syntax

src/attributes/derive.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ The *`derive` attribute* allows new [items] to be automatically generated for
66
data structures.
77

88
r[attributes.derive.syntax]
9-
It uses the [_MetaListPaths_] syntax to specify a list of
9+
It uses the [MetaListPaths] syntax to specify a list of
1010
traits to implement or paths to [derive macros] to process.
1111

1212
For example, the following will create an [`impl` item] for the
@@ -43,7 +43,6 @@ The *`automatically_derived` attribute* is automatically added to
4343
has no direct effect, but it may be used by tools and diagnostic lints to
4444
detect these automatically generated implementations.
4545

46-
[_MetaListPaths_]: ../attributes.md#meta-item-attribute-syntax
4746
[`impl` item]: ../items/implementations.md
4847
[items]: ../items.md
4948
[derive macros]: ../procedural-macros.md#derive-macros

src/attributes/diagnostics.md

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ unreachable code or omitted documentation.
1212

1313
r[attributes.diagnostics.lint.level]
1414
The lint attributes `allow`,
15-
`expect`, `warn`, `deny`, and `forbid` use the [_MetaListPaths_] syntax
15+
`expect`, `warn`, `deny`, and `forbid` use the [MetaListPaths] syntax
1616
to specify a list of lint names to change the lint level for the entity
1717
to which the attribute applies.
1818

@@ -313,7 +313,7 @@ The `deprecated` attribute has several forms:
313313
- `deprecated` --- Issues a generic message.
314314
- `deprecated = "message"` --- Includes the given string in the deprecation
315315
message.
316-
- [_MetaListNameValueStr_] syntax with two optional fields:
316+
- [MetaListNameValueStr] syntax with two optional fields:
317317
- `since` --- Specifies a version number when the item was deprecated. `rustc`
318318
does not currently interpret the string, but external tools like [Clippy]
319319
may check the validity of the value.
@@ -359,7 +359,7 @@ and [traits].
359359

360360
r[attributes.diagnostics.must_use.message]
361361
The `must_use` attribute may include a message by using the
362-
[_MetaNameValueStr_] syntax such as `#[must_use = "example message"]`. The
362+
[MetaNameValueStr] syntax such as `#[must_use = "example message"]`. The
363363
message will be given alongside the warning.
364364

365365
r[attributes.diagnostics.must_use.type]
@@ -483,7 +483,7 @@ r[attributes.diagnostic.on_unimplemented.allowed-positions]
483483
The attribute should be placed on a [trait declaration], though it is not an error to be located in other positions.
484484
485485
r[attributes.diagnostic.on_unimplemented.syntax]
486-
The attribute uses the [_MetaListNameValueStr_] syntax to specify its inputs, though any malformed input to the attribute is not considered as an error to provide both forwards and backwards compatibility.
486+
The attribute uses the [MetaListNameValueStr] syntax to specify its inputs, though any malformed input to the attribute is not considered as an error to provide both forwards and backwards compatibility.
487487
488488
r[attributes.diagnostic.on_unimplemented.keys]
489489
The following keys have the given meaning:
@@ -663,9 +663,6 @@ error[E0277]: the trait bound `&str: AsExpression<Integer>` is not satisfied
663663
The first error message includes a somewhat confusing error message about the relationship of `&str` and `Expression`, as well as the unsatisfied trait bound in the blanket impl. After adding `#[diagnostic::do_not_recommend]`, it no longer considers the blanket impl for the recommendation. The message should be a little clearer, with an indication that a string cannot be converted to an `Integer`.
664664

665665
[Clippy]: https://github.com/rust-lang/rust-clippy
666-
[_MetaListNameValueStr_]: ../attributes.md#meta-item-attribute-syntax
667-
[_MetaListPaths_]: ../attributes.md#meta-item-attribute-syntax
668-
[_MetaNameValueStr_]: ../attributes.md#meta-item-attribute-syntax
669666
[`Drop`]: ../special-types-and-traits.md#drop
670667
[attributes]: ../attributes.md
671668
[block expression]: ../expressions/block-expr.md

src/attributes/limits.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ maximum depth for potentially infinitely-recursive compile-time operations
1212
like macro expansion or auto-dereference.
1313

1414
r[attributes.limits.recursion_limit.syntax]
15-
It uses the [_MetaNameValueStr_]
15+
It uses the [MetaNameValueStr]
1616
syntax to specify the recursion depth.
1717

1818
> [!NOTE]
@@ -53,7 +53,7 @@ The *`type_length_limit` attribute* limits the maximum number of type
5353
substitutions made when constructing a concrete type during monomorphization.
5454

5555
r[attributes.limits.type_length_limit.syntax]
56-
It is applied at the [crate] level, and uses the [_MetaNameValueStr_] syntax
56+
It is applied at the [crate] level, and uses the [MetaNameValueStr] syntax
5757
to set the limit based on the number of type substitutions.
5858

5959
> [!NOTE]
@@ -69,6 +69,5 @@ fn f<T>(x: T) {}
6969
f(((((1,), 2), 3), 4));
7070
```
7171

72-
[_MetaNameValueStr_]: ../attributes.md#meta-item-attribute-syntax
7372
[attributes]: ../attributes.md
7473
[crate]: ../crates-and-source-files.md

src/attributes/testing.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ A function annotated with the `test` attribute can also be annotated with the
5757
execute that function as a test. It will still be compiled when in test mode.
5858

5959
r[attributes.testing.ignore.syntax]
60-
The `ignore` attribute may optionally be written with the [_MetaNameValueStr_]
60+
The `ignore` attribute may optionally be written with the [MetaNameValueStr]
6161
syntax to specify a reason why the test is ignored.
6262

6363
```rust
@@ -86,7 +86,7 @@ r[attributes.testing.should_panic.syntax]
8686
The `should_panic` attribute may optionally take an input string that must
8787
appear within the panic message. If the string is not found in the message,
8888
then the test will fail. The string may be passed using the
89-
[_MetaNameValueStr_] syntax or the [_MetaListNameValueStr_] syntax with an
89+
[MetaNameValueStr] syntax or the [MetaListNameValueStr] syntax with an
9090
`expected` field.
9191

9292
```rust
@@ -97,8 +97,6 @@ fn mytest() {
9797
}
9898
```
9999

100-
[_MetaListNameValueStr_]: ../attributes.md#meta-item-attribute-syntax
101-
[_MetaNameValueStr_]: ../attributes.md#meta-item-attribute-syntax
102100
[`Termination`]: std::process::Termination
103101
[`report`]: std::process::Termination::report
104102
[`test` conditional compilation option]: ../conditional-compilation.md#test

src/attributes/type_system.md

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ r[attributes.type-system.non_exhaustive.allowed-positions]
1414
It can be applied to [`struct`s][struct], [`enum`s][enum], and `enum` variants.
1515

1616
r[attributes.type-system.non_exhaustive.syntax]
17-
The `non_exhaustive` attribute uses the [_MetaWord_] syntax and thus does not
17+
The `non_exhaustive` attribute uses the [MetaWord] syntax and thus does not
1818
take any inputs.
1919

2020
r[attributes.type-system.non_exhaustive.same-crate]
@@ -80,7 +80,7 @@ r[attributes.type-system.non_exhaustive.construction]
8080
Non-exhaustive types cannot be constructed outside of the defining crate:
8181

8282
- Non-exhaustive variants ([`struct`][struct] or [`enum` variant][enum]) cannot be constructed
83-
with a [_StructExpression_] \(including with [functional update syntax]).
83+
with a [StructExpression] \(including with [functional update syntax]).
8484
- The implicitly defined same-named constant of a [unit-like struct][struct],
8585
or the same-named constructor function of a [tuple struct][struct],
8686
has a [visibility] no greater than `pub(crate)`.
@@ -132,7 +132,7 @@ r[attributes.type-system.non_exhaustive.match]
132132
There are limitations when matching on non-exhaustive types outside of the defining crate:
133133

134134
- When pattern matching on a non-exhaustive variant ([`struct`][struct] or [`enum` variant][enum]),
135-
a [_StructPattern_] must be used which must include a `..`. A tuple variant's constructor's
135+
a [StructPattern] must be used which must include a `..`. A tuple variant's constructor's
136136
[visibility] is reduced to be no greater than `pub(crate)`.
137137
- When pattern matching on a non-exhaustive [`enum`][enum], matching on a variant does not
138138
contribute towards the exhaustiveness of the arms.
@@ -206,10 +206,6 @@ let _ = EnumWithNonExhaustiveVariants::First as u8;
206206

207207
Non-exhaustive types are always considered inhabited in downstream crates.
208208

209-
[_MetaWord_]: ../attributes.md#meta-item-attribute-syntax
210-
[_StructExpression_]: ../expressions/struct-expr.md
211-
[_StructPattern_]: ../patterns.md#struct-patterns
212-
[_TupleStructPattern_]: ../patterns.md#tuple-struct-patterns
213209
[`if let`]: ../expressions/if-expr.md#if-let-expressions
214210
[`match`]: ../expressions/match-expr.md
215211
[attributes]: ../attributes.md

0 commit comments

Comments
 (0)