mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-07 12:33:14 +00:00
use and_then/flat_map for map().flatten()
This commit is contained in:
parent
ac229c2819
commit
5a07e33d2c
@ -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 {
|
||||
|
@ -79,7 +79,7 @@ impl<'tcx> ValTree<'tcx> {
|
||||
}
|
||||
|
||||
pub fn try_to_target_usize(self, tcx: TyCtxt<'tcx>) -> Option<u64> {
|
||||
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
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -110,8 +110,6 @@ impl<'a, 'tcx: 'a> InferCtxtExt<'a, 'tcx> for InferCtxt<'tcx> {
|
||||
body_id: LocalDefId,
|
||||
tys: FxIndexSet<Ty<'tcx>>,
|
||||
) -> 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))
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user