@@ -20,6 +20,7 @@ use rustc_hir::def_id::DefId;
20
20
use rustc_hir::intravisit::Visitor;
21
21
use rustc_hir::lang_items::LangItem;
22
22
use rustc_hir::{AsyncGeneratorKind, GeneratorKind, Node};
23
+ use rustc_infer::infer::TyCtxtInferExt;
23
24
use rustc_middle::hir::map;
24
25
use rustc_middle::ty::{
25
26
self, suggest_arbitrary_trait_bound, suggest_constraining_type_param, AdtKind, DefIdTree,
@@ -253,8 +254,8 @@ pub trait InferCtxtExt<'tcx> {
253
254
&self,
254
255
span: Span,
255
256
found_span: Option<Span>,
256
- expected_ref: ty::PolyTraitRef<'tcx>,
257
257
found: ty::PolyTraitRef<'tcx>,
258
+ expected: ty::PolyTraitRef<'tcx>,
258
259
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed>;
259
260
260
261
fn suggest_fully_qualified_path(
@@ -1529,13 +1530,13 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
1529
1530
&self,
1530
1531
span: Span,
1531
1532
found_span: Option<Span>,
1532
- expected_ref: ty::PolyTraitRef<'tcx>,
1533
1533
found: ty::PolyTraitRef<'tcx>,
1534
+ expected: ty::PolyTraitRef<'tcx>,
1534
1535
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
1535
- pub(crate) fn build_fn_sig_string <'tcx>(
1536
+ pub(crate) fn build_fn_sig_ty <'tcx>(
1536
1537
tcx: TyCtxt<'tcx>,
1537
1538
trait_ref: ty::PolyTraitRef<'tcx>,
1538
- ) -> String {
1539
+ ) -> Ty<'tcx> {
1539
1540
let inputs = trait_ref.skip_binder().substs.type_at(1);
1540
1541
let sig = match inputs.kind() {
1541
1542
ty::Tuple(inputs)
@@ -1557,10 +1558,11 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
1557
1558
abi::Abi::Rust,
1558
1559
),
1559
1560
};
1560
- trait_ref.rebind(sig).to_string()
1561
+
1562
+ tcx.mk_fn_ptr(trait_ref.rebind(sig))
1561
1563
}
1562
1564
1563
- let argument_kind = match expected_ref .skip_binder().self_ty().kind() {
1565
+ let argument_kind = match expected .skip_binder().self_ty().kind() {
1564
1566
ty::Closure(..) => "closure",
1565
1567
ty::Generator(..) => "generator",
1566
1568
_ => "function",
@@ -1569,17 +1571,22 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
1569
1571
self.tcx.sess,
1570
1572
span,
1571
1573
E0631,
1572
- "type mismatch in {} arguments",
1573
- argument_kind
1574
+ "type mismatch in {argument_kind} arguments",
1574
1575
);
1575
1576
1576
- let found_str = format!("expected signature of `{}`", build_fn_sig_string(self.tcx, found));
1577
- err.span_label(span, found_str);
1577
+ err.span_label(span, "expected due to this");
1578
1578
1579
1579
let found_span = found_span.unwrap_or(span);
1580
- let expected_str =
1581
- format!("found signature of `{}`", build_fn_sig_string(self.tcx, expected_ref));
1582
- err.span_label(found_span, expected_str);
1580
+ err.span_label(found_span, "found signature defined here");
1581
+
1582
+ let expected = build_fn_sig_ty(self.tcx, expected);
1583
+ let found = build_fn_sig_ty(self.tcx, found);
1584
+
1585
+ let (expected_str, found_str) =
1586
+ self.tcx.infer_ctxt().enter(|infcx| infcx.cmp(expected, found));
1587
+
1588
+ let signature_kind = format!("{argument_kind} signature");
1589
+ err.note_expected_found(&signature_kind, expected_str, &signature_kind, found_str);
1583
1590
1584
1591
err
1585
1592
}
0 commit comments