@@ -1420,87 +1420,84 @@ impl clean::FnDecl {
14201420 }
14211421}
14221422
1423- impl clean:: Visibility {
1424- pub ( crate ) fn print_with_space < ' a , ' tcx : ' a > (
1425- self ,
1426- item_did : ItemId ,
1427- cx : & ' a Context < ' tcx > ,
1428- ) -> impl fmt:: Display + ' a + Captures < ' tcx > {
1429- use std:: fmt:: Write as _;
1430-
1431- let to_print: Cow < ' static , str > = match self {
1432- clean:: Public => "pub " . into ( ) ,
1433- clean:: Inherited => "" . into ( ) ,
1434- clean:: Visibility :: Restricted ( vis_did) => {
1435- // FIXME(camelid): This may not work correctly if `item_did` is a module.
1436- // However, rustdoc currently never displays a module's
1437- // visibility, so it shouldn't matter.
1438- let parent_module = find_nearest_parent_module ( cx. tcx ( ) , item_did. expect_def_id ( ) ) ;
1439-
1440- if vis_did. is_crate_root ( ) {
1441- "pub(crate) " . into ( )
1442- } else if parent_module == Some ( vis_did) {
1443- // `pub(in foo)` where `foo` is the parent module
1444- // is the same as no visibility modifier
1445- "" . into ( )
1446- } else if parent_module
1447- . and_then ( |parent| find_nearest_parent_module ( cx. tcx ( ) , parent) )
1448- == Some ( vis_did)
1449- {
1450- "pub(super) " . into ( )
1451- } else {
1452- let path = cx. tcx ( ) . def_path ( vis_did) ;
1453- debug ! ( "path={:?}" , path) ;
1454- // modified from `resolved_path()` to work with `DefPathData`
1455- let last_name = path. data . last ( ) . unwrap ( ) . data . get_opt_name ( ) . unwrap ( ) ;
1456- let anchor = anchor ( vis_did, last_name, cx) . to_string ( ) ;
1457-
1458- let mut s = "pub(in " . to_owned ( ) ;
1459- for seg in & path. data [ ..path. data . len ( ) - 1 ] {
1460- let _ = write ! ( s, "{}::" , seg. data. get_opt_name( ) . unwrap( ) ) ;
1461- }
1462- let _ = write ! ( s, "{}) " , anchor) ;
1463- s. into ( )
1423+ pub ( crate ) fn visibility_print_with_space < ' a , ' tcx : ' a > (
1424+ visibility : Option < ty:: Visibility < DefId > > ,
1425+ item_did : ItemId ,
1426+ cx : & ' a Context < ' tcx > ,
1427+ ) -> impl fmt:: Display + ' a + Captures < ' tcx > {
1428+ use std:: fmt:: Write as _;
1429+
1430+ let to_print: Cow < ' static , str > = match visibility {
1431+ None => "" . into ( ) ,
1432+ Some ( ty:: Visibility :: Public ) => "pub " . into ( ) ,
1433+ Some ( ty:: Visibility :: Restricted ( vis_did) ) => {
1434+ // FIXME(camelid): This may not work correctly if `item_did` is a module.
1435+ // However, rustdoc currently never displays a module's
1436+ // visibility, so it shouldn't matter.
1437+ let parent_module = find_nearest_parent_module ( cx. tcx ( ) , item_did. expect_def_id ( ) ) ;
1438+
1439+ if vis_did. is_crate_root ( ) {
1440+ "pub(crate) " . into ( )
1441+ } else if parent_module == Some ( vis_did) {
1442+ // `pub(in foo)` where `foo` is the parent module
1443+ // is the same as no visibility modifier
1444+ "" . into ( )
1445+ } else if parent_module. and_then ( |parent| find_nearest_parent_module ( cx. tcx ( ) , parent) )
1446+ == Some ( vis_did)
1447+ {
1448+ "pub(super) " . into ( )
1449+ } else {
1450+ let path = cx. tcx ( ) . def_path ( vis_did) ;
1451+ debug ! ( "path={:?}" , path) ;
1452+ // modified from `resolved_path()` to work with `DefPathData`
1453+ let last_name = path. data . last ( ) . unwrap ( ) . data . get_opt_name ( ) . unwrap ( ) ;
1454+ let anchor = anchor ( vis_did, last_name, cx) . to_string ( ) ;
1455+
1456+ let mut s = "pub(in " . to_owned ( ) ;
1457+ for seg in & path. data [ ..path. data . len ( ) - 1 ] {
1458+ let _ = write ! ( s, "{}::" , seg. data. get_opt_name( ) . unwrap( ) ) ;
14641459 }
1460+ let _ = write ! ( s, "{}) " , anchor) ;
1461+ s. into ( )
14651462 }
1466- } ;
1467- display_fn ( move |f| write ! ( f, "{}" , to_print) )
1468- }
1463+ }
1464+ } ;
1465+ display_fn ( move |f| write ! ( f, "{}" , to_print) )
1466+ }
14691467
1470- /// This function is the same as print_with_space, except that it renders no links.
1471- /// It's used for macros' rendered source view, which is syntax highlighted and cannot have
1472- /// any HTML in it.
1473- pub ( crate ) fn to_src_with_space < ' a , ' tcx : ' a > (
1474- self ,
1475- tcx : TyCtxt < ' tcx > ,
1476- item_did : DefId ,
1477- ) -> impl fmt:: Display + ' a + Captures < ' tcx > {
1478- let to_print = match self {
1479- clean:: Public => "pub " . to_owned ( ) ,
1480- clean:: Inherited => String :: new ( ) ,
1481- clean:: Visibility :: Restricted ( vis_did) => {
1482- // FIXME(camelid): This may not work correctly if `item_did` is a module.
1483- // However, rustdoc currently never displays a module's
1484- // visibility, so it shouldn't matter.
1485- let parent_module = find_nearest_parent_module ( tcx, item_did) ;
1486-
1487- if vis_did. is_crate_root ( ) {
1488- "pub(crate) " . to_owned ( )
1489- } else if parent_module == Some ( vis_did) {
1490- // `pub(in foo)` where `foo` is the parent module
1491- // is the same as no visibility modifier
1492- String :: new ( )
1493- } else if parent_module. and_then ( |parent| find_nearest_parent_module ( tcx, parent) )
1494- == Some ( vis_did)
1495- {
1496- "pub(super) " . to_owned ( )
1497- } else {
1498- format ! ( "pub(in {}) " , tcx. def_path_str( vis_did) )
1499- }
1468+ /// This function is the same as print_with_space, except that it renders no links.
1469+ /// It's used for macros' rendered source view, which is syntax highlighted and cannot have
1470+ /// any HTML in it.
1471+ pub ( crate ) fn visibility_to_src_with_space < ' a , ' tcx : ' a > (
1472+ visibility : Option < ty:: Visibility < DefId > > ,
1473+ tcx : TyCtxt < ' tcx > ,
1474+ item_did : DefId ,
1475+ ) -> impl fmt:: Display + ' a + Captures < ' tcx > {
1476+ let to_print = match visibility {
1477+ None => String :: new ( ) ,
1478+ Some ( ty:: Visibility :: Public ) => "pub " . to_owned ( ) ,
1479+ Some ( ty:: Visibility :: Restricted ( vis_did) ) => {
1480+ // FIXME(camelid): This may not work correctly if `item_did` is a module.
1481+ // However, rustdoc currently never displays a module's
1482+ // visibility, so it shouldn't matter.
1483+ let parent_module = find_nearest_parent_module ( tcx, item_did) ;
1484+
1485+ if vis_did. is_crate_root ( ) {
1486+ "pub(crate) " . to_owned ( )
1487+ } else if parent_module == Some ( vis_did) {
1488+ // `pub(in foo)` where `foo` is the parent module
1489+ // is the same as no visibility modifier
1490+ String :: new ( )
1491+ } else if parent_module. and_then ( |parent| find_nearest_parent_module ( tcx, parent) )
1492+ == Some ( vis_did)
1493+ {
1494+ "pub(super) " . to_owned ( )
1495+ } else {
1496+ format ! ( "pub(in {}) " , tcx. def_path_str( vis_did) )
15001497 }
1501- } ;
1502- display_fn ( move |f| f . write_str ( & to_print ) )
1503- }
1498+ }
1499+ } ;
1500+ display_fn ( move |f| f . write_str ( & to_print ) )
15041501}
15051502
15061503pub ( crate ) trait PrintWithSpace {
0 commit comments