@@ -128,6 +128,7 @@ pub trait Visitor<E: Clone> {
128128 fn visit_path ( & mut self , path : & Path , _id : ast:: NodeId , e : E ) {
129129 walk_path ( self , path, e)
130130 }
131+ fn visit_attribute ( & mut self , _attr : & Attribute , _e : E ) { }
131132}
132133
133134pub fn walk_inlined_item < E : Clone , V : Visitor < E > > ( visitor : & mut V ,
@@ -142,7 +143,10 @@ pub fn walk_inlined_item<E: Clone, V: Visitor<E>>(visitor: &mut V,
142143
143144
144145pub fn walk_crate < E : Clone , V : Visitor < E > > ( visitor : & mut V , krate : & Crate , env : E ) {
145- visitor. visit_mod ( & krate. module , krate. span , CRATE_NODE_ID , env)
146+ visitor. visit_mod ( & krate. module , krate. span , CRATE_NODE_ID , env. clone ( ) ) ;
147+ for attr in krate. attrs . iter ( ) {
148+ visitor. visit_attribute ( attr, env. clone ( ) ) ;
149+ }
146150}
147151
148152pub fn walk_mod < E : Clone , V : Visitor < E > > ( visitor : & mut V , module : & Mod , env : E ) {
@@ -158,7 +162,7 @@ pub fn walk_mod<E: Clone, V: Visitor<E>>(visitor: &mut V, module: &Mod, env: E)
158162pub fn walk_view_item < E : Clone , V : Visitor < E > > ( visitor : & mut V , vi : & ViewItem , env : E ) {
159163 match vi. node {
160164 ViewItemExternCrate ( name, _, _) => {
161- visitor. visit_ident ( vi. span , name, env)
165+ visitor. visit_ident ( vi. span , name, env. clone ( ) )
162166 }
163167 ViewItemUse ( ref vp) => {
164168 match vp. node {
@@ -178,6 +182,9 @@ pub fn walk_view_item<E: Clone, V: Visitor<E>>(visitor: &mut V, vi: &ViewItem, e
178182 }
179183 }
180184 }
185+ for attr in vi. attrs . iter ( ) {
186+ visitor. visit_attribute ( attr, env. clone ( ) ) ;
187+ }
181188}
182189
183190pub fn walk_local < E : Clone , V : Visitor < E > > ( visitor : & mut V , local : & Local , env : E ) {
@@ -213,18 +220,18 @@ pub fn walk_item<E: Clone, V: Visitor<E>>(visitor: &mut V, item: &Item, env: E)
213220 match item. node {
214221 ItemStatic ( typ, _, expr) => {
215222 visitor. visit_ty ( typ, env. clone ( ) ) ;
216- visitor. visit_expr ( expr, env) ;
223+ visitor. visit_expr ( expr, env. clone ( ) ) ;
217224 }
218225 ItemFn ( declaration, fn_style, abi, ref generics, body) => {
219226 visitor. visit_fn ( & FkItemFn ( item. ident , generics, fn_style, abi) ,
220227 declaration,
221228 body,
222229 item. span ,
223230 item. id ,
224- env)
231+ env. clone ( ) )
225232 }
226233 ItemMod ( ref module) => {
227- visitor. visit_mod ( module, item. span , item. id , env)
234+ visitor. visit_mod ( module, item. span , item. id , env. clone ( ) )
228235 }
229236 ItemForeignMod ( ref foreign_module) => {
230237 for view_item in foreign_module. view_items . iter ( ) {
@@ -236,11 +243,11 @@ pub fn walk_item<E: Clone, V: Visitor<E>>(visitor: &mut V, item: &Item, env: E)
236243 }
237244 ItemTy ( typ, ref type_parameters) => {
238245 visitor. visit_ty ( typ, env. clone ( ) ) ;
239- visitor. visit_generics ( type_parameters, env)
246+ visitor. visit_generics ( type_parameters, env. clone ( ) )
240247 }
241248 ItemEnum ( ref enum_definition, ref type_parameters) => {
242249 visitor. visit_generics ( type_parameters, env. clone ( ) ) ;
243- walk_enum_def ( visitor, enum_definition, type_parameters, env)
250+ walk_enum_def ( visitor, enum_definition, type_parameters, env. clone ( ) )
244251 }
245252 ItemImpl ( ref type_parameters,
246253 ref trait_reference,
@@ -263,7 +270,7 @@ pub fn walk_item<E: Clone, V: Visitor<E>>(visitor: &mut V, item: &Item, env: E)
263270 item. ident ,
264271 generics,
265272 item. id ,
266- env)
273+ env. clone ( ) )
267274 }
268275 ItemTrait ( ref generics, _, ref trait_paths, ref methods) => {
269276 visitor. visit_generics ( generics, env. clone ( ) ) ;
@@ -276,7 +283,10 @@ pub fn walk_item<E: Clone, V: Visitor<E>>(visitor: &mut V, item: &Item, env: E)
276283 visitor. visit_trait_method ( method, env. clone ( ) )
277284 }
278285 }
279- ItemMac ( ref macro) => visitor. visit_mac ( macro, env) ,
286+ ItemMac ( ref macro) => visitor. visit_mac ( macro, env. clone ( ) ) ,
287+ }
288+ for attr in item. attrs . iter ( ) {
289+ visitor. visit_attribute ( attr, env. clone ( ) ) ;
280290 }
281291}
282292
@@ -310,9 +320,12 @@ pub fn walk_variant<E: Clone, V: Visitor<E>>(visitor: &mut V,
310320 }
311321 }
312322 match variant. node . disr_expr {
313- Some ( expr) => visitor. visit_expr ( expr, env) ,
323+ Some ( expr) => visitor. visit_expr ( expr, env. clone ( ) ) ,
314324 None => ( )
315325 }
326+ for attr in variant. node . attrs . iter ( ) {
327+ visitor. visit_attribute ( attr, env. clone ( ) ) ;
328+ }
316329}
317330
318331pub fn skip_ty < E , V : Visitor < E > > ( _: & mut V , _: & Ty , _: E ) {
@@ -469,9 +482,13 @@ pub fn walk_foreign_item<E: Clone, V: Visitor<E>>(visitor: &mut V,
469482 match foreign_item. node {
470483 ForeignItemFn ( function_declaration, ref generics) => {
471484 walk_fn_decl ( visitor, function_declaration, env. clone ( ) ) ;
472- visitor. visit_generics ( generics, env)
485+ visitor. visit_generics ( generics, env. clone ( ) )
473486 }
474- ForeignItemStatic ( typ, _) => visitor. visit_ty ( typ, env) ,
487+ ForeignItemStatic ( typ, _) => visitor. visit_ty ( typ, env. clone ( ) ) ,
488+ }
489+
490+ for attr in foreign_item. attrs . iter ( ) {
491+ visitor. visit_attribute ( attr, env. clone ( ) ) ;
475492 }
476493}
477494
@@ -525,7 +542,10 @@ pub fn walk_method_helper<E: Clone, V: Visitor<E>>(visitor: &mut V,
525542 method. body ,
526543 method. span ,
527544 method. id ,
528- env)
545+ env. clone ( ) ) ;
546+ for attr in method. attrs . iter ( ) {
547+ visitor. visit_attribute ( attr, env. clone ( ) ) ;
548+ }
529549}
530550
531551pub fn walk_fn < E : Clone , V : Visitor < E > > ( visitor : & mut V ,
@@ -560,7 +580,10 @@ pub fn walk_ty_method<E: Clone, V: Visitor<E>>(visitor: &mut V,
560580 visitor. visit_ty ( argument_type. ty , env. clone ( ) )
561581 }
562582 visitor. visit_generics ( & method_type. generics , env. clone ( ) ) ;
563- visitor. visit_ty ( method_type. decl . output , env) ;
583+ visitor. visit_ty ( method_type. decl . output , env. clone ( ) ) ;
584+ for attr in method_type. attrs . iter ( ) {
585+ visitor. visit_attribute ( attr, env. clone ( ) ) ;
586+ }
564587}
565588
566589pub fn walk_trait_method < E : Clone , V : Visitor < E > > ( visitor : & mut V ,
@@ -596,7 +619,11 @@ pub fn walk_struct_field<E: Clone, V: Visitor<E>>(visitor: &mut V,
596619 _ => { }
597620 }
598621
599- visitor. visit_ty ( struct_field. node . ty , env)
622+ visitor. visit_ty ( struct_field. node . ty , env. clone ( ) ) ;
623+
624+ for attr in struct_field. node . attrs . iter ( ) {
625+ visitor. visit_attribute ( attr, env. clone ( ) ) ;
626+ }
600627}
601628
602629pub fn walk_block < E : Clone , V : Visitor < E > > ( visitor : & mut V , block : & Block , env : E ) {
@@ -784,5 +811,8 @@ pub fn walk_arm<E: Clone, V: Visitor<E>>(visitor: &mut V, arm: &Arm, env: E) {
784811 visitor. visit_pat ( * pattern, env. clone ( ) )
785812 }
786813 walk_expr_opt ( visitor, arm. guard , env. clone ( ) ) ;
787- visitor. visit_expr ( arm. body , env)
814+ visitor. visit_expr ( arm. body , env. clone ( ) ) ;
815+ for attr in arm. attrs . iter ( ) {
816+ visitor. visit_attribute ( attr, env. clone ( ) ) ;
817+ }
788818}
0 commit comments