Open matklad opened 2 years ago
smaller repro:
macro_rules! m {
(($tt:tt)) => {
stringify!($tt)
};
($vis:vis $name:ident) => {
m!(($vis))
};
}
const _: &str = m$0!(foo);
Turns out tt
fragments can capture empty vis
captures
:speak_no_evil:
Ye I don't think there is much we can do here right now? I assume rust doesn't need to convert intermediate expansions back into proper ASTs like we do 😬 so this requires us to have an empty ast node or something similar.
I demand a cursed
label for macro related issues like these
Oh now thinking about that, it makes a lot of sense that it works this way, since macro captures that arent tt
, ident
or lifetime
are opaque, so capturing an empty token tree should be opaque to following macros 🙃. Ye I am really not sure how we can get out of this aside from modifying our syntax trees... lovely.
I think modifying syntax trees is ok: we support $crate
in the ast for example.
One worry I have is that we lightly enforce an invariat that there are no nodes of length zero, and, if we allow them, I expect a tonne of subtle bugs to surface over the years.
So perhaps we can say that, in the ast, this node contains a single space?
This macro call fails to expand for me:
https://github.com/near/nearcore/blob/d338e91390c9b3ed422c66dbfd2548bcc8282249/genesis-tools/genesis-csv-to-json/src/csv_parser.rs#L345-L347
I think this is related to
$vis
token producing an empty match, as the following works:pub RES => "res/test_accounts.csv"