EDIT: nevermind, this is intentionally impossible. rustc people are such killjoys :(((((((
I've recently been screwing around with macros and I totally thought I was cooking with this:
macro_rules! foo {
($stuff:tt,$dol:tt) => {
macro_rules! bar {
($dolx:tt) => {{
println!("{:?}", ($dolx, $stuff));
}
foo!(($dolx, $stuff), $dol);};
}
};
}
However, my (in hindsight unjustified) hopes were quickly dashed by this:
foo!(0, $);
bar!(1); // prints (1, 0)
bar!(2); // I want this to print (2, (1, 0)) and so on, but instead I get
// error[E0659]: `bar` is ambiguous
In desperate investigation, I finally managed to get through my thick head the realization that this too fails:
macro_rules! baz {
() => {
println!("hello");
};
}
baz!();
#[noop] // an attribute proc macro which simply returns the input tokenstream
macro_rules! baz {
() => {
println!("goodbye");
};
}
baz!(); // same error
Whereas, with the attribute macro removed, it works perfectly fine.
Why does this restriction exist? Can I get past this, if not to get the first example to work, then at least the second? Even cargo-expand expands them correctly.