1
Fork 0

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
This commit is contained in:
bors 2023-07-23 14:09:19 +00:00
commit c474aa7db0
12 changed files with 20 additions and 32 deletions

View file

@ -401,7 +401,7 @@ fn parse_clobber_abi<'a>(p: &mut Parser<'a>, args: &mut AsmArgs) -> PResult<'a,
// should have errored above during parsing // should have errored above during parsing
[] => unreachable!(), [] => unreachable!(),
[(abi, _span)] => args.clobber_abis.push((*abi, full_span)), [(abi, _span)] => args.clobber_abis.push((*abi, full_span)),
[abis @ ..] => { abis => {
for (abi, span) in abis { for (abi, span) in abis {
args.clobber_abis.push((*abi, *span)); args.clobber_abis.push((*abi, *span));
} }

View file

@ -352,7 +352,7 @@ fn emit_orphan_check_error<'tcx>(
let this = |name: &str| { let this = |name: &str| {
if !trait_ref.def_id.is_local() && !is_target_ty { if !trait_ref.def_id.is_local() && !is_target_ty {
msg("this", &format!(" because this is a foreign trait")) msg("this", " because this is a foreign trait")
} else { } else {
msg("this", &format!(" because {name} are always foreign")) msg("this", &format!(" because {name} are always foreign"))
} }

View file

@ -705,10 +705,10 @@ impl<'a, 'tcx> CastCheck<'tcx> {
) )
}), }),
|lint| { |lint| {
lint.help(format!( lint.help(
"cast can be replaced by coercion; this might \ "cast can be replaced by coercion; this might \
require a temporary variable" require a temporary variable",
)) )
}, },
); );
} }

View file

@ -264,11 +264,11 @@ fn msg_span_from_named_region<'tcx>(
ty::RePlaceholder(ty::PlaceholderRegion { ty::RePlaceholder(ty::PlaceholderRegion {
bound: ty::BoundRegion { kind: ty::BoundRegionKind::BrAnon(Some(span)), .. }, bound: ty::BoundRegion { kind: ty::BoundRegionKind::BrAnon(Some(span)), .. },
.. ..
}) => (format!("the anonymous lifetime defined here"), Some(span)), }) => ("the anonymous lifetime defined here".to_owned(), Some(span)),
ty::RePlaceholder(ty::PlaceholderRegion { ty::RePlaceholder(ty::PlaceholderRegion {
bound: ty::BoundRegion { kind: ty::BoundRegionKind::BrAnon(None), .. }, bound: ty::BoundRegion { kind: ty::BoundRegionKind::BrAnon(None), .. },
.. ..
}) => (format!("an anonymous lifetime"), None), }) => ("an anonymous lifetime".to_owned(), None),
_ => bug!("{:?}", region), _ => bug!("{:?}", region),
} }
} }
@ -2354,7 +2354,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
if let Ok(snip) = self.tcx.sess.source_map().span_to_next_source(p.span) if let Ok(snip) = self.tcx.sess.source_map().span_to_next_source(p.span)
&& snip.starts_with(' ') && snip.starts_with(' ')
{ {
format!("{new_lt}") new_lt.to_string()
} else { } else {
format!("{new_lt} ") format!("{new_lt} ")
} }

View file

@ -333,11 +333,7 @@ pub fn suggest_new_region_bound(
} else { } else {
None None
}; };
let name = if let Some(name) = &existing_lt_name { let name = if let Some(name) = &existing_lt_name { name } else { "'a" };
format!("{}", name)
} else {
format!("'a")
};
// if there are more than one elided lifetimes in inputs, the explicit `'_` lifetime cannot be used. // if there are more than one elided lifetimes in inputs, the explicit `'_` lifetime cannot be used.
// introducing a new lifetime `'a` or making use of one from existing named lifetimes if any // introducing a new lifetime `'a` or making use of one from existing named lifetimes if any
if let Some(id) = scope_def_id if let Some(id) = scope_def_id
@ -350,7 +346,7 @@ pub fn suggest_new_region_bound(
if p.span.hi() - p.span.lo() == rustc_span::BytePos(1) { // Ampersand (elided without '_) if p.span.hi() - p.span.lo() == rustc_span::BytePos(1) { // Ampersand (elided without '_)
(p.span.shrink_to_hi(),format!("{name} ")) (p.span.shrink_to_hi(),format!("{name} "))
} else { // Underscore (elided with '_) } else { // Underscore (elided with '_)
(p.span, format!("{name}")) (p.span, name.to_string())
} }
) )
.collect::<Vec<_>>() .collect::<Vec<_>>()

View file

@ -49,7 +49,7 @@ impl<'a> Parser<'a> {
&& self.check_ident() && self.check_ident()
// `Const` followed by IDENT // `Const` followed by IDENT
{ {
return Ok(self.recover_const_param_with_mistyped_const(preceding_attrs, ident)?); return self.recover_const_param_with_mistyped_const(preceding_attrs, ident);
} }
// Parse optional colon and param bounds. // Parse optional colon and param bounds.

View file

@ -183,7 +183,7 @@ pub(super) fn encode_all_query_results<'tcx>(
encoder: &mut CacheEncoder<'_, 'tcx>, encoder: &mut CacheEncoder<'_, 'tcx>,
query_result_index: &mut EncodedDepNodeIndex, query_result_index: &mut EncodedDepNodeIndex,
) { ) {
for encode in super::ENCODE_QUERY_RESULTS.iter().copied().filter_map(|e| e) { for encode in super::ENCODE_QUERY_RESULTS.iter().copied().flatten() {
encode(tcx, encoder, query_result_index); encode(tcx, encoder, query_result_index);
} }
} }

View file

@ -1395,7 +1395,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
let head_span = source_map.guess_head_span(span); let head_span = source_map.guess_head_span(span);
err.subdiagnostic(ConsiderAddingADerive { err.subdiagnostic(ConsiderAddingADerive {
span: head_span.shrink_to_lo(), span: head_span.shrink_to_lo(),
suggestion: format!("#[derive(Default)]\n") suggestion: "#[derive(Default)]\n".to_string(),
}); });
} }
for ns in [Namespace::MacroNS, Namespace::TypeNS, Namespace::ValueNS] { for ns in [Namespace::MacroNS, Namespace::TypeNS, Namespace::ValueNS] {
@ -1718,7 +1718,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
if next_binding.is_none() && let Some(span) = non_exhaustive { if next_binding.is_none() && let Some(span) = non_exhaustive {
note_span.push_span_label( note_span.push_span_label(
span, span,
format!("cannot be constructed because it is `#[non_exhaustive]`"), "cannot be constructed because it is `#[non_exhaustive]`",
); );
} }
err.span_note(note_span, msg); err.span_note(note_span, msg);

View file

@ -227,10 +227,8 @@ impl CodeStats {
} }
pub fn print_vtable_sizes(&self, crate_name: &str) { pub fn print_vtable_sizes(&self, crate_name: &str) {
let mut infos = std::mem::take(&mut *self.vtable_sizes.lock()) let mut infos =
.into_iter() std::mem::take(&mut *self.vtable_sizes.lock()).into_values().collect::<Vec<_>>();
.map(|(_did, stats)| stats)
.collect::<Vec<_>>();
// Primary sort: cost % in reverse order (from largest to smallest) // Primary sort: cost % in reverse order (from largest to smallest)
// Secondary sort: trait_name // Secondary sort: trait_name

View file

@ -329,18 +329,13 @@ pub struct OnUnimplementedNote {
} }
/// Append a message for `~const Trait` errors. /// Append a message for `~const Trait` errors.
#[derive(Clone, Copy, PartialEq, Eq, Debug)] #[derive(Clone, Copy, PartialEq, Eq, Debug, Default)]
pub enum AppendConstMessage { pub enum AppendConstMessage {
#[default]
Default, Default,
Custom(Symbol), Custom(Symbol),
} }
impl Default for AppendConstMessage {
fn default() -> Self {
AppendConstMessage::Default
}
}
impl<'tcx> OnUnimplementedDirective { impl<'tcx> OnUnimplementedDirective {
fn parse( fn parse(
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,

View file

@ -1471,7 +1471,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
let span = if needs_parens { span } else { span.shrink_to_lo() }; let span = if needs_parens { span } else { span.shrink_to_lo() };
let suggestions = if !needs_parens { let suggestions = if !needs_parens {
vec![(span.shrink_to_lo(), format!("{}", sugg_prefix))] vec![(span.shrink_to_lo(), sugg_prefix)]
} else { } else {
vec![ vec![
(span.shrink_to_lo(), format!("{}(", sugg_prefix)), (span.shrink_to_lo(), format!("{}(", sugg_prefix)),

View file

@ -183,8 +183,7 @@ pub fn test_main_static_abort(tests: &[&TestDescAndFn]) {
let test = tests let test = tests
.into_iter() .into_iter()
.filter(|test| test.desc.name.as_slice() == name) .find(|test| test.desc.name.as_slice() == name)
.next()
.unwrap_or_else(|| panic!("couldn't find a test with the provided name '{name}'")); .unwrap_or_else(|| panic!("couldn't find a test with the provided name '{name}'"));
let TestDescAndFn { desc, testfn } = test; let TestDescAndFn { desc, testfn } = test;
match testfn.into_runnable() { match testfn.into_runnable() {