Skip to content

Commit cc28ae5

Browse files
committed
Implement ToSource and ToToken for ast::Arg
This makes ast::Arg usable in the quote_ macros. Please note that this commit doesn't include a regression test. There are tests that use the quote macros, but all of them are ignored. Due to that, there is no obvious (to me) way to test this. Since this change is absolutely trivial and only hooks up an additional type to existing infrastructure (which presumably is tested elsewhere), I concluded it's not worth the effort to follow up on this.
1 parent 8e9e484 commit cc28ae5

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)