Skip to content

Allow higher-ranked fn sigs in ValuePairs #116073

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 24, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion compiler/rustc_hir_analysis/src/check/compare_impl_item.rs
Original file line number Diff line number Diff line change
@@ -1134,7 +1134,10 @@ fn report_trait_method_mismatch<'tcx>(
&mut diag,
&cause,
trait_err_span.map(|sp| (sp, Cow::from("type in trait"))),
Some(infer::ValuePairs::Sigs(ExpectedFound { expected: trait_sig, found: impl_sig })),
Some(infer::ValuePairs::PolySigs(ExpectedFound {
expected: ty::Binder::dummy(trait_sig),
found: ty::Binder::dummy(impl_sig),
})),
terr,
false,
false,
11 changes: 4 additions & 7 deletions compiler/rustc_hir_analysis/src/check/mod.rs
Original file line number Diff line number Diff line change
@@ -573,10 +573,7 @@ pub fn check_function_signature<'tcx>(
let norm_cause = ObligationCause::misc(cause.span, local_id);
let actual_sig = ocx.normalize(&norm_cause, param_env, actual_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_ty, actual_ty) {
match ocx.eq(&cause, param_env, expected_sig, actual_sig) {
Ok(()) => {
let errors = ocx.select_all_or_error();
if !errors.is_empty() {
@@ -595,9 +592,9 @@ pub fn check_function_signature<'tcx>(
&mut diag,
&cause,
None,
Some(infer::ValuePairs::Sigs(ExpectedFound {
expected: tcx.liberate_late_bound_regions(fn_id, expected_sig),
found: tcx.liberate_late_bound_regions(fn_id, actual_sig),
Some(infer::ValuePairs::PolySigs(ExpectedFound {
expected: expected_sig,
found: actual_sig,
})),
err,
false,
23 changes: 22 additions & 1 deletion compiler/rustc_infer/src/infer/at.rs
Original file line number Diff line number Diff line change
@@ -478,7 +478,28 @@ impl<'tcx> ToTrace<'tcx> for ty::FnSig<'tcx> {
a: Self,
b: Self,
) -> TypeTrace<'tcx> {
TypeTrace { cause: cause.clone(), values: Sigs(ExpectedFound::new(a_is_expected, a, b)) }
TypeTrace {
cause: cause.clone(),
values: PolySigs(ExpectedFound::new(
a_is_expected,
ty::Binder::dummy(a),
ty::Binder::dummy(b),
)),
}
}
}

impl<'tcx> ToTrace<'tcx> for ty::PolyFnSig<'tcx> {
fn to_trace(
cause: &ObligationCause<'tcx>,
a_is_expected: bool,
a: Self,
b: Self,
) -> TypeTrace<'tcx> {
TypeTrace {
cause: cause.clone(),
values: PolySigs(ExpectedFound::new(a_is_expected, a, b)),
}
}
}

9 changes: 3 additions & 6 deletions compiler/rustc_infer/src/infer/error_reporting/mod.rs
Original file line number Diff line number Diff line change
@@ -1660,7 +1660,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
_ => (false, Mismatch::Fixed("type")),
}
}
ValuePairs::Sigs(infer::ExpectedFound { expected, found }) => {
ValuePairs::PolySigs(infer::ExpectedFound { expected, found }) => {
OpaqueTypesVisitor::visit_expected_found(self.tcx, expected, found, span)
.report(diag);
(false, Mismatch::Fixed("signature"))
@@ -2232,15 +2232,12 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
ret => ret,
}
}
infer::Sigs(exp_found) => {
infer::PolySigs(exp_found) => {
let exp_found = self.resolve_vars_if_possible(exp_found);
if exp_found.references_error() {
return None;
}
let (exp, fnd) = self.cmp_fn_sig(
&ty::Binder::dummy(exp_found.expected),
&ty::Binder::dummy(exp_found.found),
);
let (exp, fnd) = self.cmp_fn_sig(&exp_found.expected, &exp_found.found);
Some((exp, fnd, None, None))
}
}
Original file line number Diff line number Diff line change
@@ -35,14 +35,14 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
&& let (Subtype(sup_trace), Subtype(sub_trace)) = (&sup_origin, &sub_origin)
&& let CompareImplItemObligation { trait_item_def_id, .. } = sub_trace.cause.code()
&& sub_trace.values == sup_trace.values
&& let ValuePairs::Sigs(ExpectedFound { expected, found }) = sub_trace.values
&& let ValuePairs::PolySigs(ExpectedFound { expected, found }) = sub_trace.values
{
// FIXME(compiler-errors): Don't like that this needs `Ty`s, but
// all of the region highlighting machinery only deals with those.
let guar = self.emit_err(
var_origin.span(),
Ty::new_fn_ptr(self.cx.tcx,ty::Binder::dummy(expected)),
Ty::new_fn_ptr(self.cx.tcx,ty::Binder::dummy(found)),
Ty::new_fn_ptr(self.cx.tcx, expected),
Ty::new_fn_ptr(self.cx.tcx, found),
*trait_item_def_id,
);
return Some(guar);
2 changes: 1 addition & 1 deletion compiler/rustc_infer/src/infer/mod.rs
Original file line number Diff line number Diff line change
@@ -383,7 +383,7 @@ pub enum ValuePairs<'tcx> {
Aliases(ExpectedFound<ty::AliasTy<'tcx>>),
TraitRefs(ExpectedFound<ty::TraitRef<'tcx>>),
PolyTraitRefs(ExpectedFound<ty::PolyTraitRef<'tcx>>),
Sigs(ExpectedFound<ty::FnSig<'tcx>>),
PolySigs(ExpectedFound<ty::PolyFnSig<'tcx>>),
ExistentialTraitRef(ExpectedFound<ty::PolyExistentialTraitRef<'tcx>>),
ExistentialProjection(ExpectedFound<ty::PolyExistentialProjection<'tcx>>),
}
5 changes: 4 additions & 1 deletion compiler/rustc_passes/src/check_attr.rs
Original file line number Diff line number Diff line change
@@ -2333,7 +2333,10 @@ impl CheckAttrVisitor<'_> {
&mut diag,
&cause,
None,
Some(ValuePairs::Sigs(ExpectedFound { expected: expected_sig, found: sig })),
Some(ValuePairs::PolySigs(ExpectedFound {
expected: ty::Binder::dummy(expected_sig),
found: ty::Binder::dummy(sig),
})),
terr,
false,
false,
4 changes: 2 additions & 2 deletions tests/ui/panic-handler/panic-handler-bad-signature-1.stderr
Original file line number Diff line number Diff line change
@@ -4,8 +4,8 @@ error[E0308]: `#[panic_handler]` function has wrong type
LL | fn panic(info: PanicInfo) -> () {}
| ^^^^^^^^^ expected `&PanicInfo<'_>`, found `PanicInfo<'_>`
|
= note: expected signature `fn(&PanicInfo<'_>) -> !`
found signature `fn(PanicInfo<'_>)`
= note: expected signature `for<'a, 'b> fn(&'a PanicInfo<'b>) -> !`
found signature `for<'a> fn(PanicInfo<'a>)`

error: aborting due to previous error

4 changes: 2 additions & 2 deletions tests/ui/panic-handler/panic-handler-bad-signature-2.stderr
Original file line number Diff line number Diff line change
@@ -4,8 +4,8 @@ error[E0308]: `#[panic_handler]` function has wrong type
LL | fn panic(info: &'static PanicInfo) -> !
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ one type is more general than the other
|
= note: expected fn pointer `for<'a, 'b> fn(&'a PanicInfo<'b>) -> _`
found fn pointer `for<'a> fn(&'static PanicInfo<'a>) -> _`
= note: expected signature `for<'a, 'b> fn(&'a PanicInfo<'b>) -> _`
found signature `for<'a> fn(&'static PanicInfo<'a>) -> _`

error: aborting due to previous error

Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ error[E0308]: `#[panic_handler]` function has wrong type
LL | fn panic() -> ! {
| ^^^^^^^^^^^^^^^ incorrect number of function parameters
|
= note: expected signature `fn(&PanicInfo<'_>) -> _`
= note: expected signature `for<'a, 'b> fn(&'a PanicInfo<'b>) -> _`
found signature `fn() -> _`

error: aborting due to previous error
4 changes: 2 additions & 2 deletions tests/ui/panic-handler/panic-handler-bad-signature-5.stderr
Original file line number Diff line number Diff line change
@@ -4,8 +4,8 @@ error[E0308]: `#[panic_handler]` function has wrong type
LL | fn panic(info: &PanicInfo<'static>) -> !
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ one type is more general than the other
|
= note: expected fn pointer `for<'a, 'b> fn(&'a PanicInfo<'b>) -> _`
found fn pointer `for<'a> fn(&'a PanicInfo<'static>) -> _`
= note: expected signature `for<'a, 'b> fn(&'a PanicInfo<'b>) -> _`
found signature `for<'a> fn(&'a PanicInfo<'static>) -> _`

error: aborting due to previous error