|
7 | $( ($a, $b)),*
| ^
...
19 | vec![does_not_work! {
| ______________-
20 | | a ; b c d
21 | | }]
| |_________- caused by the macro expansion here
|
= note: the usage of `does_not_work!` is likely invalid in expression context
help: you might be missing a semicolon here
|
21 | };]
| +
for one, vec! itself is a macro, and macro expands from outside to inside, so you might not get what you wanted.
but the real reason is that, in your first example, the macro expansion is not valid rust item form, neither does it expand to a statement, nor does it expand to an expression.
rust macro cannot expand to incomplete form like in C/C++. e.g. you cannot achieve something like:
Knowledgewise, I knew this, but it never hit me until just now. Thanks! This makes sense.
This explains the confusing compiler error. So the output of my macro has to be expression, statement, form (or a sequence of statement / forms ?). No fragments. This makes sense. Thanks.
(I've removed macro_rules itself from this list; as far as I can tell, it was included to show that macro invocations can be included in the expansion of macros, as long as the inner macro invocation is in a valid position after the outer macro is expanded.)