Rollup merge of #123379 - wutchzone:119266, r=compiler-errors

Print note with closure signature on type mismatch

Fixes #119266

r? Nilstrieb
This commit is contained in:
许杰友 Jieyou Xu (Joe) 2024-04-20 21:45:34 +01:00 committed by GitHub
commit e9e936cfa8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 48 additions and 2 deletions

View file

@ -61,7 +61,7 @@ use crate::traits::{
use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
use rustc_errors::{
codes::*, pluralize, struct_span_code_err, Applicability, Diag, DiagCtxt, DiagStyledString,
ErrorGuaranteed, IntoDiagArg,
ErrorGuaranteed, IntoDiagArg, StringPart,
};
use rustc_hir as hir;
use rustc_hir::def::DefKind;
@ -1917,6 +1917,23 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
);
if !is_simple_error || terr.must_include_note() {
diag.note_expected_found(&expected_label, expected, &found_label, found);
if let Some(ty::Closure(_, args)) =
exp_found.map(|expected_type_found| expected_type_found.found.kind())
{
diag.highlighted_note(vec![
StringPart::normal("closure has signature: `"),
StringPart::highlighted(
self.tcx
.signature_unclosure(
args.as_closure().sig(),
rustc_hir::Unsafety::Normal,
)
.to_string(),
),
StringPart::normal("`"),
]);
}
}
}
}