1
Fork 0

wrap fn sig binders in fn ptr

This commit is contained in:
Eduardo Sánchez Muñoz 2023-09-19 21:15:58 +02:00
parent c599761140
commit 85d61b01ae
3 changed files with 13 additions and 28 deletions

View file

@ -568,18 +568,15 @@ pub fn check_function_signature<'tcx>(
let infcx = &tcx.infer_ctxt().build(); let infcx = &tcx.infer_ctxt().build();
let ocx = ObligationCtxt::new(infcx); let ocx = ObligationCtxt::new(infcx);
let unnormalized_actual_sig = infcx.instantiate_binder_with_fresh_vars( let actual_sig = tcx.fn_sig(fn_id).instantiate_identity();
cause.span,
infer::HigherRankedType,
tcx.fn_sig(fn_id).instantiate_identity(),
);
let norm_cause = ObligationCause::misc(cause.span, local_id); 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(()) => { Ok(()) => {
let errors = ocx.select_all_or_error(); let errors = ocx.select_all_or_error();
if !errors.is_empty() { if !errors.is_empty() {
@ -599,8 +596,8 @@ pub fn check_function_signature<'tcx>(
&cause, &cause,
None, None,
Some(infer::ValuePairs::Sigs(ExpectedFound { Some(infer::ValuePairs::Sigs(ExpectedFound {
expected: expected_sig, expected: tcx.liberate_late_bound_regions(fn_id, expected_sig),
found: actual_sig, found: tcx.liberate_late_bound_regions(fn_id, actual_sig),
})), })),
err, err,
false, false,

View file

@ -2,16 +2,10 @@ error[E0308]: `#[panic_handler]` function has wrong type
--> $DIR/panic-handler-bad-signature-2.rs:9:1 --> $DIR/panic-handler-bad-signature-2.rs:9:1
| |
LL | fn panic(info: &'static PanicInfo) -> ! LL | fn panic(info: &'static PanicInfo) -> !
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ lifetime mismatch | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ one type is more general than the other
| |
= note: expected signature `fn(&PanicInfo<'_>) -> _` = note: expected fn pointer `for<'a, 'b> fn(&'a PanicInfo<'b>) -> _`
found signature `fn(&'static PanicInfo<'_>) -> _` found fn pointer `for<'a> fn(&'static PanicInfo<'a>) -> _`
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
error: aborting due to previous error error: aborting due to previous error

View file

@ -2,16 +2,10 @@ error[E0308]: `#[panic_handler]` function has wrong type
--> $DIR/panic-handler-bad-signature-5.rs:9:1 --> $DIR/panic-handler-bad-signature-5.rs:9:1
| |
LL | fn panic(info: &PanicInfo<'static>) -> ! LL | fn panic(info: &PanicInfo<'static>) -> !
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ lifetime mismatch | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ one type is more general than the other
| |
= note: expected signature `fn(&PanicInfo<'_>) -> _` = note: expected fn pointer `for<'a, 'b> fn(&'a PanicInfo<'b>) -> _`
found signature `fn(&PanicInfo<'static>) -> _` found fn pointer `for<'a> fn(&'a 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
error: aborting due to previous error error: aborting due to previous error