about summary refs log tree commit diff
path: root/compiler/rustc_privacy/src/errors.rs
diff options
context:
space:
mode:
authorMichael Goulet <michael@errs.io>2022-07-29 06:48:39 +0000
committerMichael Goulet <michael@errs.io>2022-08-05 16:44:01 +0000
commit0ad57d8502435aeed18f489f6a40fe36bc7fa73f (patch)
treee9ae18bb5456145c9946347d820b9ca2c0a13c63 /compiler/rustc_privacy/src/errors.rs
parentd77da9da84fc89908ad01578c33c2dca8f597ffe (diff)
downloadrust-0ad57d8502435aeed18f489f6a40fe36bc7fa73f.tar.gz
rust-0ad57d8502435aeed18f489f6a40fe36bc7fa73f.zip
Delay formatting trimmed path until lint/error is emitted
Diffstat (limited to 'compiler/rustc_privacy/src/errors.rs')
-rw-r--r--compiler/rustc_privacy/src/errors.rs21
1 files changed, 16 insertions, 5 deletions
diff --git a/compiler/rustc_privacy/src/errors.rs b/compiler/rustc_privacy/src/errors.rs
index b0fac91f6eb..f3d0c759e21 100644
--- a/compiler/rustc_privacy/src/errors.rs
+++ b/compiler/rustc_privacy/src/errors.rs
@@ -1,3 +1,6 @@
+use std::fmt::Display;
+
+use rustc_errors::IntoDiagnosticArg;
 use rustc_macros::{LintDiagnostic, SessionDiagnostic, SessionSubdiagnostic};
 use rustc_span::{Span, Symbol};
 
@@ -35,7 +38,7 @@ pub struct ItemIsPrivate<'a> {
     #[label]
     pub span: Span,
     pub kind: &'a str,
-    pub descr: String,
+    pub descr: FromDisplay<'a>,
 }
 
 #[derive(SessionDiagnostic)]
@@ -55,7 +58,7 @@ pub struct InPublicInterfaceTraits<'a> {
     pub span: Span,
     pub vis_descr: &'static str,
     pub kind: &'a str,
-    pub descr: String,
+    pub descr: FromDisplay<'a>,
     #[label(privacy::visibility_label)]
     pub vis_span: Span,
 }
@@ -69,7 +72,7 @@ pub struct InPublicInterface<'a> {
     pub span: Span,
     pub vis_descr: &'static str,
     pub kind: &'a str,
-    pub descr: String,
+    pub descr: FromDisplay<'a>,
     #[label(privacy::visibility_label)]
     pub vis_span: Span,
 }
@@ -78,7 +81,7 @@ pub struct InPublicInterface<'a> {
 #[lint(privacy::from_private_dep_in_public_interface)]
 pub struct FromPrivateDependencyInPublicInterface<'a> {
     pub kind: &'a str,
-    pub descr: String,
+    pub descr: FromDisplay<'a>,
     pub krate: Symbol,
 }
 
@@ -87,5 +90,13 @@ pub struct FromPrivateDependencyInPublicInterface<'a> {
 pub struct PrivateInPublicLint<'a> {
     pub vis_descr: &'static str,
     pub kind: &'a str,
-    pub descr: String,
+    pub descr: FromDisplay<'a>,
+}
+
+pub struct FromDisplay<'a>(pub &'a dyn Display);
+
+impl IntoDiagnosticArg for FromDisplay<'_> {
+    fn into_diagnostic_arg(self) -> rustc_errors::DiagnosticArgValue<'static> {
+        self.0.to_string().into_diagnostic_arg()
+    }
 }