@@ -37,6 +37,7 @@ fn should_explore(tcx: ty::ctxt, def_id: ast::DefId) -> bool {
3737 match tcx. items . find ( & def_id. node ) {
3838 Some ( & ast_map:: node_item( ..) )
3939 | Some ( & ast_map:: node_method( ..) )
40+ | Some ( & ast_map:: node_foreign_item( ..) )
4041 | Some ( & ast_map:: node_trait_method( ..) ) => true ,
4142 _ => false
4243 }
@@ -106,8 +107,7 @@ impl MarkSymbolVisitor {
106107 match item. node {
107108 ast:: item_fn( ..)
108109 | ast:: item_ty( ..)
109- | ast:: item_static( ..)
110- | ast:: item_foreign_mod( _) => {
110+ | ast:: item_static( ..) => {
111111 visit:: walk_item ( self , item, ( ) ) ;
112112 }
113113 _ => ( )
@@ -119,6 +119,9 @@ impl MarkSymbolVisitor {
119119 ast_map:: node_method( method, _, _) => {
120120 visit:: walk_block ( self , method. body , ( ) ) ;
121121 }
122+ ast_map:: node_foreign_item( foreign_item, _, _, _) => {
123+ visit:: walk_foreign_item ( self , foreign_item, ( ) ) ;
124+ }
122125 _ => ( )
123126 }
124127 }
@@ -299,19 +302,31 @@ impl DeadVisitor {
299302 }
300303 false
301304 }
305+
306+ fn warn_dead_code ( & mut self , id : ast:: NodeId ,
307+ span : codemap:: Span , ident : & ast:: Ident ) {
308+ self . tcx . sess . add_lint ( dead_code, id, span,
309+ format ! ( "code is never used: `{}`" ,
310+ token:: ident_to_str( ident) ) ) ;
311+ }
302312}
303313
304314impl Visitor < ( ) > for DeadVisitor {
305315 fn visit_item ( & mut self , item : @ast:: item , _: ( ) ) {
306316 let ctor_id = get_struct_ctor_id ( item) ;
307317 if !self . symbol_is_live ( item. id , ctor_id) && should_warn ( item) {
308- self . tcx . sess . add_lint ( dead_code, item. id , item. span ,
309- format ! ( "code is never used: `{}`" ,
310- token:: ident_to_str( & item. ident) ) ) ;
318+ self . warn_dead_code ( item. id , item. span , & item. ident ) ;
311319 }
312320 visit:: walk_item ( self , item, ( ) ) ;
313321 }
314322
323+ fn visit_foreign_item ( & mut self , fi : @ast:: foreign_item , _: ( ) ) {
324+ if !self . symbol_is_live ( fi. id , None ) {
325+ self . warn_dead_code ( fi. id , fi. span , & fi. ident ) ;
326+ }
327+ visit:: walk_foreign_item ( self , fi, ( ) ) ;
328+ }
329+
315330 fn visit_fn ( & mut self , fk : & visit:: fn_kind ,
316331 _: & ast:: fn_decl , block : ast:: P < ast:: Block > ,
317332 span : codemap:: Span , id : ast:: NodeId , _: ( ) ) {
@@ -320,10 +335,7 @@ impl Visitor<()> for DeadVisitor {
320335 visit:: fk_method( ..) => {
321336 let ident = visit:: name_of_fn ( fk) ;
322337 if !self . symbol_is_live ( id, None ) {
323- self . tcx . sess
324- . add_lint ( dead_code, id, span,
325- format ! ( "code is never used: `{}`" ,
326- token:: ident_to_str( & ident) ) ) ;
338+ self . warn_dead_code ( id, span, & ident) ;
327339 }
328340 }
329341 _ => ( )
0 commit comments