]> git.lizzy.rs Git - rust.git/commit
proc_macro: Add an expand_expr method to TokenStream
authorNika Layzell <nika@thelayzells.com>
Sun, 18 Jul 2021 19:53:06 +0000 (15:53 -0400)
committerNika Layzell <nika@thelayzells.com>
Fri, 12 Nov 2021 20:41:40 +0000 (15:41 -0500)
commit3e4d3d2a295d87b2d7ac45a06a727605e8ea21db
tree61acbf038ef7994315ff507e7195b93aa0765a8f
parent800a156c1ef0c16eb80f57536d96fbf6629fb3b1
proc_macro: Add an expand_expr method to TokenStream

This feature is aimed at giving proc macros access to powers similar to
those used by builtin macros such as `format_args!` or `concat!`. These
macros are able to accept macros in place of string literal parameters,
such as the format string, as they perform recursive macro expansion
while being expanded.

This can be especially useful in many cases thanks to helper macros like
`concat!`, `stringify!` and `include_str!` which are often used to
construct string literals at compile-time in user code.

For now, this method only allows expanding macros which produce
literals, although more expresisons will be supported before the method
is stabilized.
compiler/rustc_expand/src/proc_macro.rs
compiler/rustc_expand/src/proc_macro_server.rs
library/proc_macro/src/bridge/mod.rs
library/proc_macro/src/lib.rs
src/test/ui/proc-macro/auxiliary/expand-expr.rs [new file with mode: 0644]
src/test/ui/proc-macro/auxiliary/included-file.txt [new file with mode: 0644]
src/test/ui/proc-macro/expand-expr.rs [new file with mode: 0644]
src/test/ui/proc-macro/expand-expr.stderr [new file with mode: 0644]