From f80b12129ea8a58464a685abefd1f36819d3dd7b Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Thu, 10 Apr 2025 08:15:03 +0000 Subject: [PATCH] Avoid some more duplication --- compiler/rustc_hir_typeck/src/coercion.rs | 38 ++++++++--------------- 1 file changed, 13 insertions(+), 25 deletions(-) diff --git a/compiler/rustc_hir_typeck/src/coercion.rs b/compiler/rustc_hir_typeck/src/coercion.rs index ec198c25297..fd899425f62 100644 --- a/compiler/rustc_hir_typeck/src/coercion.rs +++ b/compiler/rustc_hir_typeck/src/coercion.rs @@ -586,17 +586,12 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> { // for the former and let type inference do the rest. let coerce_target = self.next_ty_var(self.cause.span); - let mut coercion = match reborrow { - None => { - self.unify_and(coerce_target, target, [], Adjust::Pointer(PointerCoercion::Unsize))? - } - Some((ref deref, ref autoref)) => self.unify_and( - coerce_target, - target, - [deref.clone(), autoref.clone()], - Adjust::Pointer(PointerCoercion::Unsize), - )?, - }; + let mut coercion = self.unify_and( + coerce_target, + target, + reborrow.into_iter().flat_map(|(deref, autoref)| [deref, autoref]), + Adjust::Pointer(PointerCoercion::Unsize), + )?; let mut selcx = traits::SelectionContext::new(self); @@ -836,20 +831,13 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> { && hdr_b.safety.is_unsafe() { let unsafe_a = self.tcx.safe_to_unsafe_fn_ty(fn_ty_a); - match adjustment { - Some(kind) => self.unify_and( - unsafe_a, - b, - [Adjustment { kind, target: Ty::new_fn_ptr(self.tcx, fn_ty_a) }], - Adjust::Pointer(PointerCoercion::UnsafeFnPointer), - ), - None => self.unify_and( - unsafe_a, - b, - [], - Adjust::Pointer(PointerCoercion::UnsafeFnPointer), - ), - } + self.unify_and( + unsafe_a, + b, + adjustment + .map(|kind| Adjustment { kind, target: Ty::new_fn_ptr(self.tcx, fn_ty_a) }), + Adjust::Pointer(PointerCoercion::UnsafeFnPointer), + ) } else { let a = Ty::new_fn_ptr(self.tcx, fn_ty_a); match adjustment {