Skip to content

Commit e81a072

Browse files
authored
Rollup merge of rust-lang#109283 - notriddle:notriddle/visibility-to-src-with-space, r=jsha
rustdoc: reduce allocations in `visibility_to_src_with_space`
2 parents 8417c93 + 8628e27 commit e81a072

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/librustdoc/html/format.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -1502,27 +1502,27 @@ pub(crate) fn visibility_to_src_with_space<'a, 'tcx: 'a>(
15021502
tcx: TyCtxt<'tcx>,
15031503
item_did: DefId,
15041504
) -> impl fmt::Display + 'a + Captures<'tcx> {
1505-
let to_print = match visibility {
1506-
None => String::new(),
1507-
Some(ty::Visibility::Public) => "pub ".to_owned(),
1505+
let to_print: Cow<'static, str> = match visibility {
1506+
None => "".into(),
1507+
Some(ty::Visibility::Public) => "pub ".into(),
15081508
Some(ty::Visibility::Restricted(vis_did)) => {
15091509
// FIXME(camelid): This may not work correctly if `item_did` is a module.
15101510
// However, rustdoc currently never displays a module's
15111511
// visibility, so it shouldn't matter.
15121512
let parent_module = find_nearest_parent_module(tcx, item_did);
15131513

15141514
if vis_did.is_crate_root() {
1515-
"pub(crate) ".to_owned()
1515+
"pub(crate) ".into()
15161516
} else if parent_module == Some(vis_did) {
15171517
// `pub(in foo)` where `foo` is the parent module
15181518
// is the same as no visibility modifier
1519-
String::new()
1519+
"".into()
15201520
} else if parent_module.and_then(|parent| find_nearest_parent_module(tcx, parent))
15211521
== Some(vis_did)
15221522
{
1523-
"pub(super) ".to_owned()
1523+
"pub(super) ".into()
15241524
} else {
1525-
format!("pub(in {}) ", tcx.def_path_str(vis_did))
1525+
format!("pub(in {}) ", tcx.def_path_str(vis_did)).into()
15261526
}
15271527
}
15281528
};

0 commit comments

Comments
 (0)