diff options
| author | Aris Merchant <22333129+inquisitivecrystal@users.noreply.github.com> | 2021-06-13 01:36:53 -0700 |
|---|---|---|
| committer | Aris Merchant <22333129+inquisitivecrystal@users.noreply.github.com> | 2021-06-16 01:13:28 -0700 |
| commit | f1f1c9b25b1046baecd271963739a8fef7c358e1 (patch) | |
| tree | 28a87bc2598e255dd441227fb203b75ab591914b /compiler/rustc_trait_selection/src/traits | |
| parent | 0a8629bff642c3c3b84bb644c0099194f063b627 (diff) | |
Improve errors for missing Debug and Display impls
Diffstat (limited to 'compiler/rustc_trait_selection/src/traits')
| -rw-r--r-- | compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs index 19c3385dd4c..e276d92bf5a 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs @@ -514,6 +514,30 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { } } + // Return early if the trait is Debug or Display and the invocation + // originates within a standard library macro, because the output + // is otherwise overwhelming and unhelpful (see #85844 for an + // example). + + let trait_is_debug = + self.tcx.is_diagnostic_item(sym::debug_trait, trait_ref.def_id()); + let trait_is_display = + self.tcx.is_diagnostic_item(sym::display_trait, trait_ref.def_id()); + + let in_std_macro = + match obligation.cause.span.ctxt().outer_expn_data().macro_def_id { + Some(macro_def_id) => { + let crate_name = tcx.crate_name(macro_def_id.krate); + crate_name == sym::std || crate_name == sym::core + } + None => false, + }; + + if in_std_macro && (trait_is_debug || trait_is_display) { + err.emit(); + return; + } + err } |
