Rollup merge of #115001 - matthiaskrgr:perf_clippy, r=cjgillot

clippy::perf stuff
This commit is contained in:
Matthias Krüger 2023-08-20 00:28:34 +02:00 committed by GitHub
commit d49b1aba80
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 16 deletions

View file

@ -14,6 +14,7 @@ use rustc_span::symbol::kw::{Empty, Underscore};
use rustc_span::symbol::{sym, Ident}; use rustc_span::symbol::{sym, Ident};
use rustc_span::Span; use rustc_span::Span;
use rustc_trait_selection::infer::InferCtxtExt; use rustc_trait_selection::infer::InferCtxtExt;
use std::fmt::Write;
impl<'a, 'tcx> FnCtxt<'a, 'tcx> { impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
pub(super) fn lint_dot_call_from_2018( pub(super) fn lint_dot_call_from_2018(
@ -143,16 +144,16 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let (self_adjusted, precise) = self.adjust_expr(pick, self_expr, sp); let (self_adjusted, precise) = self.adjust_expr(pick, self_expr, sp);
if precise { if precise {
let args = args let args = args.iter().fold(String::new(), |mut string, arg| {
.iter()
.map(|arg| {
let span = arg.span.find_ancestor_inside(sp).unwrap_or_default(); let span = arg.span.find_ancestor_inside(sp).unwrap_or_default();
format!( write!(
string,
", {}", ", {}",
self.sess().source_map().span_to_snippet(span).unwrap() self.sess().source_map().span_to_snippet(span).unwrap()
) )
}) .unwrap();
.collect::<String>(); string
});
lint.span_suggestion( lint.span_suggestion(
sp, sp,

View file

@ -1,6 +1,7 @@
//! Diagnostics related methods for `Ty`. //! Diagnostics related methods for `Ty`.
use std::borrow::Cow; use std::borrow::Cow;
use std::fmt::Write;
use std::ops::ControlFlow; use std::ops::ControlFlow;
use crate::ty::{ use crate::ty::{
@ -335,10 +336,10 @@ pub fn suggest_constraining_type_params<'a>(
// - insert: `, X: Bar` // - insert: `, X: Bar`
suggestions.push(( suggestions.push((
generics.tail_span_for_predicate_suggestion(), generics.tail_span_for_predicate_suggestion(),
constraints constraints.iter().fold(String::new(), |mut string, &(constraint, _)| {
.iter() write!(string, ", {param_name}: {constraint}").unwrap();
.map(|&(constraint, _)| format!(", {param_name}: {constraint}")) string
.collect::<String>(), }),
SuggestChangingConstraintsMessage::RestrictTypeFurther { ty: param_name }, SuggestChangingConstraintsMessage::RestrictTypeFurther { ty: param_name },
)); ));
continue; continue;

View file

@ -199,9 +199,9 @@ impl DebugOptions {
fn bool_option_val(option: &str, some_strval: Option<&str>) -> bool { fn bool_option_val(option: &str, some_strval: Option<&str>) -> bool {
if let Some(val) = some_strval { if let Some(val) = some_strval {
if vec!["yes", "y", "on", "true"].contains(&val) { if ["yes", "y", "on", "true"].contains(&val) {
true true
} else if vec!["no", "n", "off", "false"].contains(&val) { } else if ["no", "n", "off", "false"].contains(&val) {
false false
} else { } else {
bug!( bug!(