about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEduardo Sánchez Muñoz <eduardosm-dev@e64.io>2023-09-19 21:15:58 +0200
committerEduardo Sánchez Muñoz <eduardosm-dev@e64.io>2023-09-19 21:15:58 +0200
commit85d61b01aea90d9201c35c4bd61a508c72807c92 (patch)
tree42aa6d4d278e7545f9d084e0fa6241da8ddad4bd
parentc599761140ed1e3824a10d556395f178617e076a (diff)
downloadrust-85d61b01aea90d9201c35c4bd61a508c72807c92.tar.gz
rust-85d61b01aea90d9201c35c4bd61a508c72807c92.zip
wrap fn sig binders in fn ptr
-rw-r--r--compiler/rustc_hir_analysis/src/check/mod.rs17
-rw-r--r--tests/ui/panic-handler/panic-handler-bad-signature-2.stderr12
-rw-r--r--tests/ui/panic-handler/panic-handler-bad-signature-5.stderr12
3 files changed, 13 insertions, 28 deletions
diff --git a/compiler/rustc_hir_analysis/src/check/mod.rs b/compiler/rustc_hir_analysis/src/check/mod.rs
index b9ce4c07922..0cf3cee66b5 100644
--- a/compiler/rustc_hir_analysis/src/check/mod.rs
+++ b/compiler/rustc_hir_analysis/src/check/mod.rs
@@ -568,18 +568,15 @@ pub fn check_function_signature<'tcx>(
     let infcx = &tcx.infer_ctxt().build();
     let ocx = ObligationCtxt::new(infcx);
 
-    let unnormalized_actual_sig = infcx.instantiate_binder_with_fresh_vars(
-        cause.span,
-        infer::HigherRankedType,
-        tcx.fn_sig(fn_id).instantiate_identity(),
-    );
+    let actual_sig = tcx.fn_sig(fn_id).instantiate_identity();
 
     let norm_cause = ObligationCause::misc(cause.span, local_id);
-    let actual_sig = ocx.normalize(&norm_cause, param_env, unnormalized_actual_sig);
+    let actual_sig = ocx.normalize(&norm_cause, param_env, actual_sig);
 
-    let expected_sig = tcx.liberate_late_bound_regions(fn_id, expected_sig);
+    let expected_ty = Ty::new_fn_ptr(tcx, expected_sig);
+    let actual_ty = Ty::new_fn_ptr(tcx, actual_sig);
 
-    match ocx.eq(&cause, param_env, expected_sig, actual_sig) {
+    match ocx.eq(&cause, param_env, expected_ty, actual_ty) {
         Ok(()) => {
             let errors = ocx.select_all_or_error();
             if !errors.is_empty() {
@@ -599,8 +596,8 @@ pub fn check_function_signature<'tcx>(
                 &cause,
                 None,
                 Some(infer::ValuePairs::Sigs(ExpectedFound {
-                    expected: expected_sig,
-                    found: actual_sig,
+                    expected: tcx.liberate_late_bound_regions(fn_id, expected_sig),
+                    found: tcx.liberate_late_bound_regions(fn_id, actual_sig),
                 })),
                 err,
                 false,
diff --git a/tests/ui/panic-handler/panic-handler-bad-signature-2.stderr b/tests/ui/panic-handler/panic-handler-bad-signature-2.stderr
index 37c737d974d..06e32d5fb84 100644
--- a/tests/ui/panic-handler/panic-handler-bad-signature-2.stderr
+++ b/tests/ui/panic-handler/panic-handler-bad-signature-2.stderr
@@ -2,16 +2,10 @@ error[E0308]: `#[panic_handler]` function has wrong type
   --> $DIR/panic-handler-bad-signature-2.rs:9:1
    |
 LL | fn panic(info: &'static PanicInfo) -> !
-   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ lifetime mismatch
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ one type is more general than the other
    |
-   = note: expected signature `fn(&PanicInfo<'_>) -> _`
-              found signature `fn(&'static PanicInfo<'_>) -> _`
-note: the anonymous lifetime as defined here...
-  --> $DIR/panic-handler-bad-signature-2.rs:9:1
-   |
-LL | fn panic(info: &'static PanicInfo) -> !
-   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-   = note: ...does not necessarily outlive the static lifetime
+   = note: expected fn pointer `for<'a, 'b> fn(&'a PanicInfo<'b>) -> _`
+              found fn pointer `for<'a> fn(&'static PanicInfo<'a>) -> _`
 
 error: aborting due to previous error
 
diff --git a/tests/ui/panic-handler/panic-handler-bad-signature-5.stderr b/tests/ui/panic-handler/panic-handler-bad-signature-5.stderr
index 2745c05834c..22b8d5ca811 100644
--- a/tests/ui/panic-handler/panic-handler-bad-signature-5.stderr
+++ b/tests/ui/panic-handler/panic-handler-bad-signature-5.stderr
@@ -2,16 +2,10 @@ error[E0308]: `#[panic_handler]` function has wrong type
   --> $DIR/panic-handler-bad-signature-5.rs:9:1
    |
 LL | fn panic(info: &PanicInfo<'static>) -> !
-   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ lifetime mismatch
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ one type is more general than the other
    |
-   = note: expected signature `fn(&PanicInfo<'_>) -> _`
-              found signature `fn(&PanicInfo<'static>) -> _`
-note: the anonymous lifetime as defined here...
-  --> $DIR/panic-handler-bad-signature-5.rs:9:1
-   |
-LL | fn panic(info: &PanicInfo<'static>) -> !
-   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-   = note: ...does not necessarily outlive the static lifetime
+   = note: expected fn pointer `for<'a, 'b> fn(&'a PanicInfo<'b>) -> _`
+              found fn pointer `for<'a> fn(&'a PanicInfo<'static>) -> _`
 
 error: aborting due to previous error