Skip to content

Commit d49b1ab

Browse files
authored
Rollup merge of rust-lang#115001 - matthiaskrgr:perf_clippy, r=cjgillot
clippy::perf stuff
2 parents bb3cf24 + 4cd3b0b commit d49b1ab

File tree

3 files changed

+18
-16
lines changed

3 files changed

+18
-16
lines changed

compiler/rustc_hir_typeck/src/method/prelude2021.rs

+11-10
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use rustc_span::symbol::kw::{Empty, Underscore};
1414
use rustc_span::symbol::{sym, Ident};
1515
use rustc_span::Span;
1616
use rustc_trait_selection::infer::InferCtxtExt;
17+
use std::fmt::Write;
1718

1819
impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1920
pub(super) fn lint_dot_call_from_2018(
@@ -143,16 +144,16 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
143144

144145
let (self_adjusted, precise) = self.adjust_expr(pick, self_expr, sp);
145146
if precise {
146-
let args = args
147-
.iter()
148-
.map(|arg| {
149-
let span = arg.span.find_ancestor_inside(sp).unwrap_or_default();
150-
format!(
151-
", {}",
152-
self.sess().source_map().span_to_snippet(span).unwrap()
153-
)
154-
})
155-
.collect::<String>();
147+
let args = args.iter().fold(String::new(), |mut string, arg| {
148+
let span = arg.span.find_ancestor_inside(sp).unwrap_or_default();
149+
write!(
150+
string,
151+
", {}",
152+
self.sess().source_map().span_to_snippet(span).unwrap()
153+
)
154+
.unwrap();
155+
string
156+
});
156157

157158
lint.span_suggestion(
158159
sp,

compiler/rustc_middle/src/ty/diagnostics.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! Diagnostics related methods for `Ty`.
22
33
use std::borrow::Cow;
4+
use std::fmt::Write;
45
use std::ops::ControlFlow;
56

67
use crate::ty::{
@@ -335,10 +336,10 @@ pub fn suggest_constraining_type_params<'a>(
335336
// - insert: `, X: Bar`
336337
suggestions.push((
337338
generics.tail_span_for_predicate_suggestion(),
338-
constraints
339-
.iter()
340-
.map(|&(constraint, _)| format!(", {param_name}: {constraint}"))
341-
.collect::<String>(),
339+
constraints.iter().fold(String::new(), |mut string, &(constraint, _)| {
340+
write!(string, ", {param_name}: {constraint}").unwrap();
341+
string
342+
}),
342343
SuggestChangingConstraintsMessage::RestrictTypeFurther { ty: param_name },
343344
));
344345
continue;

compiler/rustc_mir_transform/src/coverage/debug.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,9 @@ impl DebugOptions {
199199

200200
fn bool_option_val(option: &str, some_strval: Option<&str>) -> bool {
201201
if let Some(val) = some_strval {
202-
if vec!["yes", "y", "on", "true"].contains(&val) {
202+
if ["yes", "y", "on", "true"].contains(&val) {
203203
true
204-
} else if vec!["no", "n", "off", "false"].contains(&val) {
204+
} else if ["no", "n", "off", "false"].contains(&val) {
205205
false
206206
} else {
207207
bug!(

0 commit comments

Comments
 (0)