From 987656f5096c89377d4b58cda5e659f21437001f Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Thu, 19 Dec 2024 10:25:22 +0000 Subject: [PATCH] Remove a duplicated check that doesn't do anything anymore. --- compiler/rustc_hir_typeck/src/coercion.rs | 37 ------------------- tests/crashes/134005.rs | 5 --- .../ui/function-pointer/signature-mismatch.rs | 6 +++ .../signature-mismatch.stderr | 12 ++++++ 4 files changed, 18 insertions(+), 42 deletions(-) delete mode 100644 tests/crashes/134005.rs create mode 100644 tests/ui/function-pointer/signature-mismatch.rs create mode 100644 tests/ui/function-pointer/signature-mismatch.stderr diff --git a/compiler/rustc_hir_typeck/src/coercion.rs b/compiler/rustc_hir_typeck/src/coercion.rs index e3705945f33fc..541e16e42a7d9 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 c1f4c758a14ec..0000000000000 --- 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 0000000000000..f269e9bf84b31 --- /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 0000000000000..f02a576e511f5 --- /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`.