Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit aadd618

Browse files
committed
Auto merge of rust-lang#87449 - matthiaskrgr:clippyy_v2, r=nagisa
more clippy::complexity fixes (also a couple of clippy::perf fixes)
2 parents f381e77 + 3fd8cbb commit aadd618

File tree

32 files changed

+44
-51
lines changed

32 files changed

+44
-51
lines changed

compiler/rustc_ast_pretty/src/pprust/state.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2189,8 +2189,7 @@ impl<'a> State<'a> {
21892189
Options(InlineAsmOptions),
21902190
}
21912191

2192-
let mut args = vec![];
2193-
args.push(AsmArg::Template(InlineAsmTemplatePiece::to_string(&asm.template)));
2192+
let mut args = vec![AsmArg::Template(InlineAsmTemplatePiece::to_string(&asm.template))];
21942193
args.extend(asm.operands.iter().map(|(o, _)| AsmArg::Operand(o)));
21952194
if !asm.options.is_empty() {
21962195
args.push(AsmArg::Options(asm.options));

compiler/rustc_codegen_llvm/src/llvm_util.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ pub fn llvm_global_features(sess: &Session) -> Vec<String> {
365365

366366
features_string
367367
};
368-
features.extend(features_string.split(",").map(String::from));
368+
features.extend(features_string.split(',').map(String::from));
369369
}
370370
Some(_) | None => {}
371371
};
@@ -374,7 +374,7 @@ pub fn llvm_global_features(sess: &Session) -> Vec<String> {
374374
if s.is_empty() {
375375
return None;
376376
}
377-
let feature = if s.starts_with("+") || s.starts_with("-") {
377+
let feature = if s.starts_with('+') || s.starts_with('-') {
378378
&s[1..]
379379
} else {
380380
return Some(s.to_string());

compiler/rustc_expand/src/proc_macro_server.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -834,7 +834,7 @@ fn ident_name_compatibility_hack(
834834
.flat_map(|c| c.as_os_str().to_str())
835835
.find(|c| c.starts_with("js-sys"))
836836
{
837-
let mut version = c.trim_start_matches("js-sys-").split(".");
837+
let mut version = c.trim_start_matches("js-sys-").split('.');
838838
if version.next() == Some("0")
839839
&& version.next() == Some("3")
840840
&& version

compiler/rustc_hir/src/def.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ impl<T> PerNS<Option<T>> {
476476

477477
/// Returns an iterator over the items which are `Some`.
478478
pub fn present_items(self) -> impl Iterator<Item = T> {
479-
IntoIter::new([self.type_ns, self.value_ns, self.macro_ns]).filter_map(|it| it)
479+
IntoIter::new([self.type_ns, self.value_ns, self.macro_ns]).flatten()
480480
}
481481
}
482482

compiler/rustc_hir_pretty/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1357,8 +1357,8 @@ impl<'a> State<'a> {
13571357
Options(ast::InlineAsmOptions),
13581358
}
13591359

1360-
let mut args = vec![];
1361-
args.push(AsmArg::Template(ast::InlineAsmTemplatePiece::to_string(&asm.template)));
1360+
let mut args =
1361+
vec![AsmArg::Template(ast::InlineAsmTemplatePiece::to_string(&asm.template))];
13621362
args.extend(asm.operands.iter().map(|(o, _)| AsmArg::Operand(o)));
13631363
if !asm.options.is_empty() {
13641364
args.push(AsmArg::Options(asm.options));

compiler/rustc_lint/src/levels.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ pub fn is_known_lint_tool(m_item: Symbol, sess: &Session, attrs: &[ast::Attribut
576576
// NOTE: does no error handling; error handling is done by rustc_resolve.
577577
sess.filter_by_name(attrs, sym::register_tool)
578578
.filter_map(|attr| attr.meta_item_list())
579-
.flat_map(std::convert::identity)
579+
.flatten()
580580
.filter_map(|nested_meta| nested_meta.ident())
581581
.map(|ident| ident.name)
582582
.any(|name| name == m_item)

compiler/rustc_lint/src/types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -906,7 +906,7 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
906906
} else {
907907
return FfiUnsafe {
908908
ty,
909-
reason: format!("box cannot be represented as a single pointer"),
909+
reason: "box cannot be represented as a single pointer".to_string(),
910910
help: None,
911911
};
912912
}

compiler/rustc_macros/src/symbols.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ fn symbols_with_errors(input: TokenStream) -> (TokenStream, Vec<syn::Error>) {
135135
let mut check_dup = |span: Span, str: &str, errors: &mut Errors| {
136136
if let Some(prev_span) = keys.get(str) {
137137
errors.error(span, format!("Symbol `{}` is duplicated", str));
138-
errors.error(*prev_span, format!("location of previous definition"));
138+
errors.error(*prev_span, "location of previous definition".to_string());
139139
} else {
140140
keys.insert(str.to_string(), span);
141141
}

compiler/rustc_middle/src/ty/codec.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ impl<'tcx, D: TyDecoder<'tcx>> RefDecodable<'tcx, D> for [mir::abstract_const::N
385385
impl<'tcx, D: TyDecoder<'tcx>> RefDecodable<'tcx, D> for ty::List<ty::BoundVariableKind> {
386386
fn decode(decoder: &mut D) -> Result<&'tcx Self, D::Error> {
387387
let len = decoder.read_usize()?;
388-
Ok(decoder.tcx().mk_bound_variable_kinds((0..len).map(|_| Decodable::decode(decoder)))?)
388+
decoder.tcx().mk_bound_variable_kinds((0..len).map(|_| Decodable::decode(decoder)))
389389
}
390390
}
391391

compiler/rustc_mir/src/borrow_check/diagnostics/conflict_errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
320320
.map(|n| format!("`{}`", n))
321321
.unwrap_or_else(|| "the mutable reference".to_string()),
322322
),
323-
format!("&mut *"),
323+
"&mut *".to_string(),
324324
Applicability::MachineApplicable,
325325
);
326326
}

compiler/rustc_mir/src/borrow_check/diagnostics/mutability_errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
731731
if suggestions.peek().is_some() {
732732
err.span_suggestions(
733733
path_segment.ident.span,
734-
&format!("use mutable method"),
734+
"use mutable method",
735735
suggestions,
736736
Applicability::MaybeIncorrect,
737737
);

compiler/rustc_mir/src/monomorphize/partitioning/merging.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ pub fn merge_codegen_units<'tcx>(
4646
// Record that `second_smallest` now contains all the stuff that was in
4747
// `smallest` before.
4848
let mut consumed_cgu_names = cgu_contents.remove(&smallest.name()).unwrap();
49-
cgu_contents.get_mut(&second_smallest.name()).unwrap().extend(consumed_cgu_names.drain(..));
49+
cgu_contents.get_mut(&second_smallest.name()).unwrap().append(&mut consumed_cgu_names);
5050

5151
debug!(
5252
"CodegenUnit {} merged into CodegenUnit {}",

compiler/rustc_mir/src/transform/check_consts/ops.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ impl NonConstOp for CellBorrow {
255255
);
256256
err.span_label(
257257
span,
258-
format!("this borrow of an interior mutable value may end up in the final value"),
258+
"this borrow of an interior mutable value may end up in the final value",
259259
);
260260
if let hir::ConstContext::Static(_) = ccx.const_kind() {
261261
err.help(

compiler/rustc_mir/src/transform/coverage/debug.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ impl DebugCounters {
344344
return if counter_format.id {
345345
format!("{}#{}", block_label, id.index())
346346
} else {
347-
format!("{}", block_label)
347+
block_label.to_string()
348348
};
349349
}
350350
}
@@ -369,7 +369,7 @@ impl DebugCounters {
369369
}
370370
return format!("({})", self.format_counter_kind(counter_kind));
371371
}
372-
return format!("{}", self.format_counter_kind(counter_kind));
372+
return self.format_counter_kind(counter_kind).to_string();
373373
}
374374
}
375375
format!("#{}", operand.index().to_string())

compiler/rustc_mir/src/transform/coverage/graph.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -526,8 +526,8 @@ impl TraverseCoverageGraphWithLoops {
526526
pub fn new(basic_coverage_blocks: &CoverageGraph) -> Self {
527527
let start_bcb = basic_coverage_blocks.start_node();
528528
let backedges = find_loop_backedges(basic_coverage_blocks);
529-
let mut context_stack = Vec::new();
530-
context_stack.push(TraversalContext { loop_backedges: None, worklist: vec![start_bcb] });
529+
let context_stack =
530+
vec![TraversalContext { loop_backedges: None, worklist: vec![start_bcb] }];
531531
// `context_stack` starts with a `TraversalContext` for the main function context (beginning
532532
// with the `start` BasicCoverageBlock of the function). New worklists are pushed to the top
533533
// of the stack as loops are entered, and popped off of the stack when a loop's worklist is

compiler/rustc_mir/src/transform/inline.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -614,8 +614,8 @@ impl Inliner<'tcx> {
614614
.vars_and_temps_iter()
615615
.map(|local| callee_body.local_decls[local].clone()),
616616
);
617-
caller_body.source_scopes.extend(callee_body.source_scopes.drain(..));
618-
caller_body.var_debug_info.extend(callee_body.var_debug_info.drain(..));
617+
caller_body.source_scopes.extend(&mut callee_body.source_scopes.drain(..));
618+
caller_body.var_debug_info.append(&mut callee_body.var_debug_info);
619619
caller_body.basic_blocks_mut().extend(callee_body.basic_blocks_mut().drain(..));
620620

621621
caller_body[callsite.block].terminator = Some(Terminator {

compiler/rustc_mir/src/transform/lower_intrinsics.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,8 @@ fn validate_simd_shuffle(tcx: TyCtxt<'tcx>, args: &[Operand<'tcx>], span: Span)
147147
match &args[2] {
148148
Operand::Constant(_) => {} // all good
149149
_ => {
150-
let msg = format!("last argument of `simd_shuffle` is required to be a `const` item");
151-
tcx.sess.span_err(span, &msg);
150+
let msg = "last argument of `simd_shuffle` is required to be a `const` item";
151+
tcx.sess.span_err(span, msg);
152152
}
153153
}
154154
}

compiler/rustc_mir/src/util/pretty.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ impl Visitor<'tcx> for ExtraComments<'tcx> {
479479
uv.promoted
480480
),
481481
ty::ConstKind::Value(val) => format!("Value({:?})", val),
482-
ty::ConstKind::Error(_) => format!("Error"),
482+
ty::ConstKind::Error(_) => "Error".to_string(),
483483
};
484484
self.push(&format!("+ val: {}", val));
485485
}

compiler/rustc_parse/src/parser/item.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,8 +1107,7 @@ impl<'a> Parser<'a> {
11071107
e
11081108
})?;
11091109

1110-
let enum_definition =
1111-
EnumDef { variants: variants.into_iter().filter_map(|v| v).collect() };
1110+
let enum_definition = EnumDef { variants: variants.into_iter().flatten().collect() };
11121111
Ok((id, ItemKind::Enum(enum_definition, generics)))
11131112
}
11141113

compiler/rustc_passes/src/check_attr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -855,7 +855,7 @@ impl CheckAttrVisitor<'tcx> {
855855
hir_id,
856856
meta.span(),
857857
|lint| {
858-
lint.build(&format!("invalid `doc` attribute")).emit();
858+
lint.build(&"invalid `doc` attribute").emit();
859859
},
860860
);
861861
is_valid = false;

compiler/rustc_passes/src/entry.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ fn no_main_err(tcx: TyCtxt<'_>, visitor: &EntryContext<'_, '_>) {
229229
if let Some(main_def) = tcx.resolutions(()).main_def {
230230
if main_def.opt_fn_def_id().is_none() {
231231
// There is something at `crate::main`, but it is not a function definition.
232-
err.span_label(main_def.span, &format!("non-function item at `crate::main` is found"));
232+
err.span_label(main_def.span, "non-function item at `crate::main` is found");
233233
}
234234
}
235235

compiler/rustc_query_system/src/query/plumbing.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -620,8 +620,8 @@ fn incremental_verify_ich<CTX, K, V: Debug>(
620620
};
621621
tcx.sess().struct_err(&format!("internal compiler error: encountered incremental compilation error with {:?}", dep_node))
622622
.help(&format!("This is a known issue with the compiler. Run {} to allow your project to compile", run_cmd))
623-
.note(&format!("Please follow the instructions below to create a bug report with the provided information"))
624-
.note(&format!("See <https://github.com/rust-lang/rust/issues/84970> for more information"))
623+
.note(&"Please follow the instructions below to create a bug report with the provided information")
624+
.note(&"See <https://github.com/rust-lang/rust/issues/84970> for more information")
625625
.emit();
626626
panic!("Found unstable fingerprints for {:?}: {:?}", dep_node, result);
627627
}

compiler/rustc_resolve/src/late/diagnostics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1061,7 +1061,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
10611061
}
10621062
err.span_suggestion(
10631063
span,
1064-
&format!("use this syntax instead"),
1064+
&"use this syntax instead",
10651065
format!("{path_str}"),
10661066
Applicability::MaybeIncorrect,
10671067
);

compiler/rustc_session/src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1867,7 +1867,7 @@ fn parse_extern_dep_specs(
18671867
)
18681868
});
18691869

1870-
let locparts: Vec<_> = loc.split(":").collect();
1870+
let locparts: Vec<_> = loc.split(':').collect();
18711871
let spec = match &locparts[..] {
18721872
["raw", ..] => {
18731873
// Don't want `:` split string

compiler/rustc_session/src/options.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -684,7 +684,7 @@ mod parse {
684684
Some(v) => v,
685685
};
686686

687-
*slot = Some(match v.trim_end_matches("s") {
687+
*slot = Some(match v.trim_end_matches('s') {
688688
"statement" | "stmt" => MirSpanview::Statement,
689689
"terminator" | "term" => MirSpanview::Terminator,
690690
"block" | "basicblock" => MirSpanview::Block,

compiler/rustc_target/src/spec/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2018,7 +2018,7 @@ impl Target {
20182018

20192019
if base.is_builtin {
20202020
// This can cause unfortunate ICEs later down the line.
2021-
return Err(format!("may not set is_builtin for targets not built-in"));
2021+
return Err("may not set is_builtin for targets not built-in".to_string());
20222022
}
20232023
// Each field should have been read using `Json::remove_key` so any keys remaining are unused.
20242024
let remaining_keys = obj.as_object().ok_or("Expected JSON object for target")?.keys();

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,10 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
124124
self.impl_similar_to(trait_ref, obligation).unwrap_or_else(|| trait_ref.def_id());
125125
let trait_ref = trait_ref.skip_binder();
126126

127-
let mut flags = vec![];
128-
flags.push((
127+
let mut flags = vec![(
129128
sym::ItemContext,
130129
self.describe_enclosure(obligation.cause.body_id).map(|s| s.to_owned()),
131-
));
130+
)];
132131

133132
match obligation.cause.code {
134133
ObligationCauseCode::BuiltinDerivedObligation(..)

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

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -290,13 +290,9 @@ fn suggest_restriction(
290290
} else {
291291
// Trivial case: `T` needs an extra bound: `T: Bound`.
292292
let (sp, suggestion) = match (
293-
generics
294-
.params
295-
.iter()
296-
.filter(|p| {
297-
!matches!(p.kind, hir::GenericParamKind::Type { synthetic: Some(_), .. })
298-
})
299-
.next(),
293+
generics.params.iter().find(|p| {
294+
!matches!(p.kind, hir::GenericParamKind::Type { synthetic: Some(_), .. })
295+
}),
300296
super_traits,
301297
) {
302298
(_, None) => predicate_constraint(

compiler/rustc_traits/src/dropck_outlives.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ fn dropck_outlives<'tcx>(
9090

9191
// "outlives" represent types/regions that may be touched
9292
// by a destructor.
93-
result.kinds.extend(constraints.outlives.drain(..));
94-
result.overflows.extend(constraints.overflows.drain(..));
93+
result.kinds.append(&mut constraints.outlives);
94+
result.overflows.append(&mut constraints.overflows);
9595

9696
// If we have even one overflow, we should stop trying to evaluate further --
9797
// chances are, the subsequent overflows for this evaluation won't provide useful

compiler/rustc_typeck/src/check/method/prelude2021.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
357357
if let Ok(expr_text) = self.sess().source_map().span_to_snippet(expr.span) {
358358
(expr_text, true)
359359
} else {
360-
(format!("(..)"), false)
360+
("(..)".to_string(), false)
361361
};
362362

363363
let adjusted_text = if let Some(probe::AutorefOrPtrAdjustment::ToConstPtr) =

compiler/rustc_typeck/src/check/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -791,7 +791,7 @@ fn fn_sig_suggestion<'tcx>(
791791
})
792792
})
793793
.chain(std::iter::once(if sig.c_variadic { Some("...".to_string()) } else { None }))
794-
.filter_map(|arg| arg)
794+
.flatten()
795795
.collect::<Vec<String>>()
796796
.join(", ");
797797
let output = sig.output();

src/librustdoc/html/format.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ crate fn href(did: DefId, cx: &Context<'_>) -> Result<(String, ItemType, Vec<Str
488488
let cache = &cx.cache();
489489
let relative_to = &cx.current;
490490
fn to_module_fqp(shortty: ItemType, fqp: &[String]) -> &[String] {
491-
if shortty == ItemType::Module { &fqp[..] } else { &fqp[..fqp.len() - 1] }
491+
if shortty == ItemType::Module { fqp } else { &fqp[..fqp.len() - 1] }
492492
}
493493

494494
if !did.is_local() && !cache.access_levels.is_public(did) && !cache.document_private {
@@ -509,7 +509,7 @@ crate fn href(did: DefId, cx: &Context<'_>) -> Result<(String, ItemType, Vec<Str
509509
match cache.extern_locations[&did.krate] {
510510
ExternalLocation::Remote(ref s) => {
511511
let s = s.trim_end_matches('/');
512-
let mut s = vec![&s[..]];
512+
let mut s = vec![s];
513513
s.extend(module_fqp[..].iter().map(String::as_str));
514514
s
515515
}

0 commit comments

Comments
 (0)