From 4df66cd014409042f1ddbc2f2130c81e4bdc941f Mon Sep 17 00:00:00 2001 From: Seo Sanghyeon Date: Mon, 15 Dec 2014 22:31:38 +0900 Subject: [PATCH] Resolve lifetimes in associated types --- src/libsyntax/visit.rs | 19 +++++++++------- .../associated-types-resolve-lifetime.rs | 22 +++++++++++++++++++ 2 files changed, 33 insertions(+), 8 deletions(-) create mode 100644 src/test/run-pass/associated-types-resolve-lifetime.rs diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs index 3535c6e267eba..cf3efeeeb8fe3 100644 --- a/src/libsyntax/visit.rs +++ b/src/libsyntax/visit.rs @@ -555,14 +555,18 @@ pub fn walk_ty_param_bound<'v, V: Visitor<'v>>(visitor: &mut V, } } +pub fn walk_ty_param<'v, V: Visitor<'v>>(visitor: &mut V, param: &'v TyParam) { + visitor.visit_ident(param.span, param.ident); + walk_ty_param_bounds_helper(visitor, ¶m.bounds); + match param.default { + Some(ref ty) => visitor.visit_ty(&**ty), + None => {} + } +} + pub fn walk_generics<'v, V: Visitor<'v>>(visitor: &mut V, generics: &'v Generics) { for type_parameter in generics.ty_params.iter() { - visitor.visit_ident(type_parameter.span, type_parameter.ident); - walk_ty_param_bounds_helper(visitor, &type_parameter.bounds); - match type_parameter.default { - Some(ref ty) => visitor.visit_ty(&**ty), - None => {} - } + walk_ty_param(visitor, type_parameter); } walk_lifetime_decls_helper(visitor, &generics.lifetimes); for predicate in generics.where_clause.predicates.iter() { @@ -665,8 +669,7 @@ 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.ty_param.span, - associated_type.ty_param.ident) + walk_ty_param(visitor, &associated_type.ty_param); } } } diff --git a/src/test/run-pass/associated-types-resolve-lifetime.rs b/src/test/run-pass/associated-types-resolve-lifetime.rs new file mode 100644 index 0000000000000..1be09e1e0680d --- /dev/null +++ b/src/test/run-pass/associated-types-resolve-lifetime.rs @@ -0,0 +1,22 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![feature(associated_types)] + +trait Get { + fn get(&self) -> T; +} + +trait Trait<'a> { + type T: 'static; + type U: Get<&'a int>; +} + +fn main() {}