@@ -43,7 +43,7 @@ use syntax::print::pprust::{
4343 ty_to_string
4444} ;
4545use syntax:: ptr:: P ;
46- use syntax:: codemap:: { Spanned , DUMMY_SP } ;
46+ use syntax:: codemap:: { Spanned , DUMMY_SP , respan } ;
4747use syntax_pos:: * ;
4848
4949use { escape, generated_code, lower_attributes, PathCollector , SaveContext } ;
@@ -65,12 +65,19 @@ macro_rules! down_cast_data {
6565}
6666
6767macro_rules! access_from {
68+ ( $save_ctxt: expr, $vis: expr, $id: expr) => {
69+ Access {
70+ public: $vis. node == ast:: VisibilityKind :: Public ,
71+ reachable: $save_ctxt. analysis. access_levels. is_reachable( $id) ,
72+ }
73+ } ;
74+
6875 ( $save_ctxt: expr, $item: expr) => {
6976 Access {
70- public: $item. vis == ast:: Visibility :: Public ,
77+ public: $item. vis. node == ast:: VisibilityKind :: Public ,
7178 reachable: $save_ctxt. analysis. access_levels. is_reachable( $item. id) ,
7279 }
73- }
80+ } ;
7481}
7582
7683pub struct DumpVisitor < ' l , ' tcx : ' l , ' ll , O : DumpOutput + ' ll > {
@@ -405,12 +412,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
405412
406413 method_data. value = sig_str;
407414 method_data. sig = sig:: method_signature ( id, name, generics, sig, & self . save_ctxt ) ;
408- self . dumper . dump_def (
409- & Access {
410- public : vis == ast:: Visibility :: Public ,
411- reachable : self . save_ctxt . analysis . access_levels . is_reachable ( id) ,
412- } ,
413- method_data) ;
415+ self . dumper . dump_def ( & access_from ! ( self . save_ctxt, vis, id) , method_data) ;
414416 }
415417
416418 // walk arg and return types
@@ -543,10 +545,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
543545 let span = self . span_from_span ( sub_span. expect ( "No span found for variable" ) ) ;
544546
545547 self . dumper . dump_def (
546- & Access {
547- public : vis == ast:: Visibility :: Public ,
548- reachable : self . save_ctxt . analysis . access_levels . is_reachable ( id) ,
549- } ,
548+ & access_from ! ( self . save_ctxt, vis, id) ,
550549 Def {
551550 kind : DefKind :: Const ,
552551 id : :: id_from_node_id ( id, & self . save_ctxt ) ,
@@ -597,7 +596,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
597596 . iter ( )
598597 . enumerate ( )
599598 . filter_map ( |( i, f) | {
600- if include_priv_fields || f. vis == ast:: Visibility :: Public {
599+ if include_priv_fields || f. vis . node == ast:: VisibilityKind :: Public {
601600 f. ident
602601 . map ( |i| i. to_string ( ) )
603602 . or_else ( || Some ( i. to_string ( ) ) )
@@ -1135,6 +1134,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
11351134
11361135 fn process_trait_item ( & mut self , trait_item : & ' l ast:: TraitItem , trait_id : DefId ) {
11371136 self . process_macro_use ( trait_item. span ) ;
1137+ let vis_span = trait_item. span . empty ( ) ;
11381138 match trait_item. node {
11391139 ast:: TraitItemKind :: Const ( ref ty, ref expr) => {
11401140 self . process_assoc_const (
@@ -1144,7 +1144,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
11441144 & ty,
11451145 expr. as_ref ( ) . map ( |e| & * * e) ,
11461146 trait_id,
1147- ast:: Visibility :: Public ,
1147+ respan ( vis_span , ast:: VisibilityKind :: Public ) ,
11481148 & trait_item. attrs ,
11491149 ) ;
11501150 }
@@ -1155,7 +1155,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
11551155 trait_item. id ,
11561156 trait_item. ident ,
11571157 & trait_item. generics ,
1158- ast:: Visibility :: Public ,
1158+ respan ( vis_span , ast:: VisibilityKind :: Public ) ,
11591159 trait_item. span ,
11601160 ) ;
11611161 }
@@ -1259,10 +1259,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
12591259
12601260 // The access is calculated using the current tree ID, but with the root tree's visibility
12611261 // (since nested trees don't have their own visibility).
1262- let access = Access {
1263- public : root_item. vis == ast:: Visibility :: Public ,
1264- reachable : self . save_ctxt . analysis . access_levels . is_reachable ( id) ,
1265- } ;
1262+ let access = access_from ! ( self . save_ctxt, root_item. vis, id) ;
12661263
12671264 // The parent def id of a given use tree is always the enclosing item.
12681265 let parent = self . save_ctxt . tcx . hir . opt_local_def_id ( id)
0 commit comments