Rollup merge of #121416 - veera-sivarajan:bugfix-120785, r=nnethercote
Improve error messages for generics with default parameters Fixes #120785 Issue: Previously, all type parameters with default types were deliberately ignored to simplify error messages. For example, an error message for Box type would display `Box<T>` instead of `Box<T, _>`. But, this resulted in unclear error message when a concrete type was used instead of the default type. Fix: This PR fixes it by checking if a concrete type is specified after a default type to display the entire type name or the simplified type name.
This commit is contained in:
commit
f23c6ddada
4 changed files with 79 additions and 4 deletions
|
@ -1247,10 +1247,23 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||
(&ty::Adt(def1, sub1), &ty::Adt(def2, sub2)) => {
|
||||
let did1 = def1.did();
|
||||
let did2 = def2.did();
|
||||
let sub_no_defaults_1 =
|
||||
self.tcx.generics_of(did1).own_args_no_defaults(self.tcx, sub1);
|
||||
let sub_no_defaults_2 =
|
||||
self.tcx.generics_of(did2).own_args_no_defaults(self.tcx, sub2);
|
||||
|
||||
let generics1 = self.tcx.generics_of(did1);
|
||||
let generics2 = self.tcx.generics_of(did2);
|
||||
|
||||
let non_default_after_default = generics1
|
||||
.check_concrete_type_after_default(self.tcx, sub1)
|
||||
|| generics2.check_concrete_type_after_default(self.tcx, sub2);
|
||||
let sub_no_defaults_1 = if non_default_after_default {
|
||||
generics1.own_args(sub1)
|
||||
} else {
|
||||
generics1.own_args_no_defaults(self.tcx, sub1)
|
||||
};
|
||||
let sub_no_defaults_2 = if non_default_after_default {
|
||||
generics2.own_args(sub2)
|
||||
} else {
|
||||
generics2.own_args_no_defaults(self.tcx, sub2)
|
||||
};
|
||||
let mut values = (DiagStyledString::new(), DiagStyledString::new());
|
||||
let path1 = self.tcx.def_path_str(did1);
|
||||
let path2 = self.tcx.def_path_str(did2);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue