about summary refs log tree commit diff
diff options
context:
space:
mode:
authorOli Scherer <github333195615777966@oli-obk.de>2025-04-10 08:15:03 +0000
committerOli Scherer <github333195615777966@oli-obk.de>2025-04-10 08:19:12 +0000
commitf80b12129ea8a58464a685abefd1f36819d3dd7b (patch)
tree253eaa72fd3520793b497e78508c8ae25100167c
parent673012faf7085d426d6598b8e445ad8630921723 (diff)
downloadrust-f80b12129ea8a58464a685abefd1f36819d3dd7b.tar.gz
rust-f80b12129ea8a58464a685abefd1f36819d3dd7b.zip
Avoid some more duplication
-rw-r--r--compiler/rustc_hir_typeck/src/coercion.rs38
1 files 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 {