Macros: Add a 'literal' fragment specifier
Implements RFC 1576. See: https://github.com/rust-lang/rfcs/blob/master/text/1576-macros-literal-matcher.md Changes are mostly in libsyntax, docs, and tests. Feature gate is enabled for 1.27.0. Many thanks to Vadim Petrochenkov for following through code reviews and suggestions. Example: ````rust macro_rules! test_literal { ($l:literal) => { println!("literal: {}", $l); }; ($e:expr) => { println!("expr: {}", $e); }; } fn main() { let a = 1; test_literal!(a); test_literal!(2); test_literal!(-3); } ``` Output: ``` expr: 1 literal: 2 literal: -3 ```
This commit is contained in:
@@ -635,6 +635,7 @@ pub fn noop_fold_interpolated<T: Folder>(nt: token::Nonterminal, fld: &mut T)
|
||||
token::NtTy(ty) => token::NtTy(fld.fold_ty(ty)),
|
||||
token::NtIdent(ident, is_raw) => token::NtIdent(fld.fold_ident(ident), is_raw),
|
||||
token::NtLifetime(ident) => token::NtLifetime(fld.fold_ident(ident)),
|
||||
token::NtLiteral(expr) => token::NtLiteral(fld.fold_expr(expr)),
|
||||
token::NtMeta(meta) => token::NtMeta(fld.fold_meta_item(meta)),
|
||||
token::NtPath(path) => token::NtPath(fld.fold_path(path)),
|
||||
token::NtTT(tt) => token::NtTT(fld.fold_tt(tt)),
|
||||
|
||||
Reference in New Issue
Block a user