@@ -21,6 +21,7 @@ use driver::session::Session;
2121use middle:: subst;
2222use syntax:: ast;
2323use syntax:: codemap:: Span ;
24+ use syntax:: owned_slice:: OwnedSlice ;
2425use syntax:: parse:: token:: special_idents;
2526use syntax:: parse:: token;
2627use syntax:: print:: pprust:: { lifetime_to_string} ;
@@ -98,8 +99,22 @@ impl<'a, 'v> Visitor<'v> for LifetimeContext<'a> {
9899 ast:: ItemTy ( _, ref generics) |
99100 ast:: ItemEnum ( _, ref generics) |
100101 ast:: ItemStruct ( _, ref generics) |
101- ast:: ItemImpl ( ref generics, _, _, _) |
102- ast:: ItemTrait ( ref generics, _, _, _) => & generics. lifetimes
102+ ast:: ItemTrait ( ref generics, _, _, _) => {
103+ self . with ( |scope, f| {
104+ f ( EarlyScope ( subst:: TypeSpace ,
105+ & generics. lifetimes ,
106+ scope) )
107+ } , |v| v. check_lifetime_defs ( & generics. lifetimes ) ) ;
108+ & generics. lifetimes
109+ }
110+ ast:: ItemImpl ( ref generics, _, _, _) => {
111+ self . with ( |scope, f| {
112+ f ( EarlyScope ( subst:: TypeSpace ,
113+ & generics. lifetimes ,
114+ scope) )
115+ } , |v| v. check_lifetime_defs ( & generics. lifetimes ) ) ;
116+ & generics. lifetimes
117+ }
103118 } ;
104119
105120 self . with ( |_, f| f ( EarlyScope ( subst:: TypeSpace , lifetimes, & ROOT_SCOPE ) ) , |v| {
@@ -155,6 +170,20 @@ impl<'a, 'v> Visitor<'v> for LifetimeContext<'a> {
155170 }
156171 self . resolve_lifetime_ref ( lifetime_ref) ;
157172 }
173+
174+ fn visit_generics ( & mut self , generics : & ast:: Generics ) {
175+ for ty_param in generics. ty_params . iter ( ) {
176+ self . visit_ty_param_bounds ( & ty_param. bounds ) ;
177+ match ty_param. default {
178+ Some ( ref ty) => self . visit_ty ( & * * ty) ,
179+ None => { }
180+ }
181+ }
182+ for predicate in generics. where_clause . predicates . iter ( ) {
183+ self . visit_ident ( predicate. span , predicate. ident ) ;
184+ self . visit_ty_param_bounds ( & predicate. bounds ) ;
185+ }
186+ }
158187}
159188
160189impl < ' a > LifetimeContext < ' a > {
@@ -167,6 +196,47 @@ impl<'a> LifetimeContext<'a> {
167196 } ) )
168197 }
169198
199+ fn visit_ty_param_bounds ( & mut self ,
200+ bounds : & OwnedSlice < ast:: TyParamBound > ) {
201+ for bound in bounds. iter ( ) {
202+ match * bound {
203+ ast:: TraitTyParamBound ( ref trait_ref) => {
204+ self . visit_trait_ref ( trait_ref) ;
205+ }
206+ ast:: UnboxedFnTyParamBound ( ref fn_decl) => {
207+ self . visit_unboxed_fn_ty_param_bound ( & * * fn_decl) ;
208+ }
209+ ast:: RegionTyParamBound ( ref lifetime) => {
210+ self . visit_lifetime_ref ( lifetime) ;
211+ }
212+ }
213+ }
214+ }
215+
216+ fn visit_trait_ref ( & mut self , trait_ref : & ast:: TraitRef ) {
217+ self . with ( |scope, f| {
218+ f ( LateScope ( trait_ref. ref_id , & trait_ref. lifetimes , scope) )
219+ } , |v| {
220+ v. check_lifetime_defs ( & trait_ref. lifetimes ) ;
221+ for lifetime in trait_ref. lifetimes . iter ( ) {
222+ v. visit_lifetime_decl ( lifetime) ;
223+ }
224+ v. visit_path ( & trait_ref. path , trait_ref. ref_id ) ;
225+ } )
226+ }
227+
228+ fn visit_unboxed_fn_ty_param_bound ( & mut self ,
229+ bound : & ast:: UnboxedFnBound ) {
230+ self . with ( |scope, f| {
231+ f ( LateScope ( bound. ref_id , & bound. lifetimes , scope) )
232+ } , |v| {
233+ for argument in bound. decl . inputs . iter ( ) {
234+ v. visit_ty ( & * argument. ty ) ;
235+ }
236+ v. visit_ty ( & * bound. decl . output ) ;
237+ } )
238+ }
239+
170240 /// Visits self by adding a scope and handling recursive walk over the contents with `walk`.
171241 fn visit_fn_decl ( & mut self ,
172242 n : ast:: NodeId ,
0 commit comments