Rollup merge of #117625 - nnethercote:clippy-perf, r=cuviper
Fix some clippy perf lints `@matthiaskrgr` gave me the output of a clippy run with perf lints enabled. This PR fixes ones that I thought were worth fixing. r? `@cuviper`
This commit is contained in:
commit
7552dd19ad
@ -2362,11 +2362,7 @@ fn add_annotation_to_file(
|
|||||||
|
|
||||||
let label = label.as_ref().map(|m| {
|
let label = label.as_ref().map(|m| {
|
||||||
normalize_whitespace(
|
normalize_whitespace(
|
||||||
&emitter
|
&emitter.translate_message(m, &args).map_err(Report::new).unwrap(),
|
||||||
.translate_message(m, &args)
|
|
||||||
.map_err(Report::new)
|
|
||||||
.unwrap()
|
|
||||||
.to_string(),
|
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -274,7 +274,7 @@ pub fn suggest_constraining_type_params<'a>(
|
|||||||
span,
|
span,
|
||||||
if span_to_replace.is_some() {
|
if span_to_replace.is_some() {
|
||||||
constraint.clone()
|
constraint.clone()
|
||||||
} else if constraint.starts_with("<") {
|
} else if constraint.starts_with('<') {
|
||||||
constraint.to_string()
|
constraint.to_string()
|
||||||
} else if bound_list_non_empty {
|
} else if bound_list_non_empty {
|
||||||
format!(" + {constraint}")
|
format!(" + {constraint}")
|
||||||
|
@ -1545,7 +1545,7 @@ pub(crate) fn add_typo_suggestion(
|
|||||||
let (span, sugg, post) = if let SuggestionTarget::SimilarlyNamed = suggestion.target
|
let (span, sugg, post) = if let SuggestionTarget::SimilarlyNamed = suggestion.target
|
||||||
&& let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(span)
|
&& let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(span)
|
||||||
&& let Some(span) = suggestion.span
|
&& let Some(span) = suggestion.span
|
||||||
&& let Some(candidate) = suggestion.candidate.as_str().strip_prefix("_")
|
&& let Some(candidate) = suggestion.candidate.as_str().strip_prefix('_')
|
||||||
&& snippet == candidate
|
&& snippet == candidate
|
||||||
{
|
{
|
||||||
// When the suggested binding change would be from `x` to `_x`, suggest changing the
|
// When the suggested binding change would be from `x` to `_x`, suggest changing the
|
||||||
|
@ -2477,7 +2477,7 @@ pub fn parse_externs(
|
|||||||
let mut error = handler.early_struct_error(format!(
|
let mut error = handler.early_struct_error(format!(
|
||||||
"crate name `{name}` passed to `--extern` is not a valid ASCII identifier"
|
"crate name `{name}` passed to `--extern` is not a valid ASCII identifier"
|
||||||
));
|
));
|
||||||
let adjusted_name = name.replace("-", "_");
|
let adjusted_name = name.replace('-', "_");
|
||||||
if crate::utils::is_ascii_ident(&adjusted_name) {
|
if crate::utils::is_ascii_ident(&adjusted_name) {
|
||||||
error.help(format!(
|
error.help(format!(
|
||||||
"consider replacing the dashes with underscores: `{adjusted_name}`"
|
"consider replacing the dashes with underscores: `{adjusted_name}`"
|
||||||
|
@ -599,7 +599,7 @@ fn build_module_items(
|
|||||||
let prim_ty = clean::PrimitiveType::from(p);
|
let prim_ty = clean::PrimitiveType::from(p);
|
||||||
items.push(clean::Item {
|
items.push(clean::Item {
|
||||||
name: None,
|
name: None,
|
||||||
attrs: Box::new(clean::Attributes::default()),
|
attrs: Box::default(),
|
||||||
// We can use the item's `DefId` directly since the only information ever used
|
// We can use the item's `DefId` directly since the only information ever used
|
||||||
// from it is `DefId.krate`.
|
// from it is `DefId.krate`.
|
||||||
item_id: ItemId::DefId(did),
|
item_id: ItemId::DefId(did),
|
||||||
|
@ -1327,6 +1327,7 @@ pub(crate) fn get_bounds(&self) -> Option<&[GenericBound]> {
|
|||||||
pub(crate) enum GenericParamDefKind {
|
pub(crate) enum GenericParamDefKind {
|
||||||
Lifetime { outlives: ThinVec<Lifetime> },
|
Lifetime { outlives: ThinVec<Lifetime> },
|
||||||
Type { did: DefId, bounds: ThinVec<GenericBound>, default: Option<Box<Type>>, synthetic: bool },
|
Type { did: DefId, bounds: ThinVec<GenericBound>, default: Option<Box<Type>>, synthetic: bool },
|
||||||
|
// Option<Box<String>> makes this type smaller than `Option<String>` would.
|
||||||
Const { ty: Box<Type>, default: Option<Box<String>>, is_host_effect: bool },
|
Const { ty: Box<Type>, default: Option<Box<String>>, is_host_effect: bool },
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -588,7 +588,7 @@ pub(crate) fn has_doc_flag(tcx: TyCtxt<'_>, did: DefId, flag: Symbol) -> bool {
|
|||||||
/// Set by `bootstrap::Builder::doc_rust_lang_org_channel` in order to keep tests passing on beta/stable.
|
/// Set by `bootstrap::Builder::doc_rust_lang_org_channel` in order to keep tests passing on beta/stable.
|
||||||
pub(crate) const DOC_RUST_LANG_ORG_CHANNEL: &str = env!("DOC_RUST_LANG_ORG_CHANNEL");
|
pub(crate) const DOC_RUST_LANG_ORG_CHANNEL: &str = env!("DOC_RUST_LANG_ORG_CHANNEL");
|
||||||
pub(crate) static DOC_CHANNEL: Lazy<&'static str> =
|
pub(crate) static DOC_CHANNEL: Lazy<&'static str> =
|
||||||
Lazy::new(|| DOC_RUST_LANG_ORG_CHANNEL.rsplit("/").filter(|c| !c.is_empty()).next().unwrap());
|
Lazy::new(|| DOC_RUST_LANG_ORG_CHANNEL.rsplit('/').filter(|c| !c.is_empty()).next().unwrap());
|
||||||
|
|
||||||
/// Render a sequence of macro arms in a format suitable for displaying to the user
|
/// Render a sequence of macro arms in a format suitable for displaying to the user
|
||||||
/// as part of an item declaration.
|
/// as part of an item declaration.
|
||||||
|
@ -356,15 +356,12 @@ fn add_path(self: &Rc<Self>, path: &Path) {
|
|||||||
|
|
||||||
let content = format!(
|
let content = format!(
|
||||||
"<h1>List of all crates</h1><ul class=\"all-items\">{}</ul>",
|
"<h1>List of all crates</h1><ul class=\"all-items\">{}</ul>",
|
||||||
krates
|
krates.iter().format_with("", |k, f| {
|
||||||
.iter()
|
f(&format_args!(
|
||||||
.map(|s| {
|
"<li><a href=\"{trailing_slash}index.html\">{k}</a></li>",
|
||||||
format!(
|
trailing_slash = ensure_trailing_slash(k),
|
||||||
"<li><a href=\"{trailing_slash}index.html\">{s}</a></li>",
|
))
|
||||||
trailing_slash = ensure_trailing_slash(s),
|
})
|
||||||
)
|
|
||||||
})
|
|
||||||
.collect::<String>()
|
|
||||||
);
|
);
|
||||||
let v = layout::render(&shared.layout, &page, "", content, &shared.style_files);
|
let v = layout::render(&shared.layout, &page, "", content, &shared.style_files);
|
||||||
shared.fs.write(dst, v)?;
|
shared.fs.write(dst, v)?;
|
||||||
|
@ -87,7 +87,7 @@ fn check_redundant_explicit_link<'md>(
|
|||||||
let link_data = collect_link_data(&mut offset_iter);
|
let link_data = collect_link_data(&mut offset_iter);
|
||||||
|
|
||||||
if let Some(resolvable_link) = link_data.resolvable_link.as_ref() {
|
if let Some(resolvable_link) = link_data.resolvable_link.as_ref() {
|
||||||
if &link_data.display_link.replace("`", "") != resolvable_link {
|
if &link_data.display_link.replace('`', "") != resolvable_link {
|
||||||
// Skips if display link does not match to actual
|
// Skips if display link does not match to actual
|
||||||
// resolvable link, usually happens if display link
|
// resolvable link, usually happens if display link
|
||||||
// has several segments, e.g.
|
// has several segments, e.g.
|
||||||
|
Loading…
Reference in New Issue
Block a user