Skip to content

Commit 59f394b

Browse files
authored
Rollup merge of #109846 - matthiaskrgr:clippy2023_04_III, r=Nilstrieb
more clippy::complexity fixes (iter_kv_map, map_flatten, nonminimal_bool)
2 parents e2ffe15 + 73bd953 commit 59f394b

File tree

16 files changed

+21
-30
lines changed

16 files changed

+21
-30
lines changed

compiler/rustc_codegen_llvm/src/common.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -378,8 +378,7 @@ pub(crate) fn get_dllimport<'tcx>(
378378
name: &str,
379379
) -> Option<&'tcx DllImport> {
380380
tcx.native_library(id)
381-
.map(|lib| lib.dll_imports.iter().find(|di| di.name.as_str() == name))
382-
.flatten()
381+
.and_then(|lib| lib.dll_imports.iter().find(|di| di.name.as_str() == name))
383382
}
384383

385384
pub(crate) fn is_mingw_gnu_toolchain(target: &Target) -> bool {

compiler/rustc_const_eval/src/transform/validate.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -677,8 +677,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
677677
);
678678
}
679679
if let Rvalue::CopyForDeref(place) = rvalue {
680-
if !place.ty(&self.body.local_decls, self.tcx).ty.builtin_deref(true).is_some()
681-
{
680+
if place.ty(&self.body.local_decls, self.tcx).ty.builtin_deref(true).is_none() {
682681
self.fail(
683682
location,
684683
"`CopyForDeref` should only be used for dereferenceable types",

compiler/rustc_hir_analysis/src/astconv/errors.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -483,8 +483,8 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
483483
[segment] if segment.args.is_none() => {
484484
trait_bound_spans = vec![segment.ident.span];
485485
associated_types = associated_types
486-
.into_iter()
487-
.map(|(_, items)| (segment.ident.span, items))
486+
.into_values()
487+
.map(|items| (segment.ident.span, items))
488488
.collect();
489489
}
490490
_ => {}

compiler/rustc_hir_typeck/src/expr_use_visitor.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
559559
// struct; however, when EUV is run during typeck, it
560560
// may not. This will generate an error earlier in typeck,
561561
// so we can just ignore it.
562-
if !self.tcx().sess.has_errors().is_some() {
562+
if self.tcx().sess.has_errors().is_none() {
563563
span_bug!(with_expr.span, "with expression doesn't evaluate to a struct");
564564
}
565565
}

compiler/rustc_infer/src/infer/error_reporting/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -978,7 +978,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
978978
let (_, sig, reg) = ty::print::FmtPrinter::new(self.tcx, Namespace::TypeNS)
979979
.name_all_regions(sig)
980980
.unwrap();
981-
let lts: Vec<String> = reg.into_iter().map(|(_, kind)| kind.to_string()).collect();
981+
let lts: Vec<String> = reg.into_values().map(|kind| kind.to_string()).collect();
982982
(if lts.is_empty() { String::new() } else { format!("for<{}> ", lts.join(", ")) }, sig)
983983
};
984984

compiler/rustc_middle/src/middle/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub mod lib_features {
1919
.stable
2020
.iter()
2121
.map(|(f, (s, _))| (*f, Some(*s)))
22-
.chain(self.unstable.iter().map(|(f, _)| (*f, None)))
22+
.chain(self.unstable.keys().map(|f| (*f, None)))
2323
.collect();
2424
all_features.sort_unstable_by(|a, b| a.0.as_str().partial_cmp(b.0.as_str()).unwrap());
2525
all_features

compiler/rustc_middle/src/ty/consts/valtree.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ impl<'tcx> ValTree<'tcx> {
7979
}
8080

8181
pub fn try_to_target_usize(self, tcx: TyCtxt<'tcx>) -> Option<u64> {
82-
self.try_to_scalar_int().map(|s| s.try_to_target_usize(tcx).ok()).flatten()
82+
self.try_to_scalar_int().and_then(|s| s.try_to_target_usize(tcx).ok())
8383
}
8484

8585
/// Get the values inside the ValTree as a slice of bytes. This only works for

compiler/rustc_mir_build/src/build/expr/as_constant.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -62,21 +62,21 @@ pub fn as_constant_inner<'tcx>(
6262
Constant { span, user_ty: None, literal }
6363
}
6464
ExprKind::NonHirLiteral { lit, ref user_ty } => {
65-
let user_ty = user_ty.as_ref().map(push_cuta).flatten();
65+
let user_ty = user_ty.as_ref().and_then(push_cuta);
6666

6767
let literal = ConstantKind::Val(ConstValue::Scalar(Scalar::Int(lit)), ty);
6868

6969
Constant { span, user_ty, literal }
7070
}
7171
ExprKind::ZstLiteral { ref user_ty } => {
72-
let user_ty = user_ty.as_ref().map(push_cuta).flatten();
72+
let user_ty = user_ty.as_ref().and_then(push_cuta);
7373

7474
let literal = ConstantKind::Val(ConstValue::ZeroSized, ty);
7575

7676
Constant { span, user_ty, literal }
7777
}
7878
ExprKind::NamedConst { def_id, substs, ref user_ty } => {
79-
let user_ty = user_ty.as_ref().map(push_cuta).flatten();
79+
let user_ty = user_ty.as_ref().and_then(push_cuta);
8080

8181
let uneval = mir::UnevaluatedConst::new(ty::WithOptConstParam::unknown(def_id), substs);
8282
let literal = ConstantKind::Unevaluated(uneval, ty);

compiler/rustc_monomorphize/src/partitioning/default.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,7 @@ impl<'tcx> Partitioner<'tcx> for DefaultPartitioning {
8989
}
9090

9191
PreInliningPartitioning {
92-
codegen_units: codegen_units
93-
.into_iter()
94-
.map(|(_, codegen_unit)| codegen_unit)
95-
.collect(),
92+
codegen_units: codegen_units.into_values().map(|codegen_unit| codegen_unit).collect(),
9693
roots,
9794
internalization_candidates,
9895
}

compiler/rustc_passes/src/entry.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ fn no_main_err(tcx: TyCtxt<'_>, visitor: &EntryContext<'_>) {
206206
// The file may be empty, which leads to the diagnostic machinery not emitting this
207207
// note. This is a relatively simple way to detect that case and emit a span-less
208208
// note instead.
209-
let file_empty = !tcx.sess.source_map().lookup_line(sp.hi()).is_ok();
209+
let file_empty = tcx.sess.source_map().lookup_line(sp.hi()).is_err();
210210

211211
tcx.sess.emit_err(NoMainErr {
212212
sp,

compiler/rustc_resolve/src/diagnostics.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1669,8 +1669,8 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
16691669
) -> Option<Symbol> {
16701670
let mut candidates = self
16711671
.extern_prelude
1672-
.iter()
1673-
.map(|(ident, _)| ident.name)
1672+
.keys()
1673+
.map(|ident| ident.name)
16741674
.chain(
16751675
self.module_map
16761676
.iter()
@@ -2007,7 +2007,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
20072007
// 1) some consistent ordering for emitted diagnostics, and
20082008
// 2) `std` suggestions before `core` suggestions.
20092009
let mut extern_crate_names =
2010-
self.extern_prelude.iter().map(|(ident, _)| ident.name).collect::<Vec<_>>();
2010+
self.extern_prelude.keys().map(|ident| ident.name).collect::<Vec<_>>();
20112011
extern_crate_names.sort_by(|a, b| b.as_str().partial_cmp(a.as_str()).unwrap());
20122012

20132013
for name in extern_crate_names.into_iter() {

compiler/rustc_resolve/src/ident.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
389389
}
390390
}
391391

392-
assert!(force || !finalize.is_some()); // `finalize` implies `force`
392+
assert!(force || finalize.is_none()); // `finalize` implies `force`
393393

394394
// Make sure `self`, `super` etc produce an error when passed to here.
395395
if orig_ident.is_path_segment_keyword() {

compiler/rustc_resolve/src/late.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -2421,8 +2421,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
24212421
.iter()
24222422
.rfind(|r| matches!(r.kind, ItemRibKind(_)))
24232423
.expect("associated item outside of an item");
2424-
seen_bindings
2425-
.extend(parent_rib.bindings.iter().map(|(ident, _)| (*ident, ident.span)));
2424+
seen_bindings.extend(parent_rib.bindings.keys().map(|ident| (*ident, ident.span)));
24262425
};
24272426
add_bindings_for_ns(ValueNS);
24282427
add_bindings_for_ns(TypeNS);

compiler/rustc_session/src/options.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -911,7 +911,7 @@ mod parse {
911911
let mut seen_instruction_threshold = false;
912912
let mut seen_skip_entry = false;
913913
let mut seen_skip_exit = false;
914-
for option in v.into_iter().map(|v| v.split(',')).flatten() {
914+
for option in v.into_iter().flat_map(|v| v.split(',')) {
915915
match option {
916916
"always" if !seen_always && !seen_never => {
917917
options.always = true;

compiler/rustc_trait_selection/src/traits/outlives_bounds.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,6 @@ impl<'a, 'tcx: 'a> InferCtxtExt<'a, 'tcx> for InferCtxt<'tcx> {
110110
body_id: LocalDefId,
111111
tys: FxIndexSet<Ty<'tcx>>,
112112
) -> Bounds<'a, 'tcx> {
113-
tys.into_iter()
114-
.map(move |ty| self.implied_outlives_bounds(param_env, body_id, ty))
115-
.flatten()
113+
tys.into_iter().flat_map(move |ty| self.implied_outlives_bounds(param_env, body_id, ty))
116114
}
117115
}

compiler/rustc_traits/src/chalk/lowering.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -909,8 +909,7 @@ pub(crate) fn collect_bound_vars<'tcx, T: TypeFoldable<TyCtxt<'tcx>>>(
909909
.or_else(|| bug!("Skipped bound var index: parameters={:?}", parameters));
910910
});
911911

912-
let binders =
913-
chalk_ir::VariableKinds::from_iter(interner, parameters.into_iter().map(|(_, v)| v));
912+
let binders = chalk_ir::VariableKinds::from_iter(interner, parameters.into_values());
914913

915914
(new_ty, binders, named_parameters)
916915
}

0 commit comments

Comments
 (0)