Skip to content

Commit 01eb0ce

Browse files
committed
auto merge of #14722 : hannobraun/rust/quote-args, r=alexcrichton
The need for this came up while I worked on a procedural macro that parses an argument and adds the same argument to a generated function.
2 parents ddd09df + cc28ae5 commit 01eb0ce

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/libsyntax/ext/quote.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,12 @@ pub mod rt {
135135
}
136136
}
137137

138+
impl ToSource for ast::Arg {
139+
fn to_source(&self) -> String {
140+
pprust::arg_to_str(self)
141+
}
142+
}
143+
138144
impl<'a> ToSource for &'a str {
139145
fn to_source(&self) -> String {
140146
let lit = dummy_spanned(ast::LitStr(
@@ -264,6 +270,7 @@ pub mod rt {
264270
impl_to_tokens!(Generics)
265271
impl_to_tokens!(@ast::Expr)
266272
impl_to_tokens!(ast::Block)
273+
impl_to_tokens!(ast::Arg)
267274
impl_to_tokens_self!(&'a str)
268275
impl_to_tokens!(())
269276
impl_to_tokens!(char)

src/libsyntax/print/pprust.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,10 @@ pub fn variant_to_str(var: &ast::Variant) -> String {
242242
to_str(|s| s.print_variant(var))
243243
}
244244

245+
pub fn arg_to_str(arg: &ast::Arg) -> String {
246+
to_str(|s| s.print_arg(arg))
247+
}
248+
245249
pub fn visibility_qualified(vis: ast::Visibility, s: &str) -> String {
246250
match vis {
247251
ast::Public => format!("pub {}", s).to_string(),

0 commit comments

Comments
 (0)