Skip to content

Commit a503fb4

Browse files
author
Keegan McAllister
committed
Changes from the meeting
1 parent 3e5861d commit a503fb4

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

text/0000-macro-reform.md

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,16 +74,26 @@ crate should be imported to the syntax environment:
7474
#[use_macros(vec, panic="fail")]
7575
extern crate std;
7676

77-
#[use_macros(*)]
77+
#[use_macros]
7878
extern crate core;
7979
```
8080

81+
The list of macros to import is optional. Omitting the list imports all macros,
82+
similar to a glob `use`. (This is also the mechanism by which `std` will
83+
inject its macros into every non-`no_std` crate.)
84+
85+
Importing with rename is an optional part of this proposal that will be
86+
implemented for 1.0 only if time permits.
87+
8188
Macros imported this way can be used anywhere in the module after the
8289
`extern crate` item, including in child modules. Since a macro-importing
8390
`extern crate` must appear at the crate root, and view items come before
8491
other items, this effectively means imported macros will be visible for
8592
the entire crate.
8693

94+
Any name collision between macros, whether imported or defined in-crate, is a
95+
hard error.
96+
8797
Many macros expand using other "helper macros" as an implementation detail.
8898
For example, librustc's `declare_lint!` uses `lint_initializer!`. The client
8999
should not know about this macro, although it still needs to be exported for
@@ -110,6 +120,11 @@ The macro `lint_initializer!`, imported from the same crate as `declare_lint!`,
110120
will be visible only during further expansion of the result of invoking
111121
`declare_lint!`.
112122

123+
`use_macros` on `macro_rules` is an optional part of this proposal that will be
124+
implemented for 1.0 only if time permits. Without it, libraries that use
125+
helper macros will need to list them in documentation so that users can import
126+
them.
127+
113128
Procedural macros need their own way to manipulate the syntax environment, but
114129
that's an unstable internal API, so it's outside the scope of this RFC.
115130

@@ -125,17 +140,17 @@ rest of the enclosing module, including any child modules. A crate might start
125140
with
126141

127142
```rust
128-
#[use_macros(*)]
143+
#[use_macros]
129144
mod macros;
130145
```
131146

132147
to define some macros for use by the whole crate, without putting those
133148
definitions in `lib.rs`.
134149

135-
Note that `#[use_macros(*)]` is equivalent to the current `#[macro_escape]`.
136-
However, the new convention is to use an outer attribute, in the file whose
137-
syntax environment is affected, rather than an inner attribute in the file
138-
defining the macros.
150+
Note that `#[use_macros]` (without a list of names) is equivalent to the
151+
current `#[macro_escape]`. However, the new convention is to use an outer
152+
attribute, in the file whose syntax environment is affected, rather than an
153+
inner attribute in the file defining the macros.
139154

140155
## Macro export and re-export
141156

@@ -265,7 +280,7 @@ however I think we should allow it anyway, to encourage the habit of writing
265280
This proposal is edited by Keegan McAllister. It has been refined through many
266281
engaging discussions with:
267282

268-
* Brian Anderson, Shachaf Ben-Kiki, Lars Bergstrom, Nick Cameron, John Clements, Alex Crichton, Cathy Douglass, Steven Fackler, Manish Goregaokar, Dave Herman, Steve Klabnik, Felix S. Klock II, Niko Matsakis, Matthew McPherrin, Paul Stansifer, Sam Tobin-Hochstadt, Aaron Turon, Huon Wilson, Brendan Zabarauskas, Cameron Zwarich
283+
* Brian Anderson, Shachaf Ben-Kiki, Lars Bergstrom, Nick Cameron, John Clements, Alex Crichton, Cathy Douglass, Steven Fackler, Manish Goregaokar, Dave Herman, Steve Klabnik, Felix S. Klock II, Niko Matsakis, Matthew McPherrin, Paul Stansifer, Sam Tobin-Hochstadt, Erick Tryzelaar, Aaron Turon, Huon Wilson, Brendan Zabarauskas, Cameron Zwarich
269284
* *GitHub*: `@bill-myers` `@blaenk` `@comex` `@glaebhoerl` `@Kimundi` `@mitchmindtree` `@mitsuhiko` `@P1Start` `@petrochenkov` `@skinner`
270285
* *Reddit*: `gnusouth` `ippa` `!kibwen` `Mystor` `Quxxy` `rime-frost` `Sinistersnare` `tejp` `UtherII` `yigal100`
271286
* *IRC*: `bstrie` `ChrisMorgan` `cmr` `Earnestly` `eddyb` `tiffany`

0 commit comments

Comments
 (0)