about summary refs log tree commit diff
diff options
context:
space:
mode:
authorOli Scherer <github333195615777966@oli-obk.de>2024-12-19 10:25:22 +0000
committerOli Scherer <github333195615777966@oli-obk.de>2024-12-19 10:56:31 +0000
commit987656f5096c89377d4b58cda5e659f21437001f (patch)
treecd3d897977d35d5077cce770361e45cfb8e78624
parent023521e6825edfa6df01e392520d7cb120eab158 (diff)
downloadrust-987656f5096c89377d4b58cda5e659f21437001f.tar.gz
rust-987656f5096c89377d4b58cda5e659f21437001f.zip
Remove a duplicated check that doesn't do anything anymore.
-rw-r--r--compiler/rustc_hir_typeck/src/coercion.rs37
-rw-r--r--tests/crashes/134005.rs5
-rw-r--r--tests/ui/function-pointer/signature-mismatch.rs6
-rw-r--r--tests/ui/function-pointer/signature-mismatch.stderr12
4 files changed, 18 insertions, 42 deletions
diff --git a/compiler/rustc_hir_typeck/src/coercion.rs b/compiler/rustc_hir_typeck/src/coercion.rs
index e3705945f33..541e16e42a7 100644
--- a/compiler/rustc_hir_typeck/src/coercion.rs
+++ b/compiler/rustc_hir_typeck/src/coercion.rs
@@ -1315,43 +1315,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
             }
         }
 
-        // Then try to coerce the previous expressions to the type of the new one.
-        // This requires ensuring there are no coercions applied to *any* of the
-        // previous expressions, other than noop reborrows (ignoring lifetimes).
-        for expr in exprs {
-            let expr = expr.as_coercion_site();
-            let noop = match self.typeck_results.borrow().expr_adjustments(expr) {
-                &[
-                    Adjustment { kind: Adjust::Deref(_), .. },
-                    Adjustment { kind: Adjust::Borrow(AutoBorrow::Ref(mutbl_adj)), .. },
-                ] => {
-                    match *self.node_ty(expr.hir_id).kind() {
-                        ty::Ref(_, _, mt_orig) => {
-                            let mutbl_adj: hir::Mutability = mutbl_adj.into();
-                            // Reborrow that we can safely ignore, because
-                            // the next adjustment can only be a Deref
-                            // which will be merged into it.
-                            mutbl_adj == mt_orig
-                        }
-                        _ => false,
-                    }
-                }
-                &[Adjustment { kind: Adjust::NeverToAny, .. }] | &[] => true,
-                _ => false,
-            };
-
-            if !noop {
-                debug!(
-                    "coercion::try_find_coercion_lub: older expression {:?} had adjustments, requiring LUB",
-                    expr,
-                );
-
-                return Err(self
-                    .commit_if_ok(|_| self.at(cause, self.param_env).lub(prev_ty, new_ty))
-                    .unwrap_err());
-            }
-        }
-
         match self.commit_if_ok(|_| coerce.coerce(prev_ty, new_ty)) {
             Err(_) => {
                 // Avoid giving strange errors on failed attempts.
diff --git a/tests/crashes/134005.rs b/tests/crashes/134005.rs
deleted file mode 100644
index c1f4c758a14..00000000000
--- a/tests/crashes/134005.rs
+++ /dev/null
@@ -1,5 +0,0 @@
-//@ known-bug: #134005
-
-fn main() {
-    let _ = [std::ops::Add::add, std::ops::Mul::mul, main as fn(_, &_)];
-}
diff --git a/tests/ui/function-pointer/signature-mismatch.rs b/tests/ui/function-pointer/signature-mismatch.rs
new file mode 100644
index 00000000000..f269e9bf84b
--- /dev/null
+++ b/tests/ui/function-pointer/signature-mismatch.rs
@@ -0,0 +1,6 @@
+//! This test used to hit an assertion instead of erroring and bailing out.
+
+fn main() {
+    let _ = [std::ops::Add::add, std::ops::Mul::mul, std::ops::Mul::mul as fn(_, &_)];
+    //~^ ERROR: mismatched types
+}
diff --git a/tests/ui/function-pointer/signature-mismatch.stderr b/tests/ui/function-pointer/signature-mismatch.stderr
new file mode 100644
index 00000000000..f02a576e511
--- /dev/null
+++ b/tests/ui/function-pointer/signature-mismatch.stderr
@@ -0,0 +1,12 @@
+error[E0308]: mismatched types
+  --> $DIR/signature-mismatch.rs:4:54
+   |
+LL |     let _ = [std::ops::Add::add, std::ops::Mul::mul, std::ops::Mul::mul as fn(_, &_)];
+   |                                                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ one type is more general than the other
+   |
+   = note: expected fn pointer `fn(_, _) -> _`
+              found fn pointer `for<'a> fn(_, &'a _) -> ()`
+
+error: aborting due to 1 previous error
+
+For more information about this error, try `rustc --explain E0308`.