Skip to content

Commit

Permalink
Resolve lifetimes in associated types
Browse files Browse the repository at this point in the history
  • Loading branch information
sanxiyn committed Dec 15, 2014
1 parent 126db54 commit 4df66cd
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/libsyntax/visit.rs
Expand Up @@ -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, &param.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() {
Expand Down Expand Up @@ -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);
}
}
}
Expand Down
22 changes: 22 additions & 0 deletions 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 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(associated_types)]

trait Get<T> {
fn get(&self) -> T;
}

trait Trait<'a> {
type T: 'static;
type U: Get<&'a int>;
}

fn main() {}

0 comments on commit 4df66cd

Please sign in to comment.