@@ -1186,8 +1186,6 @@ impl clean::Visibility {
11861186        item_did :  DefId , 
11871187        cache :  & ' a  Cache , 
11881188    )  -> impl  fmt:: Display  + ' a  + Captures < ' tcx >  { 
1189-         use  rustc_span:: symbol:: kw; 
1190- 
11911189        let  to_print = match  self  { 
11921190            clean:: Public  => "pub " . to_owned ( ) , 
11931191            clean:: Inherited  => String :: new ( ) , 
@@ -1212,18 +1210,11 @@ impl clean::Visibility {
12121210                }  else  { 
12131211                    let  path = tcx. def_path ( vis_did) ; 
12141212                    debug ! ( "path={:?}" ,  path) ; 
1215-                     let  first_name =
1216-                         path. data [ 0 ] . data . get_opt_name ( ) . expect ( "modules are always named" ) ; 
12171213                    // modified from `resolved_path()` to work with `DefPathData` 
12181214                    let  last_name = path. data . last ( ) . unwrap ( ) . data . get_opt_name ( ) . unwrap ( ) ; 
12191215                    let  anchor = anchor ( vis_did,  & last_name. as_str ( ) ,  cache) . to_string ( ) ; 
12201216
1221-                     let  mut  s = "pub(" . to_owned ( ) ; 
1222-                     if  path. data . len ( )  != 1 
1223-                         || ( first_name != kw:: SelfLower  && first_name != kw:: Super ) 
1224-                     { 
1225-                         s. push_str ( "in " ) ; 
1226-                     } 
1217+                     let  mut  s = "pub(in " . to_owned ( ) ; 
12271218                    for  seg in  & path. data [ ..path. data . len ( )  - 1 ]  { 
12281219                        s. push_str ( & format ! ( "{}::" ,  seg. data. get_opt_name( ) . unwrap( ) ) ) ; 
12291220                    } 
@@ -1234,6 +1225,43 @@ impl clean::Visibility {
12341225        } ; 
12351226        display_fn ( move  |f| f. write_str ( & to_print) ) 
12361227    } 
1228+ 
1229+     /// This function is the same as print_with_space, except that it renders no links. 
1230+      /// It's used for macros' rendered source view, which is syntax highlighted and cannot have 
1231+      /// any HTML in it. 
1232+      crate  fn  to_src_with_space < ' a ,  ' tcx :  ' a > ( 
1233+         self , 
1234+         tcx :  TyCtxt < ' tcx > , 
1235+         item_did :  DefId , 
1236+     )  -> impl  fmt:: Display  + ' a  + Captures < ' tcx >  { 
1237+         let  to_print = match  self  { 
1238+             clean:: Public  => "pub " . to_owned ( ) , 
1239+             clean:: Inherited  => String :: new ( ) , 
1240+             clean:: Visibility :: Restricted ( vis_did)  => { 
1241+                 // FIXME(camelid): This may not work correctly if `item_did` is a module. 
1242+                 //                 However, rustdoc currently never displays a module's 
1243+                 //                 visibility, so it shouldn't matter. 
1244+                 let  parent_module = find_nearest_parent_module ( tcx,  item_did) ; 
1245+ 
1246+                 if  vis_did. index  == CRATE_DEF_INDEX  { 
1247+                     "pub(crate) " . to_owned ( ) 
1248+                 }  else  if  parent_module == Some ( vis_did)  { 
1249+                     // `pub(in foo)` where `foo` is the parent module 
1250+                     // is the same as no visibility modifier 
1251+                     String :: new ( ) 
1252+                 }  else  if  parent_module
1253+                     . map ( |parent| find_nearest_parent_module ( tcx,  parent) ) 
1254+                     . flatten ( ) 
1255+                     == Some ( vis_did) 
1256+                 { 
1257+                     "pub(super) " . to_owned ( ) 
1258+                 }  else  { 
1259+                     format ! ( "pub(in {}) " ,  tcx. def_path_str( vis_did) ) 
1260+                 } 
1261+             } 
1262+         } ; 
1263+         display_fn ( move  |f| f. write_str ( & to_print) ) 
1264+     } 
12371265} 
12381266
12391267crate  trait  PrintWithSpace  { 
0 commit comments