about summary refs log tree commit diff
path: root/src/libsyntax
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2014-11-03 15:29:29 -0800
committerAlex Crichton <alex@alexcrichton.com>2014-11-03 15:55:58 -0800
commiteb793616dcf0b1e4cc416dea3bec0ef5b80834a9 (patch)
tree5f05f6f406b139dc8b58271b806d0f4811e47d10 /src/libsyntax
parent8494368d568da3303179cf2d523fc673067540d4 (diff)
parent3c84e317210d0eaa9014179c9a998449571ad8aa (diff)
downloadrust-eb793616dcf0b1e4cc416dea3bec0ef5b80834a9.tar.gz
rust-eb793616dcf0b1e4cc416dea3bec0ef5b80834a9.zip
rollup merge of #18506 : nikomatsakis/assoc-type-bounds
Diffstat (limited to 'src/libsyntax')
-rw-r--r--src/libsyntax/ast.rs4
-rw-r--r--src/libsyntax/ast_map/mod.rs14
-rw-r--r--src/libsyntax/ast_util.rs2
-rw-r--r--src/libsyntax/feature_gate.rs2
-rw-r--r--src/libsyntax/fold.rs11
-rw-r--r--src/libsyntax/parse/parser.rs11
-rw-r--r--src/libsyntax/print/pprust.rs44
-rw-r--r--src/libsyntax/visit.rs3
8 files changed, 46 insertions, 45 deletions
diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs
index 1edcb35289a..7fb93698219 100644
--- a/src/libsyntax/ast.rs
+++ b/src/libsyntax/ast.rs
@@ -861,10 +861,8 @@ pub enum ImplItem {
 
 #[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)]
 pub struct AssociatedType {
-    pub id: NodeId,
-    pub span: Span,
-    pub ident: Ident,
     pub attrs: Vec<Attribute>,
+    pub ty_param: TyParam,
 }
 
 #[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)]
diff --git a/src/libsyntax/ast_map/mod.rs b/src/libsyntax/ast_map/mod.rs
index fa36577ebdb..f049b964ff3 100644
--- a/src/libsyntax/ast_map/mod.rs
+++ b/src/libsyntax/ast_map/mod.rs
@@ -405,7 +405,9 @@ impl<'ast> Map<'ast> {
                         MethMac(_) => panic!("no path elem for {}", node),
                     }
                 }
-                TypeTraitItem(ref m) => PathName(m.ident.name),
+                TypeTraitItem(ref m) => {
+                    PathName(m.ty_param.ident.name)
+                }
             },
             NodeVariant(v) => PathName(v.node.name.name),
             _ => panic!("no path elem for {}", node)
@@ -510,7 +512,7 @@ impl<'ast> Map<'ast> {
                 match *trait_method {
                     RequiredMethod(ref type_method) => type_method.span,
                     ProvidedMethod(ref method) => method.span,
-                    TypeTraitItem(ref typedef) => typedef.span,
+                    TypeTraitItem(ref typedef) => typedef.ty_param.span,
                 }
             }
             Some(NodeImplItem(ref impl_item)) => {
@@ -650,7 +652,7 @@ impl Named for TraitItem {
         match *self {
             RequiredMethod(ref tm) => tm.ident.name,
             ProvidedMethod(ref m) => m.name(),
-            TypeTraitItem(ref at) => at.ident.name,
+            TypeTraitItem(ref at) => at.ty_param.ident.name,
         }
     }
 }
@@ -783,7 +785,7 @@ impl<'ast> Visitor<'ast> for NodeCollector<'ast> {
                             self.insert(m.id, NodeTraitItem(tm));
                         }
                         TypeTraitItem(ref typ) => {
-                            self.insert(typ.id, NodeTraitItem(tm));
+                            self.insert(typ.ty_param.id, NodeTraitItem(tm));
                         }
                     }
                 }
@@ -976,7 +978,7 @@ pub fn map_decoded_item<'ast, F: FoldOps>(map: &Map<'ast>,
             let trait_item_id = match *trait_item {
                 ProvidedMethod(ref m) => m.id,
                 RequiredMethod(ref m) => m.id,
-                TypeTraitItem(ref ty) => ty.id,
+                TypeTraitItem(ref ty) => ty.ty_param.id,
             };
 
             collector.insert(trait_item_id, NodeTraitItem(trait_item));
@@ -1080,7 +1082,7 @@ fn node_id_to_string(map: &Map, id: NodeId) -> String {
                 }
                 TypeTraitItem(ref t) => {
                     format!("type item {} in {} (id={})",
-                            token::get_ident(t.ident),
+                            token::get_ident(t.ty_param.ident),
                             map.path_to_string(id),
                             id)
                 }
diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs
index 863f53be798..3aa60236d70 100644
--- a/src/libsyntax/ast_util.rs
+++ b/src/libsyntax/ast_util.rs
@@ -524,7 +524,7 @@ impl<'a, 'v, O: IdVisitingOperation> Visitor<'v> for IdVisitor<'a, O> {
         match *tm {
             ast::RequiredMethod(ref m) => self.operation.visit_id(m.id),
             ast::ProvidedMethod(ref m) => self.operation.visit_id(m.id),
-            ast::TypeTraitItem(ref typ) => self.operation.visit_id(typ.id),
+            ast::TypeTraitItem(ref typ) => self.operation.visit_id(typ.ty_param.id),
         }
         visit::walk_trait_item(self, tm);
     }
diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs
index 330e4552e2f..7701f495f72 100644
--- a/src/libsyntax/feature_gate.rs
+++ b/src/libsyntax/feature_gate.rs
@@ -260,7 +260,7 @@ impl<'a, 'v> Visitor<'v> for Context<'a> {
             ast::RequiredMethod(_) | ast::ProvidedMethod(_) => {}
             ast::TypeTraitItem(ref ti) => {
                 self.gate_feature("associated_types",
-                                  ti.span,
+                                  ti.ty_param.span,
                                   "associated types are experimental")
             }
         }
diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs
index 9a55f07e98d..6535c8e89fd 100644
--- a/src/libsyntax/fold.rs
+++ b/src/libsyntax/fold.rs
@@ -793,19 +793,16 @@ pub fn noop_fold_typedef<T>(t: Typedef, folder: &mut T)
 
 pub fn noop_fold_associated_type<T>(at: AssociatedType, folder: &mut T)
                                     -> AssociatedType
-                                    where T: Folder {
-    let new_id = folder.new_id(at.id);
-    let new_span = folder.new_span(at.span);
-    let new_ident = folder.fold_ident(at.ident);
+                                    where T: Folder
+{
     let new_attrs = at.attrs
                       .iter()
                       .map(|attr| folder.fold_attribute((*attr).clone()))
                       .collect();
+    let new_param = folder.fold_ty_param(at.ty_param);
     ast::AssociatedType {
-        ident: new_ident,
         attrs: new_attrs,
-        id: new_id,
-        span: new_span,
+        ty_param: new_param,
     }
 }
 
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs
index 5e18c6bae48..37b9a0793b4 100644
--- a/src/libsyntax/parse/parser.rs
+++ b/src/libsyntax/parse/parser.rs
@@ -1229,16 +1229,13 @@ impl<'a> Parser<'a> {
     /// Parses `type Foo;` in a trait declaration only. The `type` keyword has
     /// already been parsed.
     fn parse_associated_type(&mut self, attrs: Vec<Attribute>)
-                             -> AssociatedType {
-        let lo = self.span.lo;
-        let ident = self.parse_ident();
-        let hi = self.span.hi;
+                             -> AssociatedType
+    {
+        let ty_param = self.parse_ty_param();
         self.expect(&token::Semi);
         AssociatedType {
-            id: ast::DUMMY_NODE_ID,
-            span: mk_sp(lo, hi),
-            ident: ident,
             attrs: attrs,
+            ty_param: ty_param,
         }
     }
 
diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs
index 4cfc95d4c3f..4cae3691f2a 100644
--- a/src/libsyntax/print/pprust.rs
+++ b/src/libsyntax/print/pprust.rs
@@ -815,9 +815,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, ";")
     }
 
@@ -2431,23 +2433,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(":", &param.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)
             }
         }));
 
@@ -2455,6 +2441,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(":", &param.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 {
diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs
index bec72e88f99..86ee23d71a6 100644
--- a/src/libsyntax/visit.rs
+++ b/src/libsyntax/visit.rs
@@ -596,7 +596,8 @@ pub fn walk_trait_item<'v, V: Visitor<'v>>(visitor: &mut V, trait_method: &'v Tr
         RequiredMethod(ref method_type) => visitor.visit_ty_method(method_type),
         ProvidedMethod(ref method) => walk_method_helper(visitor, &**method),
         TypeTraitItem(ref associated_type) => {
-            visitor.visit_ident(associated_type.span, associated_type.ident)
+            visitor.visit_ident(associated_type.ty_param.span,
+                                associated_type.ty_param.ident)
         }
     }
 }