Skip to content

Commit 576b2e7

Browse files
kmcallisterManishearth
authored andcommitted
Update docs
1 parent f3a2552 commit 576b2e7

File tree

1 file changed

+35
-29
lines changed

1 file changed

+35
-29
lines changed

reference.md

Lines changed: 35 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -668,9 +668,11 @@ transcriber : '(' transcriber * ')' | '[' transcriber * ']'
668668
| non_special_token ;
669669
```
670670

671-
User-defined syntax extensions are called "macros", and the `macro_rules`
672-
syntax extension defines them. Currently, user-defined macros can expand to
673-
expressions, statements, items, or patterns.
671+
`macro_rules` allows users to define syntax extension in a declarative way. We
672+
call such extensions "macros by example" or simply "macros" — to be distinguished
673+
from the "procedural macros" defined in [compiler plugins][plugin].
674+
675+
Currently, macros can expand to expressions, statements, items, or patterns.
674676

675677
(A `sep_token` is any token other than `*` and `+`. A `non_special_token` is
676678
any token other than a delimiter or `$`.)
@@ -2002,8 +2004,6 @@ type int8_t = i8;
20022004

20032005
### Module-only attributes
20042006

2005-
- `macro_escape` - macros defined in this module will be visible in the
2006-
module's parent, after this module has been included.
20072007
- `no_implicit_prelude` - disable injecting `use std::prelude::*` in this
20082008
module.
20092009
- `path` - specifies the file to load the module from. `#[path="foo.rs"] mod
@@ -2066,23 +2066,43 @@ On `struct`s:
20662066
remove any padding between fields (note that this is very fragile and may
20672067
break platforms which require aligned access).
20682068

2069+
### Macro- and plugin-related attributes
2070+
2071+
- `macro_use` on a `mod` — macros defined in this module will be visible in the
2072+
module's parent, after this module has been included.
2073+
2074+
- `macro_use` on an `extern crate` — load macros from this crate. An optional
2075+
list of names `#[macro_use(foo, bar)]` restricts the import to just those
2076+
macros named. The `extern crate` must appear at the crate root, not inside
2077+
`mod`, which ensures proper function of the [`$crate` macro
2078+
variable](guide-macros.html#the-variable-$crate).
2079+
2080+
- `macro_reexport` on an `extern crate` — re-export the named macros.
2081+
2082+
- `macro_export` - export a macro for cross-crate usage.
2083+
2084+
- `plugin` on an `extern crate` — load this crate as a [compiler
2085+
plugin][plugin]. The `plugin` feature gate is required. Any arguments to
2086+
the attribute, e.g. `#[plugin=...]` or `#[plugin(...)]`, are provided to the
2087+
plugin.
2088+
2089+
- `no_link` on an `extern crate` — even if we load this crate for macros or
2090+
compiler plugins, don't link it into the output.
2091+
2092+
See the [macros guide](guide-macros.html#scoping-and-macro-import/export) for
2093+
more information on macro scope.
2094+
2095+
20692096
### Miscellaneous attributes
20702097

20712098
- `export_name` - on statics and functions, this determines the name of the
20722099
exported symbol.
20732100
- `link_section` - on statics and functions, this specifies the section of the
20742101
object file that this item's contents will be placed into.
2075-
- `macro_export` - export a macro for cross-crate usage.
20762102
- `no_mangle` - on any item, do not apply the standard name mangling. Set the
20772103
symbol for this item to its identifier.
20782104
- `packed` - on structs or enums, eliminate any padding that would be used to
20792105
align fields.
2080-
- `phase` - on `extern crate` statements, allows specifying which "phase" of
2081-
compilation the crate should be loaded for. Currently, there are two
2082-
choices: `link` and `plugin`. `link` is the default. `plugin` will [load the
2083-
crate at compile-time][plugin] and use any syntax extensions or lints that the crate
2084-
defines. They can both be specified, `#[phase(link, plugin)]` to use a crate
2085-
both at runtime and compiletime.
20862106
- `simd` - on certain tuple structs, derive the arithmetic operators, which
20872107
lower to the target's SIMD instructions, if any; the `simd` feature gate
20882108
is necessary to use this attribute.
@@ -2569,15 +2589,6 @@ The currently implemented features of the reference compiler are:
25692589
* `log_syntax` - Allows use of the `log_syntax` macro attribute, which is a
25702590
nasty hack that will certainly be removed.
25712591

2572-
* `macro_rules` - The definition of new macros. This does not encompass
2573-
macro-invocation, that is always enabled by default, this
2574-
only covers the definition of new macros. There are currently
2575-
various problems with invoking macros, how they interact with
2576-
their environment, and possibly how they are used outside of
2577-
location in which they are defined. Macro definitions are
2578-
likely to change slightly in the future, so they are
2579-
currently hidden behind this feature.
2580-
25812592
* `non_ascii_idents` - The compiler supports the use of non-ascii identifiers,
25822593
but the implementation is a little rough around the
25832594
edges, so this can be seen as an experimental feature
@@ -2588,15 +2599,10 @@ The currently implemented features of the reference compiler are:
25882599
closure as `once` is unlikely to be supported going forward. So
25892600
they are hidden behind this feature until they are to be removed.
25902601

2591-
* `phase` - Usage of the `#[phase]` attribute allows loading compiler plugins
2592-
for custom lints or syntax extensions. The implementation is
2593-
considered unwholesome and in need of overhaul, and it is not clear
2594-
what they will look like moving forward.
2602+
* `plugin` - Usage of [compiler plugins][plugin] for custom lints or syntax extensions.
2603+
These depend on compiler internals and are subject to change.
25952604

2596-
* `plugin_registrar` - Indicates that a crate has [compiler plugins][plugin] that it
2597-
wants to load. As with `phase`, the implementation is
2598-
in need of an overhaul, and it is not clear that plugins
2599-
defined using this will continue to work.
2605+
* `plugin_registrar` - Indicates that a crate provides [compiler plugins][plugin].
26002606

26012607
* `quote` - Allows use of the `quote_*!` family of macros, which are
26022608
implemented very poorly and will likely change significantly

0 commit comments

Comments
 (0)