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

Commit a144ea1

Browse files
authored
Rollup merge of rust-lang#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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 2 deletions
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

Lines changed: 10 additions & 12 deletions
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

0 commit comments

Comments
 (0)