fn a() {} seems to satisfy a parsing rule that expected a fn, then some other stuff. items should be able to be function definitions, right? So they should work, right?
macro_rules! multi_impl {
(for $base:ty :
$($t:ty {
$($i:item);*
}),+) =>
{
$(
impl $t for $base
{
$( $i )*
}
)+
}
}
trait A {
fn a();
}
trait B {
fn b();
}
struct S;
multi_impl! {
for S:
A {
fn a() {}
}, B {
fn b() {}
}
}
fn main() {
S::a();
S::b();
}
The error in question:
error: expected one of `const`, `default`, `extern`, `fn`, `pub`, `type`, `unsafe`, or `}`, found `fn a() { }`
--> <anon>:11:20
|
11 | $( $i )*
| ^^
Making it $( fn $i)* only changes the error to complain about expecting an identifier after the fn, which makes sense, but the initial error does not (at least to me).
Is there a difference to the parser about code that is in the source vs code that's placed into the source by a macro?