Skip to content

Commit b594798

Browse files
committed
fix clippy::useless_format
1 parent adf759b commit b594798

File tree

6 files changed

+12
-16
lines changed

6 files changed

+12
-16
lines changed

compiler/rustc_hir_analysis/src/coherence/orphan.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ fn emit_orphan_check_error<'tcx>(
352352

353353
let this = |name: &str| {
354354
if !trait_ref.def_id.is_local() && !is_target_ty {
355-
msg("this", &format!(" because this is a foreign trait"))
355+
msg("this", " because this is a foreign trait")
356356
} else {
357357
msg("this", &format!(" because {name} are always foreign"))
358358
}

compiler/rustc_hir_typeck/src/cast.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -705,10 +705,10 @@ impl<'a, 'tcx> CastCheck<'tcx> {
705705
)
706706
}),
707707
|lint| {
708-
lint.help(format!(
708+
lint.help(
709709
"cast can be replaced by coercion; this might \
710-
require a temporary variable"
711-
))
710+
require a temporary variable",
711+
)
712712
},
713713
);
714714
}

compiler/rustc_infer/src/infer/error_reporting/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -264,11 +264,11 @@ fn msg_span_from_named_region<'tcx>(
264264
ty::RePlaceholder(ty::PlaceholderRegion {
265265
bound: ty::BoundRegion { kind: ty::BoundRegionKind::BrAnon(Some(span)), .. },
266266
..
267-
}) => (format!("the anonymous lifetime defined here"), Some(span)),
267+
}) => ("the anonymous lifetime defined here".to_owned(), Some(span)),
268268
ty::RePlaceholder(ty::PlaceholderRegion {
269269
bound: ty::BoundRegion { kind: ty::BoundRegionKind::BrAnon(None), .. },
270270
..
271-
}) => (format!("an anonymous lifetime"), None),
271+
}) => ("an anonymous lifetime".to_owned(), None),
272272
_ => bug!("{:?}", region),
273273
}
274274
}
@@ -2354,7 +2354,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
23542354
if let Ok(snip) = self.tcx.sess.source_map().span_to_next_source(p.span)
23552355
&& snip.starts_with(' ')
23562356
{
2357-
format!("{new_lt}")
2357+
new_lt.to_string()
23582358
} else {
23592359
format!("{new_lt} ")
23602360
}

compiler/rustc_infer/src/infer/error_reporting/nice_region_error/static_impl_trait.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -333,11 +333,7 @@ pub fn suggest_new_region_bound(
333333
} else {
334334
None
335335
};
336-
let name = if let Some(name) = &existing_lt_name {
337-
format!("{}", name)
338-
} else {
339-
format!("'a")
340-
};
336+
let name = if let Some(name) = &existing_lt_name { name } else { "'a" };
341337
// if there are more than one elided lifetimes in inputs, the explicit `'_` lifetime cannot be used.
342338
// introducing a new lifetime `'a` or making use of one from existing named lifetimes if any
343339
if let Some(id) = scope_def_id
@@ -350,7 +346,7 @@ pub fn suggest_new_region_bound(
350346
if p.span.hi() - p.span.lo() == rustc_span::BytePos(1) { // Ampersand (elided without '_)
351347
(p.span.shrink_to_hi(),format!("{name} "))
352348
} else { // Underscore (elided with '_)
353-
(p.span, format!("{name}"))
349+
(p.span, name.to_string())
354350
}
355351
)
356352
.collect::<Vec<_>>()

compiler/rustc_resolve/src/diagnostics.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1395,7 +1395,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
13951395
let head_span = source_map.guess_head_span(span);
13961396
err.subdiagnostic(ConsiderAddingADerive {
13971397
span: head_span.shrink_to_lo(),
1398-
suggestion: format!("#[derive(Default)]\n")
1398+
suggestion: "#[derive(Default)]\n".to_string(),
13991399
});
14001400
}
14011401
for ns in [Namespace::MacroNS, Namespace::TypeNS, Namespace::ValueNS] {
@@ -1718,7 +1718,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
17181718
if next_binding.is_none() && let Some(span) = non_exhaustive {
17191719
note_span.push_span_label(
17201720
span,
1721-
format!("cannot be constructed because it is `#[non_exhaustive]`"),
1721+
"cannot be constructed because it is `#[non_exhaustive]`",
17221722
);
17231723
}
17241724
err.span_note(note_span, msg);

compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1471,7 +1471,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
14711471

14721472
let span = if needs_parens { span } else { span.shrink_to_lo() };
14731473
let suggestions = if !needs_parens {
1474-
vec![(span.shrink_to_lo(), format!("{}", sugg_prefix))]
1474+
vec![(span.shrink_to_lo(), sugg_prefix)]
14751475
} else {
14761476
vec![
14771477
(span.shrink_to_lo(), format!("{}(", sugg_prefix)),

0 commit comments

Comments
 (0)