Skip to content

Commit 8e0f593

Browse files
authored
Merge pull request #1816 from Daniel-Aaron-Bloom/dollar-crate
Minor fixes to `$crate` behavior
2 parents 118fd1f + 4f386db commit 8e0f593

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

src/macros-by-example.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ Valid fragment specifiers are:
134134
* `block`: a [BlockExpression]
135135
* `expr`: an [Expression]
136136
* `expr_2021`: an [Expression] except [UnderscoreExpression] and [ConstBlockExpression] (see [macro.decl.meta.edition2024])
137-
* `ident`: an [IDENTIFIER_OR_KEYWORD] or [RAW_IDENTIFIER]
137+
* `ident`: an [IDENTIFIER_OR_KEYWORD], [RAW_IDENTIFIER], or [`$crate`]
138138
* `item`: an [Item]
139139
* `lifetime`: a [LIFETIME_TOKEN]
140140
* `literal`: matches `-`<sup>?</sup>[LiteralExpression]
@@ -151,10 +151,10 @@ r[macro.decl.meta.transcription]
151151
In the transcriber, metavariables are referred to simply by `$`_name_, since
152152
the fragment kind is specified in the matcher. Metavariables are replaced with
153153
the syntax element that matched them.
154+
Metavariables can be transcribed more than once or not at all.
154155

155156
r[macro.decl.meta.dollar-crate]
156-
The keyword metavariable `$crate` can be used to refer to the current crate; see [Hygiene] below. Metavariables can be
157-
transcribed more than once or not at all.
157+
The keyword metavariable [`$crate`] can be used to refer to the current crate.
158158

159159
r[macro.decl.meta.edition2021]
160160
> [!EDITION-2021]
@@ -594,3 +594,4 @@ For more detail, see the [formal specification].
594594
[Metavariables]: #metavariables
595595
[Repetitions]: #repetitions
596596
[token]: tokens.md
597+
[`$crate`]: macro.decl.hygiene.crate

src/paths.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -368,11 +368,11 @@ r[paths.qualifiers.macro-crate]
368368
### `$crate`
369369

370370
r[paths.qualifiers.macro-crate.allowed-positions]
371-
`$crate` is only used within [macro transcribers], and can only be used as the first
371+
[`$crate`] is only used within [macro transcribers], and can only be used as the first
372372
segment, without a preceding `::`.
373373

374374
r[paths.qualifiers.macro-crate.hygiene]
375-
`$crate` will expand to a path to access items from the
375+
[`$crate`] will expand to a path to access items from the
376376
top level of the crate where the macro is defined, regardless of which crate the macro is
377377
invoked.
378378

@@ -472,6 +472,7 @@ mod without { // crate::without
472472
# fn main() {}
473473
```
474474

475+
[`$crate`]: macro.decl.hygiene.crate
475476
[implementations]: items/implementations.md
476477
[items]: items.md
477478
[literal]: expressions/literal-expr.md

src/procedural-macros.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,8 +350,9 @@ r[macro.proc.token.conversion.to-proc_macro]
350350
When passed to a proc-macro
351351
- All multi-character operators are broken into single characters.
352352
- Lifetimes are broken into a `'` character and an identifier.
353-
- All metavariable substitutions are represented as their underlying token
354-
streams.
353+
- The keyword metavariable [`$crate`] is passed as a single identifier.
354+
- All other metavariable substitutions are represented as their underlying
355+
token streams.
355356
- Such token streams may be wrapped into delimited groups ([`Group`]) with
356357
implicit delimiters ([`Delimiter::None`]) when it's necessary for
357358
preserving parsing priorities.
@@ -376,6 +377,7 @@ their equivalent `#[doc = r"str"]` attributes when passed to macros.
376377
[Cargo's build scripts]: ../cargo/reference/build-scripts.html
377378
[Derive macros]: #derive-macros
378379
[Function-like macros]: #function-like-procedural-macros
380+
[`$crate`]: macro.decl.hygiene.crate
379381
[`Delimiter::None`]: proc_macro::Delimiter::None
380382
[`Group`]: proc_macro::Group
381383
[`TokenStream`]: proc_macro::TokenStream

0 commit comments

Comments
 (0)