From 78a841810eb36e486ba68e6b9fa80e45d805cc4f Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Tue, 5 Aug 2014 19:44:21 -0700 Subject: 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. `::Bar`--are supported. --- src/libsyntax/visit.rs | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) (limited to 'src/libsyntax/visit.rs') diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs index 30a38e28729..d425c60f4c9 100644 --- a/src/libsyntax/visit.rs +++ b/src/libsyntax/visit.rs @@ -116,12 +116,19 @@ pub trait Visitor<'v> { fn visit_attribute(&mut self, _attr: &'v Attribute) {} } -pub fn walk_inlined_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v InlinedItem) { +pub fn walk_inlined_item<'v,V>(visitor: &mut V, item: &'v InlinedItem) + where V: Visitor<'v> { match *item { IIItem(ref i) => visitor.visit_item(&**i), IIForeign(ref i) => visitor.visit_foreign_item(&**i), IITraitItem(_, ref ti) => visitor.visit_trait_item(ti), - IIImplItem(_, MethodImplItem(ref m)) => walk_method_helper(visitor, &**m) + IIImplItem(_, MethodImplItem(ref m)) => { + walk_method_helper(visitor, &**m) + } + IIImplItem(_, TypeImplItem(ref typedef)) => { + visitor.visit_ident(typedef.span, typedef.ident); + visitor.visit_ty(&*typedef.typ); + } } } @@ -248,6 +255,10 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item) { MethodImplItem(ref method) => { walk_method_helper(visitor, &**method) } + TypeImplItem(ref typedef) => { + visitor.visit_ident(typedef.span, typedef.ident); + visitor.visit_ty(&*typedef.typ); + } } } } @@ -366,6 +377,11 @@ pub fn walk_ty<'v, V: Visitor<'v>>(visitor: &mut V, typ: &'v Ty) { None => { } } } + TyQPath(ref qpath) => { + visitor.visit_ty(&*qpath.for_type); + visitor.visit_path(&qpath.trait_name, typ.id); + visitor.visit_ident(typ.span, qpath.item_name); + } TyFixedLengthVec(ref ty, ref expression) => { visitor.visit_ty(&**ty); visitor.visit_expr(&**expression) @@ -573,10 +589,11 @@ pub fn walk_ty_method<'v, V: Visitor<'v>>(visitor: &mut V, method_type: &'v Type pub fn walk_trait_item<'v, V: Visitor<'v>>(visitor: &mut V, trait_method: &'v TraitItem) { match *trait_method { - RequiredMethod(ref method_type) => { - visitor.visit_ty_method(method_type) - } + 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) + } } } -- cgit 1.4.1-3-g733a5