Skip to content

Commit a144ea1

Browse files
authoredFeb 18, 2022
Rollup merge of #93634 - matthiaskrgr:clippy_complexity_jan_2022, r=oli-obk
compiler: clippy::complexity fixes useless_format map_flatten useless_conversion needless_bool filter_next clone_on_copy needless_option_as_deref
2 parents f1c918f + b80057d commit a144ea1

File tree

22 files changed

+39
-45
lines changed

22 files changed

+39
-45
lines changed
 

‎compiler/rustc_ast/src/attr/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ impl AttrItem {
230230
}
231231

232232
pub fn meta_kind(&self) -> Option<MetaItemKind> {
233-
Some(MetaItemKind::from_mac_args(&self.args)?)
233+
MetaItemKind::from_mac_args(&self.args)
234234
}
235235
}
236236

‎compiler/rustc_ast_passes/src/feature_gate.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -823,7 +823,7 @@ fn maybe_stage_features(sess: &Session, krate: &ast::Crate) {
823823
);
824824
let mut all_stable = true;
825825
for ident in
826-
attr.meta_item_list().into_iter().flatten().map(|nested| nested.ident()).flatten()
826+
attr.meta_item_list().into_iter().flatten().flat_map(|nested| nested.ident())
827827
{
828828
let name = ident.name;
829829
let stable_since = lang_features

‎compiler/rustc_codegen_llvm/src/context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ pub unsafe fn create_module<'ll>(
292292
"sign-return-address-all\0".as_ptr().cast(),
293293
pac_opts.leaf.into(),
294294
);
295-
let is_bkey = if pac_opts.key == PAuthKey::A { false } else { true };
295+
let is_bkey: bool = pac_opts.key != PAuthKey::A;
296296
llvm::LLVMRustAddModuleFlag(
297297
llmod,
298298
llvm::LLVMModFlagBehavior::Error,

‎compiler/rustc_codegen_ssa/src/mir/place.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
476476
mir::ProjectionElem::Subslice { from, to, from_end } => {
477477
let mut subslice = cg_base.project_index(bx, bx.cx().const_usize(from as u64));
478478
let projected_ty =
479-
PlaceTy::from_ty(cg_base.layout.ty).projection_ty(tcx, elem.clone()).ty;
479+
PlaceTy::from_ty(cg_base.layout.ty).projection_ty(tcx, *elem).ty;
480480
subslice.layout = bx.cx().layout_of(self.monomorphize(projected_ty));
481481

482482
if subslice.layout.is_unsized() {

‎compiler/rustc_expand/src/mbe/macro_rules.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1039,7 +1039,7 @@ fn check_matcher_core(
10391039
));
10401040
err.span_suggestion(
10411041
span,
1042-
&format!("try a `pat_param` fragment specifier instead"),
1042+
"try a `pat_param` fragment specifier instead",
10431043
suggestion,
10441044
Applicability::MaybeIncorrect,
10451045
);

‎compiler/rustc_middle/src/middle/stability.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ fn deprecation_message(
198198
} else {
199199
let since = since.as_ref().map(Symbol::as_str);
200200

201-
if since.as_deref() == Some("TBD") {
201+
if since == Some("TBD") {
202202
format!("use of {} `{}` that will be deprecated in a future Rust version", kind, path)
203203
} else {
204204
format!(

‎compiler/rustc_middle/src/ty/relate.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -855,7 +855,7 @@ impl<'tcx> Relate<'tcx> for ty::ProjectionPredicate<'tcx> {
855855
) -> RelateResult<'tcx, ty::ProjectionPredicate<'tcx>> {
856856
Ok(ty::ProjectionPredicate {
857857
projection_ty: relation.relate(a.projection_ty, b.projection_ty)?,
858-
term: relation.relate(a.term, b.term)?.into(),
858+
term: relation.relate(a.term, b.term)?,
859859
})
860860
}
861861
}

‎compiler/rustc_middle/src/ty/trait_def.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ impl<'tcx> TyCtxt<'tcx> {
210210
pub fn all_impls(self, def_id: DefId) -> impl Iterator<Item = DefId> + 'tcx {
211211
let TraitImpls { blanket_impls, non_blanket_impls } = self.trait_impls_of(def_id);
212212

213-
blanket_impls.iter().chain(non_blanket_impls.iter().map(|(_, v)| v).flatten()).cloned()
213+
blanket_impls.iter().chain(non_blanket_impls.iter().flat_map(|(_, v)| v)).cloned()
214214
}
215215
}
216216

‎compiler/rustc_mir_transform/src/coverage/query.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ fn covered_code_regions<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> Vec<&'tcx Cod
140140
let body = mir_body(tcx, def_id);
141141
body.basic_blocks()
142142
.iter()
143-
.map(|data| {
143+
.flat_map(|data| {
144144
data.statements.iter().filter_map(|statement| match statement.kind {
145145
StatementKind::Coverage(box ref coverage) => {
146146
if is_inlined(body, statement) {
@@ -152,7 +152,6 @@ fn covered_code_regions<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> Vec<&'tcx Cod
152152
_ => None,
153153
})
154154
})
155-
.flatten()
156155
.collect()
157156
}
158157

‎compiler/rustc_monomorphize/src/partitioning/mod.rs

+10-12
Original file line numberDiff line numberDiff line change
@@ -220,18 +220,16 @@ pub fn partition<'tcx>(
220220
let mut cgus: Vec<_> = post_inlining.codegen_units.iter_mut().collect();
221221
cgus.sort_by_key(|cgu| cgu.size_estimate());
222222

223-
let dead_code_cgu = if let Some(cgu) = cgus
224-
.into_iter()
225-
.rev()
226-
.filter(|cgu| cgu.items().iter().any(|(_, (linkage, _))| *linkage == Linkage::External))
227-
.next()
228-
{
229-
cgu
230-
} else {
231-
// If there are no CGUs that have externally linked items,
232-
// then we just pick the first CGU as a fallback.
233-
&mut post_inlining.codegen_units[0]
234-
};
223+
let dead_code_cgu =
224+
if let Some(cgu) = cgus.into_iter().rev().find(|cgu| {
225+
cgu.items().iter().any(|(_, (linkage, _))| *linkage == Linkage::External)
226+
}) {
227+
cgu
228+
} else {
229+
// If there are no CGUs that have externally linked items,
230+
// then we just pick the first CGU as a fallback.
231+
&mut post_inlining.codegen_units[0]
232+
};
235233
dead_code_cgu.make_code_coverage_dead_code_cgu();
236234
}
237235

‎compiler/rustc_parse/src/parser/diagnostics.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -2156,7 +2156,7 @@ impl<'a> Parser<'a> {
21562156
| PatKind::TupleStruct(qself @ None, path, _)
21572157
| PatKind::Path(qself @ None, path) => match &first_pat.kind {
21582158
PatKind::Ident(_, ident, _) => {
2159-
path.segments.insert(0, PathSegment::from_ident(ident.clone()));
2159+
path.segments.insert(0, PathSegment::from_ident(*ident));
21602160
path.span = new_span;
21612161
show_sugg = true;
21622162
first_pat = pat;
@@ -2183,8 +2183,8 @@ impl<'a> Parser<'a> {
21832183
Path {
21842184
span: new_span,
21852185
segments: vec![
2186-
PathSegment::from_ident(old_ident.clone()),
2187-
PathSegment::from_ident(ident.clone()),
2186+
PathSegment::from_ident(*old_ident),
2187+
PathSegment::from_ident(*ident),
21882188
],
21892189
tokens: None,
21902190
},
@@ -2194,7 +2194,7 @@ impl<'a> Parser<'a> {
21942194
}
21952195
PatKind::Path(old_qself, old_path) => {
21962196
let mut segments = old_path.segments.clone();
2197-
segments.push(PathSegment::from_ident(ident.clone()));
2197+
segments.push(PathSegment::from_ident(*ident));
21982198
let path = PatKind::Path(
21992199
old_qself.clone(),
22002200
Path { span: new_span, segments, tokens: None },

‎compiler/rustc_parse/src/parser/generics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ impl<'a> Parser<'a> {
260260
let ate_comma = self.eat(&token::Comma);
261261

262262
if self.eat_keyword_noexpect(kw::Where) {
263-
let msg = &format!("cannot define duplicate `where` clauses on an item");
263+
let msg = "cannot define duplicate `where` clauses on an item";
264264
let mut err = self.struct_span_err(self.token.span, msg);
265265
err.span_label(lo, "previous `where` clause starts here");
266266
err.span_suggestion_verbose(

‎compiler/rustc_resolve/src/diagnostics.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -1362,8 +1362,7 @@ impl<'a> Resolver<'a> {
13621362
.filter(|(_, module)| {
13631363
current_module.is_ancestor_of(module) && !ptr::eq(current_module, *module)
13641364
})
1365-
.map(|(_, module)| module.kind.name())
1366-
.flatten(),
1365+
.flat_map(|(_, module)| module.kind.name()),
13671366
)
13681367
.filter(|c| !c.to_string().is_empty())
13691368
.collect::<Vec<_>>();
@@ -1859,7 +1858,7 @@ crate fn show_candidates(
18591858
let instead = if instead { " instead" } else { "" };
18601859
let mut msg = format!("consider importing {} {}{}", determiner, kind, instead);
18611860

1862-
for note in accessible_path_strings.iter().map(|cand| cand.3.as_ref()).flatten() {
1861+
for note in accessible_path_strings.iter().flat_map(|cand| cand.3.as_ref()) {
18631862
err.note(note);
18641863
}
18651864

@@ -1942,7 +1941,7 @@ crate fn show_candidates(
19421941
multi_span.push_span_label(span, format!("`{}`: not accessible", name));
19431942
}
19441943

1945-
for note in inaccessible_path_strings.iter().map(|cand| cand.3.as_ref()).flatten() {
1944+
for note in inaccessible_path_strings.iter().flat_map(|cand| cand.3.as_ref()) {
19461945
err.note(note);
19471946
}
19481947

‎compiler/rustc_resolve/src/late/diagnostics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1163,7 +1163,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
11631163
err.span_suggestion(
11641164
span,
11651165
&"use this syntax instead",
1166-
format!("{path_str}"),
1166+
path_str.to_string(),
11671167
Applicability::MaybeIncorrect,
11681168
);
11691169
}

‎compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1437,8 +1437,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'a, 'tcx> for InferCtxt<'a, 'tcx> {
14371437
self.tcx
14381438
.associated_items(did)
14391439
.in_definition_order()
1440-
.filter(|assoc| assoc.ident(self.tcx) == trait_assoc_ident)
1441-
.next()
1440+
.find(|assoc| assoc.ident(self.tcx) == trait_assoc_ident)
14421441
},
14431442
)
14441443
})

‎compiler/rustc_trait_selection/src/traits/project.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -959,7 +959,7 @@ fn opt_normalize_projection_type<'a, 'b, 'tcx>(
959959
infcx.inner.borrow_mut().projection_cache().insert_term(cache_key, result.clone());
960960
}
961961
obligations.extend(result.obligations);
962-
Ok(Some(result.value.into()))
962+
Ok(Some(result.value))
963963
}
964964
Ok(Projected::NoProgress(projected_ty)) => {
965965
let result = Normalized { value: projected_ty, obligations: vec![] };

‎compiler/rustc_typeck/src/astconv/errors.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
211211
);
212212

213213
let all_candidate_names: Vec<_> = all_candidates()
214-
.map(|r| self.tcx().associated_items(r.def_id()).in_definition_order())
215-
.flatten()
214+
.flat_map(|r| self.tcx().associated_items(r.def_id()).in_definition_order())
216215
.filter_map(
217216
|item| if item.kind == ty::AssocKind::Type { Some(item.name) } else { None },
218217
)

‎compiler/rustc_typeck/src/check/check.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ fn check_union_fields(tcx: TyCtxt<'_>, span: Span, item_def_id: LocalDefId) -> b
392392
"when the type does not implement `Copy`, \
393393
wrap it inside a `ManuallyDrop<_>` and ensure it is manually dropped",
394394
vec![
395-
(ty_span.shrink_to_lo(), format!("std::mem::ManuallyDrop<")),
395+
(ty_span.shrink_to_lo(), "std::mem::ManuallyDrop<".into()),
396396
(ty_span.shrink_to_hi(), ">".into()),
397397
],
398398
Applicability::MaybeIncorrect,

‎compiler/rustc_typeck/src/check/demand.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
340340

341341
let prefix = match self.maybe_get_struct_pattern_shorthand_field(expr) {
342342
Some(ident) => format!("{}: ", ident),
343-
None => format!(""),
343+
None => String::new(),
344344
};
345345

346346
match &compatible_variants[..] {
@@ -683,7 +683,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
683683

684684
let prefix = match self.maybe_get_struct_pattern_shorthand_field(expr) {
685685
Some(ident) => format!("{}: ", ident),
686-
None => format!(""),
686+
None => String::new(),
687687
};
688688

689689
if let Some(hir::Node::Expr(hir::Expr {
@@ -875,7 +875,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
875875
};
876876
let prefix = match self.maybe_get_struct_pattern_shorthand_field(expr) {
877877
Some(ident) => format!("{}: ", ident),
878-
None => format!(""),
878+
None => String::new(),
879879
};
880880
let (span, suggestion) = if self.is_else_if_block(expr) {
881881
// Don't suggest nonsense like `else *if`

‎compiler/rustc_typeck/src/check/generator_interior/drop_ranges.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ impl DropRangesBuilder {
246246

247247
fn add_control_edge(&mut self, from: PostOrderId, to: PostOrderId) {
248248
trace!("adding control edge from {:?} to {:?}", from, to);
249-
self.node_mut(from.into()).successors.push(to.into());
249+
self.node_mut(from).successors.push(to);
250250
}
251251
}
252252

‎compiler/rustc_typeck/src/check/generator_interior/drop_ranges/cfg_build.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ impl DropRangesBuilder {
527527

528528
fn drop_at(&mut self, value: TrackedValue, location: PostOrderId) {
529529
let value = self.tracked_value_index(value);
530-
self.node_mut(location.into()).drops.push(value);
530+
self.node_mut(location).drops.push(value);
531531
}
532532

533533
fn reinit_at(&mut self, value: TrackedValue, location: PostOrderId) {
@@ -537,7 +537,7 @@ impl DropRangesBuilder {
537537
// ignore this.
538538
None => return,
539539
};
540-
self.node_mut(location.into()).reinits.push(value);
540+
self.node_mut(location).reinits.push(value);
541541
}
542542

543543
/// Looks up PostOrderId for any control edges added by HirId and adds a proper edge for them.

‎compiler/rustc_typeck/src/collect/type_of.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
527527
// FIXME(associated_const_equality): add a useful error message here.
528528
tcx.ty_error_with_message(
529529
DUMMY_SP,
530-
&format!("Could not find associated const on trait"),
530+
"Could not find associated const on trait",
531531
)
532532
}
533533
}

0 commit comments

Comments
 (0)
Please sign in to comment.