Skip to content

Commit a8b8581

Browse files
committed
rewrite bullet points as prose
1 parent 6fc4e4e commit a8b8581

File tree

3 files changed

+205
-140
lines changed

3 files changed

+205
-140
lines changed

src/items/use-declarations.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ They may create bindings for:
116116
* [Built-in types]
117117
* [Attributes]
118118
* [Derive macros]
119-
* [Macros by example]
119+
* [`macro_rules`]
120120

121121
r[items.use.path.disallowed]
122122
They cannot import [associated items], [generic parameters], [local variables], paths with [`Self`], or [tool attributes]. More restrictions are described below.

src/macros-by-example.md

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -326,8 +326,9 @@ fn foo() {
326326
// m!(); // Error: m is not in scope.
327327
```
328328

329-
* textual scope name bindings for macros may shadow path-based scope bindings
330-
to macros
329+
r[macro.decl.scope.textual.shadow.path-based]
330+
Textual scope name bindings for macros may shadow path-based scope bindings to
331+
macros.
331332

332333
```rust
333334
macro_rules! m {
@@ -348,6 +349,36 @@ use crate::m2 as m;
348349
m!(); // prints "m\n"
349350
```
350351

352+
TODO: note that the opposite is not true, link to relevant name-res ambiguity error section
353+
354+
r[macro.decl.scope.path-based]
355+
### Path-based scope
356+
357+
r[macro.decl.scope.path-based.intro]
358+
By default, a macro has no path-based scope. Macros can gain path-based scope in two ways:
359+
360+
* [Use declaration re-export]
361+
* [`#[macro_export]`](macros-by-example.html#the-macro_export-attribute)
362+
363+
r[macro.decl.scope.path.reexport]
364+
Macros can be re-exported to give them path-based scope from a module other than the crate root.
365+
366+
```rust
367+
mac::m!(); // OK: Path-based lookup finds m in the mac module.
368+
369+
mod mac {
370+
macro_rules! m {
371+
() => {};
372+
}
373+
pub(crate) use m;
374+
}
375+
```
376+
377+
r[macro.decl.scope.path-based.visibility]
378+
* macros have an implicit visibility of `pub(crate)`
379+
* `#[macro_export]` changes the implicit visibility to `pub`
380+
* macro definitions do not support direct visibility modifiers
381+
351382
<!-- template:attributes -->
352383
r[macro.decl.scope.macro_use]
353384
### The `macro_use` attribute
@@ -502,25 +533,6 @@ By default, macros only have [textual scope][macro.decl.scope.textual] and canno
502533
> # fn main() {}
503534
> ```
504535
505-
r[macro.decl.scope.path.reexport]
506-
507-
* macros can be re-exported to give them path-based scope from a module other than the crate root.
508-
* there's some visibility stuff here that may already be mentioned
509-
elsewhere. I'm pretty sure that w/o a #[macro_export] the macro being
510-
re-exported is implicitly pub(crate) and with one it is implicitly pub.
511-
The later is mentioned below, don't remember where I saw the former.
512-
513-
```
514-
mac::m!(); // OK: Path-based lookup finds m in the mac module.
515-
516-
mod mac {
517-
macro_rules! m {
518-
() => {};
519-
}
520-
pub(crate) use m;
521-
}
522-
```
523-
524536
r[macro.decl.scope.macro_export.export]
525537
The `macro_export` attribute causes a macro to be exported from the crate root so that it can be referred to in other crates by path.
526538
@@ -765,3 +777,4 @@ For more detail, see the [formal specification].
765777
[Repetitions]: #repetitions
766778
[token]: tokens.md
767779
[`$crate`]: macro.decl.hygiene.crate
780+
[Use declaration re-export]: items/use-declarations.html#use-visibility

0 commit comments

Comments
 (0)