instead of collecting newly formatted Strings into one String, only create a single String and write!() to it (clippy::format_collect)
This commit is contained in:
parent
d06ca0ffaf
commit
76efd398ba
2 changed files with 16 additions and 14 deletions
|
@ -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(
|
||||
|
@ -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 args = args.iter().fold(String::new(), |mut string, arg| {
|
||||
let span = arg.span.find_ancestor_inside(sp).unwrap_or_default();
|
||||
format!(
|
||||
write!(
|
||||
string,
|
||||
", {}",
|
||||
self.sess().source_map().span_to_snippet(span).unwrap()
|
||||
)
|
||||
})
|
||||
.collect::<String>();
|
||||
.unwrap();
|
||||
string
|
||||
});
|
||||
|
||||
lint.span_suggestion(
|
||||
sp,
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
//! Diagnostics related methods for `Ty`.
|
||||
|
||||
use std::borrow::Cow;
|
||||
use std::fmt::Write;
|
||||
use std::ops::ControlFlow;
|
||||
|
||||
use crate::ty::{
|
||||
|
@ -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;
|
||||
|
|
Loading…
Add table
Reference in a new issue