about summary refs log tree commit diff
path: root/compiler
diff options
context:
space:
mode:
authorMichael Goulet <michael@errs.io>2023-10-05 01:50:00 +0000
committerMichael Goulet <michael@errs.io>2023-11-02 20:57:05 +0000
commitc83f642f12d50dbd998f5064630985306d3021d9 (patch)
treea9940979b74a34cc0e8862ee3678fdc44b22fbfb /compiler
parentb20f40dba9feabf4b446d9b09d15996f0c046eff (diff)
downloadrust-c83f642f12d50dbd998f5064630985306d3021d9.tar.gz
rust-c83f642f12d50dbd998f5064630985306d3021d9.zip
Pretty print Fn traits in rustc_on_unimplemented
Diffstat (limited to 'compiler')
-rw-r--r--compiler/rustc_span/src/symbol.rs1
-rw-r--r--compiler/rustc_trait_selection/src/traits/error_reporting/on_unimplemented.rs14
2 files changed, 15 insertions, 0 deletions
diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs
index 3f99d2a4b1f..6788bcfc601 100644
--- a/compiler/rustc_span/src/symbol.rs
+++ b/compiler/rustc_span/src/symbol.rs
@@ -316,6 +316,7 @@ symbols! {
         ToOwned,
         ToString,
         TokenStream,
+        Trait,
         Try,
         TryCaptureGeneric,
         TryCapturePrintable,
diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/on_unimplemented.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/on_unimplemented.rs
index a5508c74134..5fbfedd3e83 100644
--- a/compiler/rustc_trait_selection/src/traits/error_reporting/on_unimplemented.rs
+++ b/compiler/rustc_trait_selection/src/traits/error_reporting/on_unimplemented.rs
@@ -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!({