@@ -668,9 +668,11 @@ transcriber : '(' transcriber * ')' | '[' transcriber * ']'
668
668
| non_special_token ;
669
669
```
670
670
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.
674
676
675
677
(A ` sep_token ` is any token other than ` * ` and ` + ` . A ` non_special_token ` is
676
678
any token other than a delimiter or ` $ ` .)
@@ -2002,8 +2004,6 @@ type int8_t = i8;
2002
2004
2003
2005
### Module-only attributes
2004
2006
2005
- - ` macro_escape ` - macros defined in this module will be visible in the
2006
- module's parent, after this module has been included.
2007
2007
- ` no_implicit_prelude ` - disable injecting ` use std::prelude::* ` in this
2008
2008
module.
2009
2009
- ` path ` - specifies the file to load the module from. `#[ path="foo.rs"] mod
@@ -2066,23 +2066,43 @@ On `struct`s:
2066
2066
remove any padding between fields (note that this is very fragile and may
2067
2067
break platforms which require aligned access).
2068
2068
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
+
2069
2096
### Miscellaneous attributes
2070
2097
2071
2098
- ` export_name ` - on statics and functions, this determines the name of the
2072
2099
exported symbol.
2073
2100
- ` link_section ` - on statics and functions, this specifies the section of the
2074
2101
object file that this item's contents will be placed into.
2075
- - ` macro_export ` - export a macro for cross-crate usage.
2076
2102
- ` no_mangle ` - on any item, do not apply the standard name mangling. Set the
2077
2103
symbol for this item to its identifier.
2078
2104
- ` packed ` - on structs or enums, eliminate any padding that would be used to
2079
2105
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.
2086
2106
- ` simd ` - on certain tuple structs, derive the arithmetic operators, which
2087
2107
lower to the target's SIMD instructions, if any; the ` simd ` feature gate
2088
2108
is necessary to use this attribute.
@@ -2569,15 +2589,6 @@ The currently implemented features of the reference compiler are:
2569
2589
* ` log_syntax ` - Allows use of the ` log_syntax ` macro attribute, which is a
2570
2590
nasty hack that will certainly be removed.
2571
2591
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
-
2581
2592
* ` non_ascii_idents ` - The compiler supports the use of non-ascii identifiers,
2582
2593
but the implementation is a little rough around the
2583
2594
edges, so this can be seen as an experimental feature
@@ -2588,15 +2599,10 @@ The currently implemented features of the reference compiler are:
2588
2599
closure as ` once ` is unlikely to be supported going forward. So
2589
2600
they are hidden behind this feature until they are to be removed.
2590
2601
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.
2595
2604
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 ] .
2600
2606
2601
2607
* ` quote ` - Allows use of the ` quote_*! ` family of macros, which are
2602
2608
implemented very poorly and will likely change significantly
0 commit comments