Skip to content

Commit

Permalink
Rollup merge of rust-lang#115001 - matthiaskrgr:perf_clippy, r=cjgillot
Browse files Browse the repository at this point in the history
clippy::perf stuff
  • Loading branch information
matthiaskrgr committed Aug 19, 2023
2 parents bb3cf24 + 4cd3b0b commit d49b1ab
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 16 deletions.
21 changes: 11 additions & 10 deletions compiler/rustc_hir_typeck/src/method/prelude2021.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use rustc_span::symbol::kw::{Empty, Underscore};
use rustc_span::symbol::{sym, Ident};
use rustc_span::Span;
use rustc_trait_selection::infer::InferCtxtExt;
use std::fmt::Write;

impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
pub(super) fn lint_dot_call_from_2018(
Expand Down Expand Up @@ -143,16 +144,16 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {

let (self_adjusted, precise) = self.adjust_expr(pick, self_expr, sp);
if precise {
let args = args
.iter()
.map(|arg| {
let span = arg.span.find_ancestor_inside(sp).unwrap_or_default();
format!(
", {}",
self.sess().source_map().span_to_snippet(span).unwrap()
)
})
.collect::<String>();
let args = args.iter().fold(String::new(), |mut string, arg| {
let span = arg.span.find_ancestor_inside(sp).unwrap_or_default();
write!(
string,
", {}",
self.sess().source_map().span_to_snippet(span).unwrap()
)
.unwrap();
string
});

lint.span_suggestion(
sp,
Expand Down
9 changes: 5 additions & 4 deletions compiler/rustc_middle/src/ty/diagnostics.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Diagnostics related methods for `Ty`.

use std::borrow::Cow;
use std::fmt::Write;
use std::ops::ControlFlow;

use crate::ty::{
Expand Down Expand Up @@ -335,10 +336,10 @@ pub fn suggest_constraining_type_params<'a>(
// - insert: `, X: Bar`
suggestions.push((
generics.tail_span_for_predicate_suggestion(),
constraints
.iter()
.map(|&(constraint, _)| format!(", {param_name}: {constraint}"))
.collect::<String>(),
constraints.iter().fold(String::new(), |mut string, &(constraint, _)| {
write!(string, ", {param_name}: {constraint}").unwrap();
string
}),
SuggestChangingConstraintsMessage::RestrictTypeFurther { ty: param_name },
));
continue;
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_mir_transform/src/coverage/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,9 @@ impl DebugOptions {

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

0 comments on commit d49b1ab

Please sign in to comment.