Skip to content

clippy::style fixes #113975

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/rustc_builtin_macros/src/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ fn parse_clobber_abi<'a>(p: &mut Parser<'a>, args: &mut AsmArgs) -> PResult<'a,
// should have errored above during parsing
[] => unreachable!(),
[(abi, _span)] => args.clobber_abis.push((*abi, full_span)),
[abis @ ..] => {
abis => {
for (abi, span) in abis {
args.clobber_abis.push((*abi, *span));
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/coherence/orphan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ fn emit_orphan_check_error<'tcx>(

let this = |name: &str| {
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 {
msg("this", &format!(" because {name} are always foreign"))
}
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_hir_typeck/src/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -705,10 +705,10 @@ impl<'a, 'tcx> CastCheck<'tcx> {
)
}),
|lint| {
lint.help(format!(
lint.help(
"cast can be replaced by coercion; this might \
require a temporary variable"
))
require a temporary variable",
)
},
);
}
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_infer/src/infer/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,11 +264,11 @@ fn msg_span_from_named_region<'tcx>(
ty::RePlaceholder(ty::PlaceholderRegion {
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 {
bound: ty::BoundRegion { kind: ty::BoundRegionKind::BrAnon(None), .. },
..
}) => (format!("an anonymous lifetime"), None),
}) => ("an anonymous lifetime".to_owned(), None),
_ => bug!("{:?}", region),
}
}
Expand Down Expand Up @@ -2354,7 +2354,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
if let Ok(snip) = self.tcx.sess.source_map().span_to_next_source(p.span)
&& snip.starts_with(' ')
{
format!("{new_lt}")
new_lt.to_string()
} else {
format!("{new_lt} ")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -333,11 +333,7 @@ pub fn suggest_new_region_bound(
} else {
None
};
let name = if let Some(name) = &existing_lt_name {
format!("{}", name)
} else {
format!("'a")
};
let name = if let Some(name) = &existing_lt_name { name } else { "'a" };
// 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
if let Some(id) = scope_def_id
Expand All @@ -350,7 +346,7 @@ pub fn suggest_new_region_bound(
if p.span.hi() - p.span.lo() == rustc_span::BytePos(1) { // Ampersand (elided without '_)
(p.span.shrink_to_hi(),format!("{name} "))
} else { // Underscore (elided with '_)
(p.span, format!("{name}"))
(p.span, name.to_string())
}
)
.collect::<Vec<_>>()
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_parse/src/parser/generics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl<'a> Parser<'a> {
&& self.check_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.
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_query_impl/src/plumbing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ pub(super) fn encode_all_query_results<'tcx>(
encoder: &mut CacheEncoder<'_, 'tcx>,
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);
}
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_resolve/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1395,7 +1395,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
let head_span = source_map.guess_head_span(span);
err.subdiagnostic(ConsiderAddingADerive {
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] {
Expand Down Expand Up @@ -1718,7 +1718,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
if next_binding.is_none() && let Some(span) = non_exhaustive {
note_span.push_span_label(
span,
format!("cannot be constructed because it is `#[non_exhaustive]`"),
"cannot be constructed because it is `#[non_exhaustive]`",
);
}
err.span_note(note_span, msg);
Expand Down
6 changes: 2 additions & 4 deletions compiler/rustc_session/src/code_stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,10 +227,8 @@ impl CodeStats {
}

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

// Primary sort: cost % in reverse order (from largest to smallest)
// Secondary sort: trait_name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,18 +329,13 @@ pub struct OnUnimplementedNote {
}

/// Append a message for `~const Trait` errors.
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
#[derive(Clone, Copy, PartialEq, Eq, Debug, Default)]
pub enum AppendConstMessage {
#[default]
Default,
Custom(Symbol),
}

impl Default for AppendConstMessage {
fn default() -> Self {
AppendConstMessage::Default
}
}

impl<'tcx> OnUnimplementedDirective {
fn parse(
tcx: TyCtxt<'tcx>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1471,7 +1471,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {

let span = if needs_parens { span } else { span.shrink_to_lo() };
let suggestions = if !needs_parens {
vec![(span.shrink_to_lo(), format!("{}", sugg_prefix))]
vec![(span.shrink_to_lo(), sugg_prefix)]
} else {
vec![
(span.shrink_to_lo(), format!("{}(", sugg_prefix)),
Expand Down
3 changes: 1 addition & 2 deletions library/test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,7 @@ pub fn test_main_static_abort(tests: &[&TestDescAndFn]) {

let test = tests
.into_iter()
.filter(|test| test.desc.name.as_slice() == name)
.next()
.find(|test| test.desc.name.as_slice() == name)
.unwrap_or_else(|| panic!("couldn't find a test with the provided name '{name}'"));
let TestDescAndFn { desc, testfn } = test;
match testfn.into_runnable() {
Expand Down