@@ -51,6 +51,10 @@ impl Visibility {
51
51
Visibility :: PubCrate ( krate) => return from_module. krate ( db) == krate,
52
52
Visibility :: Public => return true ,
53
53
} ;
54
+ if from_module == to_module {
55
+ // if the modules are the same, visibility is trivially satisfied
56
+ return true ;
57
+ }
54
58
// if they're not in the same crate, it can't be visible
55
59
if from_module. krate ( db) != to_module. krate ( db) {
56
60
return false ;
@@ -73,6 +77,10 @@ impl Visibility {
73
77
Visibility :: PubCrate ( krate) => return from_module. krate ( db) == krate,
74
78
Visibility :: Public => return true ,
75
79
} ;
80
+ if from_module == to_module {
81
+ // if the modules are the same, visibility is trivially satisfied
82
+ return true ;
83
+ }
76
84
// if they're not in the same crate, it can't be visible
77
85
if def_map. krate ( ) != to_module. krate ( db) {
78
86
return false ;
@@ -100,9 +108,7 @@ impl Visibility {
100
108
// `to_module` is not a block, so there is no parent def map to use.
101
109
( None , _) => ( ) ,
102
110
// `to_module` is at `def_map`'s block, no need to move further.
103
- ( Some ( a) , Some ( b) ) if a == b => {
104
- cov_mark:: hit!( nested_module_scoping) ;
105
- }
111
+ ( Some ( a) , Some ( b) ) if a == b => { }
106
112
_ => {
107
113
if let Some ( parent) = to_module. def_map ( db) . parent ( ) {
108
114
to_module = parent;
@@ -161,6 +167,21 @@ impl Visibility {
161
167
if mod_. krate ( db) == krate { Some ( Visibility :: PubCrate ( krate) ) } else { None }
162
168
}
163
169
( Visibility :: Module ( mod_a, expl_a) , Visibility :: Module ( mod_b, expl_b) ) => {
170
+ if mod_a == mod_b {
171
+ // Most module visibilities are `pub(self)`, and assuming no errors
172
+ // this will be the common and thus fast path.
173
+ return Some ( Visibility :: Module (
174
+ mod_a,
175
+ match ( expl_a, expl_b) {
176
+ ( VisibilityExplicitness :: Explicit , _)
177
+ | ( _, VisibilityExplicitness :: Explicit ) => {
178
+ VisibilityExplicitness :: Explicit
179
+ }
180
+ _ => VisibilityExplicitness :: Implicit ,
181
+ } ,
182
+ ) ) ;
183
+ }
184
+
164
185
if mod_a. krate ( db) != def_map. krate ( ) || mod_b. krate ( db) != def_map. krate ( ) {
165
186
return None ;
166
187
}
@@ -212,6 +233,21 @@ impl Visibility {
212
233
if mod_. krate ( db) == krate { Some ( Visibility :: Module ( mod_, exp) ) } else { None }
213
234
}
214
235
( Visibility :: Module ( mod_a, expl_a) , Visibility :: Module ( mod_b, expl_b) ) => {
236
+ if mod_a == mod_b {
237
+ // Most module visibilities are `pub(self)`, and assuming no errors
238
+ // this will be the common and thus fast path.
239
+ return Some ( Visibility :: Module (
240
+ mod_a,
241
+ match ( expl_a, expl_b) {
242
+ ( VisibilityExplicitness :: Explicit , _)
243
+ | ( _, VisibilityExplicitness :: Explicit ) => {
244
+ VisibilityExplicitness :: Explicit
245
+ }
246
+ _ => VisibilityExplicitness :: Implicit ,
247
+ } ,
248
+ ) ) ;
249
+ }
250
+
215
251
if mod_a. krate ( db) != def_map. krate ( ) || mod_b. krate ( db) != def_map. krate ( ) {
216
252
return None ;
217
253
}
0 commit comments