1
Fork 0

Reduce indentation by replacing match arm w/ early return.

This commit is contained in:
jumbatm 2020-08-16 10:50:20 +10:00
parent 80c2c80d52
commit bca48ad7ac

View file

@ -2198,12 +2198,14 @@ impl ClashingExternDeclarations {
debug!("structurally_same_type_impl(cx, a = {:?}, b = {:?})", a, b); debug!("structurally_same_type_impl(cx, a = {:?}, b = {:?})", a, b);
match seen_types.get(a, b) { match seen_types.get(a, b) {
// If we've already computed the result, just return the memoized result. // If we've already computed the result, just return the memoized result.
SeenSetResult::Computed(result) => result, SeenSetResult::Computed(result) => return result,
// We are already in the process of computing structural sameness for this type, // We are already in the process of computing structural sameness for this type,
// meaning we've found a cycle. The types are structurally same, then. // meaning we've found a cycle. The types are structurally same, then.
SeenSetResult::Computing => true, SeenSetResult::Computing => return true,
// We haven't seen this combination of types at all -- compute their sameness. // We haven't seen this combination of types at all -- continue on to computing
SeenSetResult::Unseen => { // their sameness.
SeenSetResult::Unseen => (),
}
seen_types.mark_computing(a, b); seen_types.mark_computing(a, b);
let tcx = cx.tcx; let tcx = cx.tcx;
let result = if a == b || rustc_middle::ty::TyS::same_type(a, b) { let result = if a == b || rustc_middle::ty::TyS::same_type(a, b) {
@ -2223,9 +2225,8 @@ impl ClashingExternDeclarations {
}; };
#[allow(rustc::usage_of_ty_tykind)] #[allow(rustc::usage_of_ty_tykind)]
let is_primitive_or_pointer = |kind: &ty::TyKind<'_>| { let is_primitive_or_pointer =
kind.is_primitive() || matches!(kind, RawPtr(..)) |kind: &ty::TyKind<'_>| kind.is_primitive() || matches!(kind, RawPtr(..));
};
match (a_kind, b_kind) { match (a_kind, b_kind) {
(Adt(a_def, a_substs), Adt(b_def, b_substs)) => { (Adt(a_def, a_substs), Adt(b_def, b_substs)) => {
@ -2254,9 +2255,7 @@ impl ClashingExternDeclarations {
(Array(a_ty, a_const), Array(b_ty, b_const)) => { (Array(a_ty, a_const), Array(b_ty, b_const)) => {
// For arrays, we also check the constness of the type. // For arrays, we also check the constness of the type.
a_const.val == b_const.val a_const.val == b_const.val
&& structurally_same_type_impl( && structurally_same_type_impl(seen_types, cx, a_ty, b_ty, ckind)
seen_types, cx, a_ty, b_ty, ckind,
)
} }
(Slice(a_ty), Slice(b_ty)) => { (Slice(a_ty), Slice(b_ty)) => {
structurally_same_type_impl(seen_types, cx, a_ty, b_ty, ckind) structurally_same_type_impl(seen_types, cx, a_ty, b_ty, ckind)
@ -2274,9 +2273,7 @@ impl ClashingExternDeclarations {
(Ref(_a_region, a_ty, a_mut), Ref(_b_region, b_ty, b_mut)) => { (Ref(_a_region, a_ty, a_mut), Ref(_b_region, b_ty, b_mut)) => {
// For structural sameness, we don't need the region to be same. // For structural sameness, we don't need the region to be same.
a_mut == b_mut a_mut == b_mut
&& structurally_same_type_impl( && structurally_same_type_impl(seen_types, cx, a_ty, b_ty, ckind)
seen_types, cx, a_ty, b_ty, ckind,
)
} }
(FnDef(..), FnDef(..)) => { (FnDef(..), FnDef(..)) => {
let a_poly_sig = a.fn_sig(tcx); let a_poly_sig = a.fn_sig(tcx);
@ -2316,9 +2313,7 @@ impl ClashingExternDeclarations {
| (Opaque(..), Opaque(..)) => false, | (Opaque(..), Opaque(..)) => false,
// These definitely should have been caught above. // These definitely should have been caught above.
(Bool, Bool) | (Char, Char) | (Never, Never) | (Str, Str) => { (Bool, Bool) | (Char, Char) | (Never, Never) | (Str, Str) => unreachable!(),
unreachable!()
}
// An Adt and a primitive type. This can be FFI-safe is the ADT is an enum with a // An Adt and a primitive type. This can be FFI-safe is the ADT is an enum with a
// non-null field. // non-null field.
@ -2342,8 +2337,6 @@ impl ClashingExternDeclarations {
seen_types.mark_computed(a, b, result); seen_types.mark_computed(a, b, result);
result result
} }
}
}
let mut seen_types = SeenSet::new(); let mut seen_types = SeenSet::new();
structurally_same_type_impl(&mut seen_types, cx, a, b, ckind) structurally_same_type_impl(&mut seen_types, cx, a, b, ckind)
} }