@@ -1186,8 +1186,6 @@ impl clean::Visibility {
1186
1186
item_did : DefId ,
1187
1187
cache : & ' a Cache ,
1188
1188
) -> impl fmt:: Display + ' a + Captures < ' tcx > {
1189
- use rustc_span:: symbol:: kw;
1190
-
1191
1189
let to_print = match self {
1192
1190
clean:: Public => "pub " . to_owned ( ) ,
1193
1191
clean:: Inherited => String :: new ( ) ,
@@ -1212,18 +1210,11 @@ impl clean::Visibility {
1212
1210
} else {
1213
1211
let path = tcx. def_path ( vis_did) ;
1214
1212
debug ! ( "path={:?}" , path) ;
1215
- let first_name =
1216
- path. data [ 0 ] . data . get_opt_name ( ) . expect ( "modules are always named" ) ;
1217
1213
// modified from `resolved_path()` to work with `DefPathData`
1218
1214
let last_name = path. data . last ( ) . unwrap ( ) . data . get_opt_name ( ) . unwrap ( ) ;
1219
1215
let anchor = anchor ( vis_did, & last_name. as_str ( ) , cache) . to_string ( ) ;
1220
1216
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 ( ) ;
1227
1218
for seg in & path. data [ ..path. data . len ( ) - 1 ] {
1228
1219
s. push_str ( & format ! ( "{}::" , seg. data. get_opt_name( ) . unwrap( ) ) ) ;
1229
1220
}
@@ -1234,6 +1225,43 @@ impl clean::Visibility {
1234
1225
} ;
1235
1226
display_fn ( move |f| f. write_str ( & to_print) )
1236
1227
}
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
+ }
1237
1265
}
1238
1266
1239
1267
crate trait PrintWithSpace {
0 commit comments