Auto merge of #116439 - compiler-errors:on-unimplemented, r=davidtwco
Pretty print `Fn` traits in `rustc_on_unimplemented` I don't think that users really ever should need to think about `Fn*` traits' tupled args for a simple trait error. r? diagnostics
This commit is contained in:
commit
1d6f05fd37
61 changed files with 169 additions and 154 deletions
|
@ -53,6 +53,7 @@ static ALLOWED_FORMAT_SYMBOLS: &[Symbol] = &[
|
|||
sym::float,
|
||||
sym::_Self,
|
||||
sym::crate_local,
|
||||
sym::Trait,
|
||||
];
|
||||
|
||||
impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
||||
|
@ -183,6 +184,19 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
|||
flags.push((sym::cause, Some("MainFunctionType".to_string())));
|
||||
}
|
||||
|
||||
if let Some(kind) = self.tcx.fn_trait_kind_from_def_id(trait_ref.def_id)
|
||||
&& let ty::Tuple(args) = trait_ref.args.type_at(1).kind()
|
||||
{
|
||||
let args = args
|
||||
.iter()
|
||||
.map(|ty| ty.to_string())
|
||||
.collect::<Vec<_>>()
|
||||
.join(", ");
|
||||
flags.push((sym::Trait, Some(format!("{}({args})", kind.as_str()))));
|
||||
} else {
|
||||
flags.push((sym::Trait, Some(trait_ref.print_only_trait_path().to_string())));
|
||||
}
|
||||
|
||||
// Add all types without trimmed paths or visible paths, ensuring they end up with
|
||||
// their "canonical" def path.
|
||||
ty::print::with_no_trimmed_paths!(ty::print::with_no_visible_paths!({
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue