syntax: add {trait_item,impl_item,where_clause}_to_string

This commit is contained in:
Erick Tryzelaar 2015-03-13 21:54:29 -07:00
parent ed81038504
commit c3f4fba9cc

View File

@ -367,6 +367,10 @@ pub fn generics_to_string(generics: &ast::Generics) -> String {
$to_string(|s| s.print_generics(generics))
}
pub fn where_clause_to_string(i: &ast::WhereClause) -> String {
$to_string(|s| s.print_where_clause(i))
}
pub fn fn_block_to_string(p: &ast::FnDecl) -> String {
$to_string(|s| s.print_fn_block_args(p))
}
@ -912,7 +916,7 @@ impl<'a> State<'a> {
try!(space(&mut self.s));
try!(self.word_space("="));
try!(self.print_type(&**ty));
try!(self.print_where_clause(params));
try!(self.print_where_clause(&params.where_clause));
try!(word(&mut self.s, ";"));
try!(self.end()); // end the outer ibox
}
@ -975,7 +979,7 @@ impl<'a> State<'a> {
}
try!(self.print_type(&**ty));
try!(self.print_where_clause(generics));
try!(self.print_where_clause(&generics.where_clause));
try!(space(&mut self.s));
try!(self.bopen());
@ -1003,7 +1007,7 @@ impl<'a> State<'a> {
}
}
try!(self.print_bounds(":", &real_bounds[..]));
try!(self.print_where_clause(generics));
try!(self.print_where_clause(&generics.where_clause));
try!(word(&mut self.s, " "));
try!(self.bopen());
for trait_item in trait_items {
@ -1061,7 +1065,7 @@ impl<'a> State<'a> {
try!(self.head(&visibility_qualified(visibility, "enum")));
try!(self.print_ident(ident));
try!(self.print_generics(generics));
try!(self.print_where_clause(generics));
try!(self.print_where_clause(&generics.where_clause));
try!(space(&mut self.s));
self.print_variants(&enum_definition.variants, span)
}
@ -1115,12 +1119,12 @@ impl<'a> State<'a> {
));
try!(self.pclose());
}
try!(self.print_where_clause(generics));
try!(self.print_where_clause(&generics.where_clause));
try!(word(&mut self.s, ";"));
try!(self.end());
self.end() // close the outer-box
} else {
try!(self.print_where_clause(generics));
try!(self.print_where_clause(&generics.where_clause));
try!(self.nbsp());
try!(self.bopen());
try!(self.hardbreak_if_not_bol());
@ -2343,7 +2347,7 @@ impl<'a> State<'a> {
}
try!(self.print_generics(generics));
try!(self.print_fn_args_and_ret(decl, opt_explicit_self));
self.print_where_clause(generics)
self.print_where_clause(&generics.where_clause)
}
pub fn print_fn_args(&mut self, decl: &ast::FnDecl,
@ -2526,19 +2530,16 @@ impl<'a> State<'a> {
}
}
pub fn print_where_clause(&mut self, generics: &ast::Generics)
pub fn print_where_clause(&mut self, where_clause: &ast::WhereClause)
-> io::Result<()> {
if generics.where_clause.predicates.len() == 0 {
if where_clause.predicates.len() == 0 {
return Ok(())
}
try!(space(&mut self.s));
try!(self.word_space("where"));
for (i, predicate) in generics.where_clause
.predicates
.iter()
.enumerate() {
for (i, predicate) in where_clause.predicates.iter().enumerate() {
if i != 0 {
try!(self.word_space(","));
}