Skip to content

Commit

Permalink
Implement ToSource and ToToken for ast::Arg
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
hannobraun committed Jun 7, 2014
1 parent 8e9e484 commit cc28ae5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/libsyntax/ext/quote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,12 @@ pub mod rt {
}
}

impl ToSource for ast::Arg {
fn to_source(&self) -> String {
pprust::arg_to_str(self)
}
}

impl<'a> ToSource for &'a str {
fn to_source(&self) -> String {
let lit = dummy_spanned(ast::LitStr(
Expand Down Expand Up @@ -264,6 +270,7 @@ pub mod rt {
impl_to_tokens!(Generics)
impl_to_tokens!(@ast::Expr)
impl_to_tokens!(ast::Block)
impl_to_tokens!(ast::Arg)
impl_to_tokens_self!(&'a str)
impl_to_tokens!(())
impl_to_tokens!(char)
Expand Down
4 changes: 4 additions & 0 deletions src/libsyntax/print/pprust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,10 @@ pub fn variant_to_str(var: &ast::Variant) -> String {
to_str(|s| s.print_variant(var))
}

pub fn arg_to_str(arg: &ast::Arg) -> String {
to_str(|s| s.print_arg(arg))
}

pub fn visibility_qualified(vis: ast::Visibility, s: &str) -> String {
match vis {
ast::Public => format!("pub {}", s).to_string(),
Expand Down

0 comments on commit cc28ae5

Please sign in to comment.