@@ -43,7 +43,7 @@ use syntax::print::pprust::{
43
43
ty_to_string
44
44
} ;
45
45
use syntax:: ptr:: P ;
46
- use syntax:: codemap:: { Spanned , DUMMY_SP } ;
46
+ use syntax:: codemap:: { Spanned , DUMMY_SP , respan } ;
47
47
use syntax_pos:: * ;
48
48
49
49
use { escape, generated_code, lower_attributes, PathCollector , SaveContext } ;
@@ -65,12 +65,19 @@ macro_rules! down_cast_data {
65
65
}
66
66
67
67
macro_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
+
68
75
( $save_ctxt: expr, $item: expr) => {
69
76
Access {
70
- public: $item. vis == ast:: Visibility :: Public ,
77
+ public: $item. vis. node == ast:: VisibilityKind :: Public ,
71
78
reachable: $save_ctxt. analysis. access_levels. is_reachable( $item. id) ,
72
79
}
73
- }
80
+ } ;
74
81
}
75
82
76
83
pub 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> {
405
412
406
413
method_data. value = sig_str;
407
414
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) ;
414
416
}
415
417
416
418
// walk arg and return types
@@ -543,10 +545,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
543
545
let span = self . span_from_span ( sub_span. expect ( "No span found for variable" ) ) ;
544
546
545
547
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) ,
550
549
Def {
551
550
kind : DefKind :: Const ,
552
551
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> {
597
596
. iter ( )
598
597
. enumerate ( )
599
598
. 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 {
601
600
f. ident
602
601
. map ( |i| i. to_string ( ) )
603
602
. or_else ( || Some ( i. to_string ( ) ) )
@@ -1135,6 +1134,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
1135
1134
1136
1135
fn process_trait_item ( & mut self , trait_item : & ' l ast:: TraitItem , trait_id : DefId ) {
1137
1136
self . process_macro_use ( trait_item. span ) ;
1137
+ let vis_span = trait_item. span . empty ( ) ;
1138
1138
match trait_item. node {
1139
1139
ast:: TraitItemKind :: Const ( ref ty, ref expr) => {
1140
1140
self . process_assoc_const (
@@ -1144,7 +1144,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
1144
1144
& ty,
1145
1145
expr. as_ref ( ) . map ( |e| & * * e) ,
1146
1146
trait_id,
1147
- ast:: Visibility :: Public ,
1147
+ respan ( vis_span , ast:: VisibilityKind :: Public ) ,
1148
1148
& trait_item. attrs ,
1149
1149
) ;
1150
1150
}
@@ -1155,7 +1155,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
1155
1155
trait_item. id ,
1156
1156
trait_item. ident ,
1157
1157
& trait_item. generics ,
1158
- ast:: Visibility :: Public ,
1158
+ respan ( vis_span , ast:: VisibilityKind :: Public ) ,
1159
1159
trait_item. span ,
1160
1160
) ;
1161
1161
}
@@ -1259,10 +1259,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
1259
1259
1260
1260
// The access is calculated using the current tree ID, but with the root tree's visibility
1261
1261
// (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) ;
1266
1263
1267
1264
// The parent def id of a given use tree is always the enclosing item.
1268
1265
let parent = self . save_ctxt . tcx . hir . opt_local_def_id ( id)
0 commit comments