Skip to content

Commit d778dda

Browse files
authored
Rollup merge of #134354 - oli-obk:push-nlrxswvpqnuk, r=compiler-errors
Handle fndef rendering together with signature rendering Pulled out of #134353 Changes some highlighting in type mismatch errors around fndefs
2 parents 0499232 + cd104a7 commit d778dda

File tree

3 files changed

+28
-22
lines changed

3 files changed

+28
-22
lines changed

compiler/rustc_trait_selection/src/error_reporting/infer/mod.rs

+26-20
Original file line numberDiff line numberDiff line change
@@ -824,7 +824,9 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
824824
fn cmp_fn_sig(
825825
&self,
826826
sig1: &ty::PolyFnSig<'tcx>,
827+
fn_def1: Option<(DefId, &'tcx [ty::GenericArg<'tcx>])>,
827828
sig2: &ty::PolyFnSig<'tcx>,
829+
fn_def2: Option<(DefId, &'tcx [ty::GenericArg<'tcx>])>,
828830
) -> (DiagStyledString, DiagStyledString) {
829831
let sig1 = &(self.normalize_fn_sig)(*sig1);
830832
let sig2 = &(self.normalize_fn_sig)(*sig2);
@@ -930,6 +932,25 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
930932
(values.1).0.extend(x2.0);
931933
}
932934

935+
let fmt = |(did, args)| format!(" {{{}}}", self.tcx.def_path_str_with_args(did, args));
936+
937+
match (fn_def1, fn_def2) {
938+
(None, None) => {}
939+
(Some(fn_def1), Some(fn_def2)) => {
940+
let path1 = fmt(fn_def1);
941+
let path2 = fmt(fn_def2);
942+
let same_path = path1 == path2;
943+
values.0.push(path1, !same_path);
944+
values.1.push(path2, !same_path);
945+
}
946+
(Some(fn_def1), None) => {
947+
values.0.push_highlighted(fmt(fn_def1));
948+
}
949+
(None, Some(fn_def2)) => {
950+
values.1.push_highlighted(fmt(fn_def2));
951+
}
952+
}
953+
933954
values
934955
}
935956

@@ -1318,36 +1339,21 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
13181339
(ty::FnDef(did1, args1), ty::FnDef(did2, args2)) => {
13191340
let sig1 = self.tcx.fn_sig(*did1).instantiate(self.tcx, args1);
13201341
let sig2 = self.tcx.fn_sig(*did2).instantiate(self.tcx, args2);
1321-
let mut values = self.cmp_fn_sig(&sig1, &sig2);
1322-
let path1 = format!(" {{{}}}", self.tcx.def_path_str_with_args(*did1, args1));
1323-
let path2 = format!(" {{{}}}", self.tcx.def_path_str_with_args(*did2, args2));
1324-
let same_path = path1 == path2;
1325-
values.0.push(path1, !same_path);
1326-
values.1.push(path2, !same_path);
1327-
values
1342+
self.cmp_fn_sig(&sig1, Some((*did1, args1)), &sig2, Some((*did2, args2)))
13281343
}
13291344

13301345
(ty::FnDef(did1, args1), ty::FnPtr(sig_tys2, hdr2)) => {
13311346
let sig1 = self.tcx.fn_sig(*did1).instantiate(self.tcx, args1);
1332-
let mut values = self.cmp_fn_sig(&sig1, &sig_tys2.with(*hdr2));
1333-
values.0.push_highlighted(format!(
1334-
" {{{}}}",
1335-
self.tcx.def_path_str_with_args(*did1, args1)
1336-
));
1337-
values
1347+
self.cmp_fn_sig(&sig1, Some((*did1, args1)), &sig_tys2.with(*hdr2), None)
13381348
}
13391349

13401350
(ty::FnPtr(sig_tys1, hdr1), ty::FnDef(did2, args2)) => {
13411351
let sig2 = self.tcx.fn_sig(*did2).instantiate(self.tcx, args2);
1342-
let mut values = self.cmp_fn_sig(&sig_tys1.with(*hdr1), &sig2);
1343-
values
1344-
.1
1345-
.push_normal(format!(" {{{}}}", self.tcx.def_path_str_with_args(*did2, args2)));
1346-
values
1352+
self.cmp_fn_sig(&sig_tys1.with(*hdr1), None, &sig2, Some((*did2, args2)))
13471353
}
13481354

13491355
(ty::FnPtr(sig_tys1, hdr1), ty::FnPtr(sig_tys2, hdr2)) => {
1350-
self.cmp_fn_sig(&sig_tys1.with(*hdr1), &sig_tys2.with(*hdr2))
1356+
self.cmp_fn_sig(&sig_tys1.with(*hdr1), None, &sig_tys2.with(*hdr2), None)
13511357
}
13521358

13531359
_ => {
@@ -2102,7 +2108,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
21022108
if exp_found.references_error() {
21032109
return None;
21042110
}
2105-
let (exp, fnd) = self.cmp_fn_sig(&exp_found.expected, &exp_found.found);
2111+
let (exp, fnd) = self.cmp_fn_sig(&exp_found.expected, None, &exp_found.found, None);
21062112
Some((exp, fnd, None))
21072113
}
21082114
}

tests/ui/error-emitter/highlighting.svg

+1-1
Loading

tests/ui/error-emitter/unicode-output.svg

+1-1
Loading

0 commit comments

Comments
 (0)