Skip to content

Commit 5a07e33

Browse files
committed
use and_then/flat_map for map().flatten()
1 parent ac229c2 commit 5a07e33

File tree

5 files changed

+7
-10
lines changed

5 files changed

+7
-10
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_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_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
}

0 commit comments

Comments
 (0)