feat: Support $$ in macros.

The implementation mirrors what `rustc` currently does [1]. Part of #11952.

[1]: 0595ea1d12/compiler/rustc_expand/src/mbe/quoted.rs (L230-L241)
This commit is contained in:
Tim Neumann 2022-06-02 21:36:11 +02:00
parent e25cbf8584
commit 40bfb29e50
3 changed files with 82 additions and 0 deletions

View file

@ -135,6 +135,14 @@ fn next_op<'a>(first: &tt::TokenTree, src: &mut TtIter<'a>, mode: Mode) -> Resul
let id = lit.id;
Op::Var { name, kind, id }
}
tt::Leaf::Punct(punct @ tt::Punct { char: '$', .. }) => match mode {
Mode::Pattern => {
return Err(ParseError::unexpected(
"`$$` is not allowed on the pattern side",
))
}
Mode::Template => Op::Leaf(tt::Leaf::Punct(*punct)),
},
tt::Leaf::Punct(_) | tt::Leaf::Literal(_) => {
return Err(ParseError::expected("expected ident"))
}