You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The `proc_macro` attribute may only be applied to a `pub` function of type `fn(TokenStream) -> TokenStream` where [`TokenStream`] comes from the [`proc_macro` crate]. It must have the ["Rust" ABI][items.fn.extern]. No other function qualifiers are allowed. It must be located in the root of the crate.
112
124
113
-
And then we use it in a binary crate to print "42" to standard output.
125
+
r[macro.proc.proc_macro.duplicates]
126
+
The `proc_macro` attribute may only be specified once on a function.
114
127
115
-
<!-- ignore: requires external crates -->
116
-
```rust,ignore
117
-
extern crate proc_macro_examples;
118
-
use proc_macro_examples::make_answer;
128
+
r[macro.proc.proc_macro.namespace]
129
+
The `proc_macro` attribute publicly defines the macro in the [macro namespace] in the root of the crate with the same name as the function.
119
130
120
-
make_answer!();
131
+
r[macro.proc.proc_macro.behavior]
132
+
A function-like macro invocation of a function-like procedural macro will pass what is inside the delimiters of the macro invocation as the input [`TokenStream`] argument and replace the entire macro invocation with the output [`TokenStream`] of the function.
121
133
122
-
fn main() {
123
-
println!("{}", answer());
124
-
}
125
-
```
134
+
r[macro.proc.proc_macro.invocation]
135
+
Function-like procedural macros may be invoked in any macro invocation position, which includes:
126
136
127
-
r[macro.proc.function.invocation]
128
-
Function-like procedural macros may be invoked in any macro invocation
129
-
position, which includes [statements], [expressions], [patterns], [type
130
-
expressions], [item] positions, including items in [`extern` blocks], inherent
131
-
and trait [implementations], and [trait definitions].
137
+
- [Statements]
138
+
- [Expressions]
139
+
- [Patterns]
140
+
- [Type expressions]
141
+
- [Item] positions, including items in [`extern` blocks]
142
+
- Inherent and trait [implementations]
143
+
- [Trait definitions]
132
144
133
145
<!-- template:attributes -->
134
146
r[macro.proc.derive]
@@ -384,7 +396,7 @@ their equivalent `#[doc = r"str"]` attributes when passed to macros.
0 commit comments