From 319d778ed306d0b3c35af79c47c702dbdebf6d09 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Tue, 28 Oct 2014 14:48:52 -0400 Subject: Restructure AST so that the associated type definition carries bounds like any other "type parameter". --- src/libsyntax/print/pprust.rs | 44 ++++++++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 19 deletions(-) (limited to 'src/libsyntax/print') diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 386fd8ae5a6..b7f6e65fb93 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -818,9 +818,11 @@ impl<'a> State<'a> { } fn print_associated_type(&mut self, typedef: &ast::AssociatedType) - -> IoResult<()> { + -> IoResult<()> + { + try!(self.print_outer_attributes(typedef.attrs[])); try!(self.word_space("type")); - try!(self.print_ident(typedef.ident)); + try!(self.print_ty_param(&typedef.ty_param)); word(&mut self.s, ";") } @@ -2434,23 +2436,7 @@ impl<'a> State<'a> { } else { let idx = idx - generics.lifetimes.len(); let param = generics.ty_params.get(idx); - match param.unbound { - Some(TraitTyParamBound(ref tref)) => { - try!(s.print_trait_ref(tref)); - try!(s.word_space("?")); - } - _ => {} - } - try!(s.print_ident(param.ident)); - try!(s.print_bounds(":", ¶m.bounds)); - match param.default { - Some(ref default) => { - try!(space(&mut s.s)); - try!(s.word_space("=")); - s.print_type(&**default) - } - _ => Ok(()) - } + s.print_ty_param(param) } })); @@ -2458,6 +2444,26 @@ impl<'a> State<'a> { Ok(()) } + pub fn print_ty_param(&mut self, param: &ast::TyParam) -> IoResult<()> { + match param.unbound { + Some(TraitTyParamBound(ref tref)) => { + try!(self.print_trait_ref(tref)); + try!(self.word_space("?")); + } + _ => {} + } + try!(self.print_ident(param.ident)); + try!(self.print_bounds(":", ¶m.bounds)); + match param.default { + Some(ref default) => { + try!(space(&mut self.s)); + try!(self.word_space("=")); + self.print_type(&**default) + } + _ => Ok(()) + } + } + pub fn print_where_clause(&mut self, generics: &ast::Generics) -> IoResult<()> { if generics.where_clause.predicates.len() == 0 { -- cgit 1.4.1-3-g733a5