@@ -106,7 +106,7 @@ impl DefMap {
106106 visibility : & RawVisibility ,
107107 within_impl : bool ,
108108 ) -> Option < Visibility > {
109- let mut vis = match visibility {
109+ let vis = match visibility {
110110 RawVisibility :: Module ( path, explicitness) => {
111111 let ( result, remaining) = self . resolve_path (
112112 local_def_map,
@@ -120,29 +120,36 @@ impl DefMap {
120120 return None ;
121121 }
122122 let types = result. take_types ( ) ?;
123- match types {
123+ let mut vis = match types {
124124 ModuleDefId :: ModuleId ( m) => Visibility :: Module ( m, * explicitness) ,
125125 // error: visibility needs to refer to module
126126 _ => {
127127 return None ;
128128 }
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+ }
129144 }
145+ vis
146+ }
147+ RawVisibility :: PubSelf ( explicitness) => {
148+ Visibility :: Module ( self . module_id ( original_module) , * explicitness)
130149 }
131150 RawVisibility :: Public => Visibility :: Public ,
151+ RawVisibility :: PubCrate => Visibility :: PubCrate ( self . krate ) ,
132152 } ;
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-
146153 Some ( vis)
147154 }
148155
0 commit comments