]> git.lizzy.rs Git - rust.git/blobdiff - compiler/rustc_typeck/src/check/coercion.rs
Auto merge of #87794 - bonega:enum_niche_prefer_zero, r=nagisa
[rust.git] / compiler / rustc_typeck / src / check / coercion.rs
index 3bfab9d513f375e6540a3f7471f3c3342d172485..6fe96e4cc27b2f0811939203903e8379b1cc5f4c 100644 (file)
@@ -1003,6 +1003,12 @@ fn try_find_coercion_lub<E>(
             exprs.len()
         );
 
+        // The following check fixes #88097, where the compiler erroneously
+        // attempted to coerce a closure type to itself via a function pointer.
+        if prev_ty == new_ty {
+            return Ok(prev_ty);
+        }
+
         // Special-case that coercion alone cannot handle:
         // Function items or non-capturing closures of differing IDs or InternalSubsts.
         let (a_sig, b_sig) = {