Skip to content

Commit 690f25f

Browse files
committed
Merge pull request #19880 from sanxiyn/assoc-resolve-lifetime
Resolve lifetimes in associated types Reviewed-by: alexcrichton
2 parents f85be32 + 4df66cd commit 690f25f

File tree

2 files changed

+33
-8
lines changed

2 files changed

+33
-8
lines changed

src/libsyntax/visit.rs

+11-8
Original file line numberDiff line numberDiff line change
@@ -555,14 +555,18 @@ pub fn walk_ty_param_bound<'v, V: Visitor<'v>>(visitor: &mut V,
555555
}
556556
}
557557

558+
pub fn walk_ty_param<'v, V: Visitor<'v>>(visitor: &mut V, param: &'v TyParam) {
559+
visitor.visit_ident(param.span, param.ident);
560+
walk_ty_param_bounds_helper(visitor, &param.bounds);
561+
match param.default {
562+
Some(ref ty) => visitor.visit_ty(&**ty),
563+
None => {}
564+
}
565+
}
566+
558567
pub fn walk_generics<'v, V: Visitor<'v>>(visitor: &mut V, generics: &'v Generics) {
559568
for type_parameter in generics.ty_params.iter() {
560-
visitor.visit_ident(type_parameter.span, type_parameter.ident);
561-
walk_ty_param_bounds_helper(visitor, &type_parameter.bounds);
562-
match type_parameter.default {
563-
Some(ref ty) => visitor.visit_ty(&**ty),
564-
None => {}
565-
}
569+
walk_ty_param(visitor, type_parameter);
566570
}
567571
walk_lifetime_decls_helper(visitor, &generics.lifetimes);
568572
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
665669
RequiredMethod(ref method_type) => visitor.visit_ty_method(method_type),
666670
ProvidedMethod(ref method) => walk_method_helper(visitor, &**method),
667671
TypeTraitItem(ref associated_type) => {
668-
visitor.visit_ident(associated_type.ty_param.span,
669-
associated_type.ty_param.ident)
672+
walk_ty_param(visitor, &associated_type.ty_param);
670673
}
671674
}
672675
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![feature(associated_types)]
12+
13+
trait Get<T> {
14+
fn get(&self) -> T;
15+
}
16+
17+
trait Trait<'a> {
18+
type T: 'static;
19+
type U: Get<&'a int>;
20+
}
21+
22+
fn main() {}

0 commit comments

Comments
 (0)