Skip to content

Commit c474aa7

Browse files
committed
Auto merge of #113975 - matthiaskrgr:clippy_07_2023, r=fee1-dead
clippy::style fixes r? `@oli-obk` filter_map_identity iter_kv_map needless_question_mark redundant_at_rest_pattern filter_next derivable_impls useless_format
2 parents d4fe4c8 + b594798 commit c474aa7

File tree

12 files changed

+20
-32
lines changed

12 files changed

+20
-32
lines changed

compiler/rustc_builtin_macros/src/asm.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ fn parse_clobber_abi<'a>(p: &mut Parser<'a>, args: &mut AsmArgs) -> PResult<'a,
401401
// should have errored above during parsing
402402
[] => unreachable!(),
403403
[(abi, _span)] => args.clobber_abis.push((*abi, full_span)),
404-
[abis @ ..] => {
404+
abis => {
405405
for (abi, span) in abis {
406406
args.clobber_abis.push((*abi, *span));
407407
}

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_parse/src/parser/generics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ impl<'a> Parser<'a> {
4949
&& self.check_ident()
5050
// `Const` followed by IDENT
5151
{
52-
return Ok(self.recover_const_param_with_mistyped_const(preceding_attrs, ident)?);
52+
return self.recover_const_param_with_mistyped_const(preceding_attrs, ident);
5353
}
5454

5555
// Parse optional colon and param bounds.

compiler/rustc_query_impl/src/plumbing.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ pub(super) fn encode_all_query_results<'tcx>(
183183
encoder: &mut CacheEncoder<'_, 'tcx>,
184184
query_result_index: &mut EncodedDepNodeIndex,
185185
) {
186-
for encode in super::ENCODE_QUERY_RESULTS.iter().copied().filter_map(|e| e) {
186+
for encode in super::ENCODE_QUERY_RESULTS.iter().copied().flatten() {
187187
encode(tcx, encoder, query_result_index);
188188
}
189189
}

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_session/src/code_stats.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -227,10 +227,8 @@ impl CodeStats {
227227
}
228228

229229
pub fn print_vtable_sizes(&self, crate_name: &str) {
230-
let mut infos = std::mem::take(&mut *self.vtable_sizes.lock())
231-
.into_iter()
232-
.map(|(_did, stats)| stats)
233-
.collect::<Vec<_>>();
230+
let mut infos =
231+
std::mem::take(&mut *self.vtable_sizes.lock()).into_values().collect::<Vec<_>>();
234232

235233
// Primary sort: cost % in reverse order (from largest to smallest)
236234
// Secondary sort: trait_name

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

+2-7
Original file line numberDiff line numberDiff line change
@@ -329,18 +329,13 @@ pub struct OnUnimplementedNote {
329329
}
330330

331331
/// Append a message for `~const Trait` errors.
332-
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
332+
#[derive(Clone, Copy, PartialEq, Eq, Debug, Default)]
333333
pub enum AppendConstMessage {
334+
#[default]
334335
Default,
335336
Custom(Symbol),
336337
}
337338

338-
impl Default for AppendConstMessage {
339-
fn default() -> Self {
340-
AppendConstMessage::Default
341-
}
342-
}
343-
344339
impl<'tcx> OnUnimplementedDirective {
345340
fn parse(
346341
tcx: TyCtxt<'tcx>,

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)),

library/test/src/lib.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,7 @@ pub fn test_main_static_abort(tests: &[&TestDescAndFn]) {
183183

184184
let test = tests
185185
.into_iter()
186-
.filter(|test| test.desc.name.as_slice() == name)
187-
.next()
186+
.find(|test| test.desc.name.as_slice() == name)
188187
.unwrap_or_else(|| panic!("couldn't find a test with the provided name '{name}'"));
189188
let TestDescAndFn { desc, testfn } = test;
190189
match testfn.into_runnable() {

0 commit comments

Comments
 (0)