@@ -26,11 +26,6 @@ impl<'r, 'a> AccessLevelsVisitor<'r, 'a> {
26
26
pub fn compute_access_levels < ' c > ( r : & ' r mut Resolver < ' a > , krate : & ' c Crate ) {
27
27
let mut visitor = AccessLevelsVisitor { r, changed : false } ;
28
28
29
- /*
30
- let crate_effective_vis = EffectiveVisibility::default();
31
- crate_effective_vis.update(Visibility::Public, AccessLevel::Public, visitor.r);
32
- visitor.r.access_levels.set_effective_vis(CRATE_DEF_ID, crate_effective_vis);
33
- */
34
29
visitor. set_access_level_def_id ( CRATE_DEF_ID , Some ( AccessLevel :: Public ) ) ;
35
30
visitor. set_bindings_access_level ( CRATE_DEF_ID ) ;
36
31
@@ -74,41 +69,30 @@ impl<'r, 'a> AccessLevelsVisitor<'r, 'a> {
74
69
let module = self . r . get_module ( module_id. to_def_id ( ) ) . unwrap ( ) ;
75
70
let resolutions = self . r . resolutions ( module) ;
76
71
77
- for ( key, name_resolution) in resolutions. borrow ( ) . iter ( ) {
78
- if let Some ( binding) = name_resolution. borrow ( ) . binding ( ) && binding. vis . is_public ( ) && !binding. is_ambiguity ( ) && module_level. is_some ( ) {
79
- let access_level = match binding. is_import ( ) {
72
+ for ( .., name_resolution) in resolutions. borrow ( ) . iter ( ) {
73
+
74
+ if let Some ( binding) = name_resolution. borrow ( ) . binding ( ) {
75
+ let tag = match binding. is_import ( ) {
80
76
true => {
81
- set_import_binding_access_level ( self , binding, module_level) ;
82
- Some ( AccessLevel :: Exported )
77
+ if binding. vis . is_public ( ) && !binding. is_ambiguity ( ) && module_level. is_some ( ) {
78
+ set_import_binding_access_level ( self , binding, module_level) ;
79
+ }
80
+ AccessLevel :: Exported
83
81
} ,
84
- false => module_level ,
82
+ false => AccessLevel :: Public
85
83
} ;
86
- if let Some ( def_id) = binding. res ( ) . opt_def_id ( ) . and_then ( |id| id. as_local ( ) ) {
87
- self . set_access_level_def_id ( def_id, access_level) ;
88
- }
89
- }
90
84
91
- if let Some ( binding) = name_resolution. borrow ( ) . binding ( ) {
92
- println ! ( "ident: {}" , key. ident. as_str( ) ) ;
93
85
if let Some ( def_id) = binding. res ( ) . opt_def_id ( ) . and_then ( |id| id. as_local ( ) ) {
94
- let tag = match binding. is_import ( ) {
95
- true => AccessLevel :: Exported ,
96
- false => AccessLevel :: Public ,
97
- } ;
98
86
let vis = match binding. vis {
99
87
Visibility :: Public => Visibility :: Public ,
100
88
Visibility :: Restricted ( id) => Visibility :: Restricted ( id. expect_local ( ) )
101
89
} ;
102
90
self . update_effective_vis ( def_id, vis, module_id, tag) ;
103
- } ;
91
+ }
104
92
}
105
93
}
106
94
}
107
95
108
- // fn init_crate_effective_vis(&mut self) {
109
-
110
- // }
111
-
112
96
fn update_effective_vis (
113
97
& mut self ,
114
98
current_id : LocalDefId ,
@@ -117,20 +101,15 @@ impl<'r, 'a> AccessLevelsVisitor<'r, 'a> {
117
101
tag : AccessLevel ,
118
102
) {
119
103
if let Some ( inherited_effective_vis) = self . r . access_levels . get_effective_vis ( module_id) {
120
- println ! ( "tag: {:?}" , tag) ;
121
- println ! ( "inherited effective vis: {:?}" , inherited_effective_vis) ;
122
104
let mut current_effective_vis = self . r . access_levels . get_effective_vis ( current_id) . copied ( ) . unwrap_or_default ( ) ;
123
105
let nearest_available_vis = inherited_effective_vis. nearest_available ( tag) . unwrap ( ) ;
124
- println ! ( "nearest available vis: {:?}" , nearest_available_vis) ;
125
106
let calculated_effective_vis = match current_vis {
126
107
Visibility :: Public => nearest_available_vis,
127
108
Visibility :: Restricted ( _) => {
128
109
if current_vis. is_at_least ( nearest_available_vis, & * self . r ) { nearest_available_vis} else { current_vis}
129
110
}
130
111
} ;
131
- println ! ( "calculated effective vis: {:?}" , calculated_effective_vis) ;
132
112
current_effective_vis. update ( calculated_effective_vis, tag, & * self . r ) ;
133
- println ! ( "updated effective vis: {:?}" , current_effective_vis) ;
134
113
self . r . access_levels . set_effective_vis ( current_id, current_effective_vis) ;
135
114
}
136
115
}
0 commit comments