From 8ef3bf29fe47f770a52090212e3a50a0e2bc87f5 Mon Sep 17 00:00:00 2001 From: Matthias Krüger Date: Sat, 1 Apr 2023 23:16:33 +0200 Subject: a couple clippy::complexity fixes map_identity filter_next option_as_ref_deref unnecessary_find_map redundant_slicing unnecessary_unwrap bool_comparison derivable_impls manual_flatten needless_borrowed_reference --- compiler/rustc_codegen_llvm/src/builder.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'compiler/rustc_codegen_llvm/src') diff --git a/compiler/rustc_codegen_llvm/src/builder.rs b/compiler/rustc_codegen_llvm/src/builder.rs index 580451ba265..63e8a67db53 100644 --- a/compiler/rustc_codegen_llvm/src/builder.rs +++ b/compiler/rustc_codegen_llvm/src/builder.rs @@ -1190,8 +1190,8 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { // Set KCFI operand bundle let is_indirect_call = unsafe { llvm::LLVMIsAFunction(llfn).is_none() }; let kcfi_bundle = - if self.tcx.sess.is_sanitizer_kcfi_enabled() && fn_abi.is_some() && is_indirect_call { - let kcfi_typeid = kcfi_typeid_for_fnabi(self.tcx, fn_abi.unwrap()); + if let Some(fn_abi) = fn_abi && self.tcx.sess.is_sanitizer_kcfi_enabled() && is_indirect_call { + let kcfi_typeid = kcfi_typeid_for_fnabi(self.tcx, fn_abi); Some(llvm::OperandBundleDef::new("kcfi", &[self.const_u32(kcfi_typeid)])) } else { None -- cgit 1.4.1-3-g733a5 From 5a07e33d2cc57d929bbd50a22cad703d4c666fc2 Mon Sep 17 00:00:00 2001 From: Matthias Krüger Date: Sat, 1 Apr 2023 23:50:45 +0200 Subject: use and_then/flat_map for map().flatten() --- compiler/rustc_codegen_llvm/src/common.rs | 3 +-- compiler/rustc_middle/src/ty/consts/valtree.rs | 2 +- compiler/rustc_mir_build/src/build/expr/as_constant.rs | 6 +++--- compiler/rustc_session/src/options.rs | 2 +- compiler/rustc_trait_selection/src/traits/outlives_bounds.rs | 4 +--- 5 files changed, 7 insertions(+), 10 deletions(-) (limited to 'compiler/rustc_codegen_llvm/src') diff --git a/compiler/rustc_codegen_llvm/src/common.rs b/compiler/rustc_codegen_llvm/src/common.rs index efa0c13226e..4f8b5abd901 100644 --- a/compiler/rustc_codegen_llvm/src/common.rs +++ b/compiler/rustc_codegen_llvm/src/common.rs @@ -378,8 +378,7 @@ pub(crate) fn get_dllimport<'tcx>( name: &str, ) -> Option<&'tcx DllImport> { tcx.native_library(id) - .map(|lib| lib.dll_imports.iter().find(|di| di.name.as_str() == name)) - .flatten() + .and_then(|lib| lib.dll_imports.iter().find(|di| di.name.as_str() == name)) } pub(crate) fn is_mingw_gnu_toolchain(target: &Target) -> bool { diff --git a/compiler/rustc_middle/src/ty/consts/valtree.rs b/compiler/rustc_middle/src/ty/consts/valtree.rs index 5ed4af2e922..8b96864ddd7 100644 --- a/compiler/rustc_middle/src/ty/consts/valtree.rs +++ b/compiler/rustc_middle/src/ty/consts/valtree.rs @@ -79,7 +79,7 @@ impl<'tcx> ValTree<'tcx> { } pub fn try_to_target_usize(self, tcx: TyCtxt<'tcx>) -> Option { - self.try_to_scalar_int().map(|s| s.try_to_target_usize(tcx).ok()).flatten() + self.try_to_scalar_int().and_then(|s| s.try_to_target_usize(tcx).ok()) } /// Get the values inside the ValTree as a slice of bytes. This only works for diff --git a/compiler/rustc_mir_build/src/build/expr/as_constant.rs b/compiler/rustc_mir_build/src/build/expr/as_constant.rs index cfacb5ea327..99291740ac8 100644 --- a/compiler/rustc_mir_build/src/build/expr/as_constant.rs +++ b/compiler/rustc_mir_build/src/build/expr/as_constant.rs @@ -62,21 +62,21 @@ pub fn as_constant_inner<'tcx>( Constant { span, user_ty: None, literal } } ExprKind::NonHirLiteral { lit, ref user_ty } => { - let user_ty = user_ty.as_ref().map(push_cuta).flatten(); + let user_ty = user_ty.as_ref().and_then(push_cuta); let literal = ConstantKind::Val(ConstValue::Scalar(Scalar::Int(lit)), ty); Constant { span, user_ty, literal } } ExprKind::ZstLiteral { ref user_ty } => { - let user_ty = user_ty.as_ref().map(push_cuta).flatten(); + let user_ty = user_ty.as_ref().and_then(push_cuta); let literal = ConstantKind::Val(ConstValue::ZeroSized, ty); Constant { span, user_ty, literal } } ExprKind::NamedConst { def_id, substs, ref user_ty } => { - let user_ty = user_ty.as_ref().map(push_cuta).flatten(); + let user_ty = user_ty.as_ref().and_then(push_cuta); let uneval = mir::UnevaluatedConst::new(ty::WithOptConstParam::unknown(def_id), substs); let literal = ConstantKind::Unevaluated(uneval, ty); diff --git a/compiler/rustc_session/src/options.rs b/compiler/rustc_session/src/options.rs index c75af48e80a..be5d4fca7a0 100644 --- a/compiler/rustc_session/src/options.rs +++ b/compiler/rustc_session/src/options.rs @@ -911,7 +911,7 @@ mod parse { let mut seen_instruction_threshold = false; let mut seen_skip_entry = false; let mut seen_skip_exit = false; - for option in v.into_iter().map(|v| v.split(',')).flatten() { + for option in v.into_iter().flat_map(|v| v.split(',')) { match option { "always" if !seen_always && !seen_never => { options.always = true; diff --git a/compiler/rustc_trait_selection/src/traits/outlives_bounds.rs b/compiler/rustc_trait_selection/src/traits/outlives_bounds.rs index 6d2dc94845d..cff3d277a78 100644 --- a/compiler/rustc_trait_selection/src/traits/outlives_bounds.rs +++ b/compiler/rustc_trait_selection/src/traits/outlives_bounds.rs @@ -110,8 +110,6 @@ impl<'a, 'tcx: 'a> InferCtxtExt<'a, 'tcx> for InferCtxt<'tcx> { body_id: LocalDefId, tys: FxIndexSet>, ) -> Bounds<'a, 'tcx> { - tys.into_iter() - .map(move |ty| self.implied_outlives_bounds(param_env, body_id, ty)) - .flatten() + tys.into_iter().flat_map(move |ty| self.implied_outlives_bounds(param_env, body_id, ty)) } } -- cgit 1.4.1-3-g733a5