@@ -106,7 +106,7 @@ impl DefMap {
106
106
visibility : & RawVisibility ,
107
107
within_impl : bool ,
108
108
) -> Option < Visibility > {
109
- let mut vis = match visibility {
109
+ let vis = match visibility {
110
110
RawVisibility :: Module ( path, explicitness) => {
111
111
let ( result, remaining) = self . resolve_path (
112
112
local_def_map,
@@ -120,29 +120,36 @@ impl DefMap {
120
120
return None ;
121
121
}
122
122
let types = result. take_types ( ) ?;
123
- match types {
123
+ let mut vis = match types {
124
124
ModuleDefId :: ModuleId ( m) => Visibility :: Module ( m, * explicitness) ,
125
125
// error: visibility needs to refer to module
126
126
_ => {
127
127
return None ;
128
128
}
129
+ } ;
130
+
131
+ // In block expressions, `self` normally refers to the containing non-block module, and
132
+ // `super` to its parent (etc.). However, visibilities must only refer to a module in the
133
+ // DefMap they're written in, so we restrict them when that happens.
134
+ if let Visibility :: Module ( m, mv) = vis {
135
+ // ...unless we're resolving visibility for an associated item in an impl.
136
+ if self . block_id ( ) != m. block && !within_impl {
137
+ vis = Visibility :: Module ( self . module_id ( Self :: ROOT ) , mv) ;
138
+ tracing:: debug!(
139
+ "visibility {:?} points outside DefMap, adjusting to {:?}" ,
140
+ m,
141
+ vis
142
+ ) ;
143
+ }
129
144
}
145
+ vis
146
+ }
147
+ RawVisibility :: PubSelf ( explicitness) => {
148
+ Visibility :: Module ( self . module_id ( original_module) , * explicitness)
130
149
}
131
150
RawVisibility :: Public => Visibility :: Public ,
151
+ RawVisibility :: PubCrate => Visibility :: PubCrate ( self . krate ) ,
132
152
} ;
133
-
134
- // In block expressions, `self` normally refers to the containing non-block module, and
135
- // `super` to its parent (etc.). However, visibilities must only refer to a module in the
136
- // DefMap they're written in, so we restrict them when that happens.
137
- if let Visibility :: Module ( m, mv) = vis {
138
- // ...unless we're resolving visibility for an associated item in an impl.
139
- if self . block_id ( ) != m. block && !within_impl {
140
- cov_mark:: hit!( adjust_vis_in_block_def_map) ;
141
- vis = Visibility :: Module ( self . module_id ( Self :: ROOT ) , mv) ;
142
- tracing:: debug!( "visibility {:?} points outside DefMap, adjusting to {:?}" , m, vis) ;
143
- }
144
- }
145
-
146
153
Some ( vis)
147
154
}
148
155
0 commit comments