55//! assume that HTML output is desired, although it may be possible to redesign
66//! them in the future to instead emit any format desired.
77
8+ use std:: borrow:: Cow ;
89use std:: cell:: Cell ;
910use std:: fmt;
1011use std:: iter;
@@ -1295,26 +1296,28 @@ impl clean::Visibility {
12951296 item_did : ItemId ,
12961297 cx : & ' a Context < ' tcx > ,
12971298 ) -> impl fmt:: Display + ' a + Captures < ' tcx > {
1298- let to_print = match self {
1299- clean:: Public => "pub " . to_owned ( ) ,
1300- clean:: Inherited => String :: new ( ) ,
1299+ use std:: fmt:: Write as _;
1300+
1301+ let to_print: Cow < ' static , str > = match self {
1302+ clean:: Public => "pub " . into ( ) ,
1303+ clean:: Inherited => "" . into ( ) ,
13011304 clean:: Visibility :: Restricted ( vis_did) => {
13021305 // FIXME(camelid): This may not work correctly if `item_did` is a module.
13031306 // However, rustdoc currently never displays a module's
13041307 // visibility, so it shouldn't matter.
13051308 let parent_module = find_nearest_parent_module ( cx. tcx ( ) , item_did. expect_def_id ( ) ) ;
13061309
13071310 if vis_did. is_crate_root ( ) {
1308- "pub(crate) " . to_owned ( )
1311+ "pub(crate) " . into ( )
13091312 } else if parent_module == Some ( vis_did) {
13101313 // `pub(in foo)` where `foo` is the parent module
13111314 // is the same as no visibility modifier
1312- String :: new ( )
1315+ "" . into ( )
13131316 } else if parent_module
13141317 . and_then ( |parent| find_nearest_parent_module ( cx. tcx ( ) , parent) )
13151318 == Some ( vis_did)
13161319 {
1317- "pub(super) " . to_owned ( )
1320+ "pub(super) " . into ( )
13181321 } else {
13191322 let path = cx. tcx ( ) . def_path ( vis_did) ;
13201323 debug ! ( "path={:?}" , path) ;
@@ -1324,14 +1327,14 @@ impl clean::Visibility {
13241327
13251328 let mut s = "pub(in " . to_owned ( ) ;
13261329 for seg in & path. data [ ..path. data . len ( ) - 1 ] {
1327- s . push_str ( & format ! ( "{}::" , seg. data. get_opt_name( ) . unwrap( ) ) ) ;
1330+ let _ = write ! ( s , "{}::" , seg. data. get_opt_name( ) . unwrap( ) ) ;
13281331 }
1329- s . push_str ( & format ! ( "{}) " , anchor) ) ;
1330- s
1332+ let _ = write ! ( s , "{}) " , anchor) ;
1333+ s. into ( )
13311334 }
13321335 }
13331336 } ;
1334- display_fn ( move |f| f . write_str ( & to_print) )
1337+ display_fn ( move |f| write ! ( f , "{}" , to_print) )
13351338 }
13361339
13371340 /// This function is the same as print_with_space, except that it renders no links.
0 commit comments