1
Fork 0

fix clippy perf lints

This commit is contained in:
klensy 2022-05-24 13:35:54 -04:00
parent 678059f7d0
commit 2a326bcc74
4 changed files with 23 additions and 15 deletions

View file

@ -5,6 +5,7 @@
//! assume that HTML output is desired, although it may be possible to redesign
//! them in the future to instead emit any format desired.
use std::borrow::Cow;
use std::cell::Cell;
use std::fmt;
use std::iter;
@ -1295,9 +1296,11 @@ impl clean::Visibility {
item_did: ItemId,
cx: &'a Context<'tcx>,
) -> impl fmt::Display + 'a + Captures<'tcx> {
let to_print = match self {
clean::Public => "pub ".to_owned(),
clean::Inherited => String::new(),
use std::fmt::Write as _;
let to_print: Cow<'static, str> = match self {
clean::Public => "pub ".into(),
clean::Inherited => "".into(),
clean::Visibility::Restricted(vis_did) => {
// FIXME(camelid): This may not work correctly if `item_did` is a module.
// However, rustdoc currently never displays a module's
@ -1305,16 +1308,16 @@ impl clean::Visibility {
let parent_module = find_nearest_parent_module(cx.tcx(), item_did.expect_def_id());
if vis_did.is_crate_root() {
"pub(crate) ".to_owned()
"pub(crate) ".into()
} else if parent_module == Some(vis_did) {
// `pub(in foo)` where `foo` is the parent module
// is the same as no visibility modifier
String::new()
"".into()
} else if parent_module
.and_then(|parent| find_nearest_parent_module(cx.tcx(), parent))
== Some(vis_did)
{
"pub(super) ".to_owned()
"pub(super) ".into()
} else {
let path = cx.tcx().def_path(vis_did);
debug!("path={:?}", path);
@ -1324,14 +1327,14 @@ impl clean::Visibility {
let mut s = "pub(in ".to_owned();
for seg in &path.data[..path.data.len() - 1] {
s.push_str(&format!("{}::", seg.data.get_opt_name().unwrap()));
let _ = write!(s, "{}::", seg.data.get_opt_name().unwrap());
}
s.push_str(&format!("{}) ", anchor));
s
let _ = write!(s, "{}) ", anchor);
s.into()
}
}
};
display_fn(move |f| f.write_str(&to_print))
display_fn(move |f| write!(f, "{}", to_print))
}
/// This function is the same as print_with_space, except that it renders no links.