diff options
| author | Patrick Walton <pcwalton@mimiga.net> | 2014-08-05 19:44:21 -0700 |
|---|---|---|
| committer | Patrick Walton <pcwalton@mimiga.net> | 2014-09-17 16:38:57 -0700 |
| commit | 78a841810eb36e486ba68e6b9fa80e45d805cc4f (patch) | |
| tree | b1c7c6d9c49f84e03b374b5b70cb0c9d0b60a7de /src/libsyntax/print | |
| parent | 8067f4425d245a210c732a0333245fbe83190e89 (diff) | |
| download | rust-78a841810eb36e486ba68e6b9fa80e45d805cc4f.tar.gz rust-78a841810eb36e486ba68e6b9fa80e45d805cc4f.zip | |
librustc: Implement associated types behind a feature gate.
The implementation essentially desugars during type collection and AST type conversion time into the parameter scheme we have now. Only fully qualified names--e.g. `<T as Foo>::Bar`--are supported.
Diffstat (limited to 'src/libsyntax/print')
| -rw-r--r-- | src/libsyntax/print/pprust.rs | 42 |
1 files changed, 37 insertions, 5 deletions
diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index d0df95d711e..0ae5303641b 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -9,10 +9,11 @@ // except according to those terms. use abi; -use ast::{FnMutUnboxedClosureKind, FnOnceUnboxedClosureKind}; -use ast::{FnUnboxedClosureKind, MethodImplItem}; -use ast::{RegionTyParamBound, TraitTyParamBound, UnboxedClosureKind}; -use ast::{UnboxedFnTyParamBound, RequiredMethod, ProvidedMethod}; +use ast::{FnUnboxedClosureKind, FnMutUnboxedClosureKind}; +use ast::{FnOnceUnboxedClosureKind}; +use ast::{MethodImplItem, RegionTyParamBound, TraitTyParamBound}; +use ast::{RequiredMethod, ProvidedMethod, TypeImplItem, TypeTraitItem}; +use ast::{UnboxedClosureKind, UnboxedFnTyParamBound}; use ast; use ast_util; use owned_slice::OwnedSlice; @@ -660,6 +661,16 @@ impl<'a> State<'a> { ast::TyPath(ref path, ref bounds, _) => { try!(self.print_bounded_path(path, bounds)); } + ast::TyQPath(ref qpath) => { + try!(word(&mut self.s, "<")); + try!(self.print_type(&*qpath.for_type)); + try!(space(&mut self.s)); + try!(self.word_space("as")); + try!(self.print_path(&qpath.trait_name, false)); + try!(word(&mut self.s, ">")); + try!(word(&mut self.s, "::")); + try!(self.print_ident(qpath.item_name)); + } ast::TyFixedLengthVec(ref ty, ref v) => { try!(word(&mut self.s, "[")); try!(self.print_type(&**ty)); @@ -708,6 +719,22 @@ impl<'a> State<'a> { } } + fn print_associated_type(&mut self, typedef: &ast::AssociatedType) + -> IoResult<()> { + try!(self.word_space("type")); + try!(self.print_ident(typedef.ident)); + word(&mut self.s, ";") + } + + fn print_typedef(&mut self, typedef: &ast::Typedef) -> IoResult<()> { + try!(self.word_space("type")); + try!(self.print_ident(typedef.ident)); + try!(space(&mut self.s)); + try!(self.word_space("=")); + try!(self.print_type(&*typedef.typ)); + word(&mut self.s, ";") + } + /// Pretty-print an item pub fn print_item(&mut self, item: &ast::Item) -> IoResult<()> { try!(self.hardbreak_if_not_bol()); @@ -825,6 +852,9 @@ impl<'a> State<'a> { ast::MethodImplItem(ref meth) => { try!(self.print_method(&**meth)); } + ast::TypeImplItem(ref typ) => { + try!(self.print_typedef(&**typ)); + } } } try!(self.bclose(item.span)); @@ -1071,13 +1101,15 @@ impl<'a> State<'a> { m: &ast::TraitItem) -> IoResult<()> { match *m { RequiredMethod(ref ty_m) => self.print_ty_method(ty_m), - ProvidedMethod(ref m) => self.print_method(&**m) + ProvidedMethod(ref m) => self.print_method(&**m), + TypeTraitItem(ref t) => self.print_associated_type(&**t), } } pub fn print_impl_item(&mut self, ii: &ast::ImplItem) -> IoResult<()> { match *ii { MethodImplItem(ref m) => self.print_method(&**m), + TypeImplItem(ref td) => self.print_typedef(&**td), } } |
