diff --git a/compiler/rustc_trait_selection/src/error_reporting/infer/mod.rs b/compiler/rustc_trait_selection/src/error_reporting/infer/mod.rs
index 5a62a4c3bd5fe..ee5ce19cb4df6 100644
--- a/compiler/rustc_trait_selection/src/error_reporting/infer/mod.rs
+++ b/compiler/rustc_trait_selection/src/error_reporting/infer/mod.rs
@@ -824,7 +824,9 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
fn cmp_fn_sig(
&self,
sig1: &ty::PolyFnSig<'tcx>,
+ fn_def1: Option<(DefId, &'tcx [ty::GenericArg<'tcx>])>,
sig2: &ty::PolyFnSig<'tcx>,
+ fn_def2: Option<(DefId, &'tcx [ty::GenericArg<'tcx>])>,
) -> (DiagStyledString, DiagStyledString) {
let sig1 = &(self.normalize_fn_sig)(*sig1);
let sig2 = &(self.normalize_fn_sig)(*sig2);
@@ -930,6 +932,25 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
(values.1).0.extend(x2.0);
}
+ let fmt = |(did, args)| format!(" {{{}}}", self.tcx.def_path_str_with_args(did, args));
+
+ match (fn_def1, fn_def2) {
+ (None, None) => {}
+ (Some(fn_def1), Some(fn_def2)) => {
+ let path1 = fmt(fn_def1);
+ let path2 = fmt(fn_def2);
+ let same_path = path1 == path2;
+ values.0.push(path1, !same_path);
+ values.1.push(path2, !same_path);
+ }
+ (Some(fn_def1), None) => {
+ values.0.push_highlighted(fmt(fn_def1));
+ }
+ (None, Some(fn_def2)) => {
+ values.1.push_highlighted(fmt(fn_def2));
+ }
+ }
+
values
}
@@ -1318,36 +1339,21 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
(ty::FnDef(did1, args1), ty::FnDef(did2, args2)) => {
let sig1 = self.tcx.fn_sig(*did1).instantiate(self.tcx, args1);
let sig2 = self.tcx.fn_sig(*did2).instantiate(self.tcx, args2);
- let mut values = self.cmp_fn_sig(&sig1, &sig2);
- let path1 = format!(" {{{}}}", self.tcx.def_path_str_with_args(*did1, args1));
- let path2 = format!(" {{{}}}", self.tcx.def_path_str_with_args(*did2, args2));
- let same_path = path1 == path2;
- values.0.push(path1, !same_path);
- values.1.push(path2, !same_path);
- values
+ self.cmp_fn_sig(&sig1, Some((*did1, args1)), &sig2, Some((*did2, args2)))
}
(ty::FnDef(did1, args1), ty::FnPtr(sig_tys2, hdr2)) => {
let sig1 = self.tcx.fn_sig(*did1).instantiate(self.tcx, args1);
- let mut values = self.cmp_fn_sig(&sig1, &sig_tys2.with(*hdr2));
- values.0.push_highlighted(format!(
- " {{{}}}",
- self.tcx.def_path_str_with_args(*did1, args1)
- ));
- values
+ self.cmp_fn_sig(&sig1, Some((*did1, args1)), &sig_tys2.with(*hdr2), None)
}
(ty::FnPtr(sig_tys1, hdr1), ty::FnDef(did2, args2)) => {
let sig2 = self.tcx.fn_sig(*did2).instantiate(self.tcx, args2);
- let mut values = self.cmp_fn_sig(&sig_tys1.with(*hdr1), &sig2);
- values
- .1
- .push_normal(format!(" {{{}}}", self.tcx.def_path_str_with_args(*did2, args2)));
- values
+ self.cmp_fn_sig(&sig_tys1.with(*hdr1), None, &sig2, Some((*did2, args2)))
}
(ty::FnPtr(sig_tys1, hdr1), ty::FnPtr(sig_tys2, hdr2)) => {
- self.cmp_fn_sig(&sig_tys1.with(*hdr1), &sig_tys2.with(*hdr2))
+ self.cmp_fn_sig(&sig_tys1.with(*hdr1), None, &sig_tys2.with(*hdr2), None)
}
_ => {
@@ -2102,7 +2108,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
if exp_found.references_error() {
return None;
}
- let (exp, fnd) = self.cmp_fn_sig(&exp_found.expected, &exp_found.found);
+ let (exp, fnd) = self.cmp_fn_sig(&exp_found.expected, None, &exp_found.found, None);
Some((exp, fnd, None))
}
}
diff --git a/tests/ui/error-emitter/highlighting.svg b/tests/ui/error-emitter/highlighting.svg
index a4019c78f4841..68fc118f1a6e4 100644
--- a/tests/ui/error-emitter/highlighting.svg
+++ b/tests/ui/error-emitter/highlighting.svg
@@ -39,7 +39,7 @@
= note: expected fn pointer `for<'a> fn(Box<(dyn Any + Send + 'a)>) -> Pin<_>`
- found fn item `fn(Box<(dyn Any + Send + 'static)>) -> Pin<_> {wrapped_fn}`
+ found fn item `fn(Box<(dyn Any + Send + 'static)>) -> Pin<_> {wrapped_fn}`
note: function defined here
diff --git a/tests/ui/error-emitter/unicode-output.svg b/tests/ui/error-emitter/unicode-output.svg
index f98fd8b74032b..b253fff643b0f 100644
--- a/tests/ui/error-emitter/unicode-output.svg
+++ b/tests/ui/error-emitter/unicode-output.svg
@@ -39,7 +39,7 @@
╰ note: expected fn pointer `for<'a> fn(Box<(dyn Any + Send + 'a)>) -> Pin<_>`
- found fn item `fn(Box<(dyn Any + Send + 'static)>) -> Pin<_> {wrapped_fn}`
+ found fn item `fn(Box<(dyn Any + Send + 'static)>) -> Pin<_> {wrapped_fn}`
note: function defined here