about summary refs log tree commit diff
diff options
context:
space:
mode:
authorDavid Wood <david.wood@huawei.com>2022-06-22 13:42:30 +0100
committerDavid Wood <david.wood@huawei.com>2022-06-27 08:53:42 +0100
commit0557d02a9dcca2d0f2e3c6a5a0a69935da4cf1f5 (patch)
tree61ea63a3ed58fb2509977b55ee9a3a90d4545663
parentcb90a4f30c9f34b0f2b9c55daedb4fa832bbcf70 (diff)
downloadrust-0557d02a9dcca2d0f2e3c6a5a0a69935da4cf1f5.tar.gz
rust-0557d02a9dcca2d0f2e3c6a5a0a69935da4cf1f5.zip
privacy: port unnamed "item is private" diag
Signed-off-by: David Wood <david.wood@huawei.com>
-rw-r--r--compiler/rustc_error_messages/locales/en-US/privacy.ftl2
-rw-r--r--compiler/rustc_privacy/src/errors.rs8
-rw-r--r--compiler/rustc_privacy/src/lib.rs11
3 files changed, 14 insertions, 7 deletions
diff --git a/compiler/rustc_error_messages/locales/en-US/privacy.ftl b/compiler/rustc_error_messages/locales/en-US/privacy.ftl
index 6f558d1c6cc..de5b94e3916 100644
--- a/compiler/rustc_error_messages/locales/en-US/privacy.ftl
+++ b/compiler/rustc_error_messages/locales/en-US/privacy.ftl
@@ -4,3 +4,5 @@ privacy-field-is-private-label = private field
 
 privacy-item-is-private = {$kind} `{$descr}` is private
     .label = private {$kind}
+privacy-unnamed-item-is-private = {$kind} is private
+    .label = private {$kind}
diff --git a/compiler/rustc_privacy/src/errors.rs b/compiler/rustc_privacy/src/errors.rs
index a3072ded5a3..4db712ac8ad 100644
--- a/compiler/rustc_privacy/src/errors.rs
+++ b/compiler/rustc_privacy/src/errors.rs
@@ -37,3 +37,11 @@ pub struct ItemIsPrivate<'a> {
     pub kind: &'a str,
     pub descr: String,
 }
+
+#[derive(SessionDiagnostic)]
+#[error(privacy::unnamed_item_is_private)]
+pub struct UnnamedItemIsPrivate {
+    #[primary_span]
+    pub span: Span,
+    pub kind: &'static str,
+}
diff --git a/compiler/rustc_privacy/src/lib.rs b/compiler/rustc_privacy/src/lib.rs
index 2ff1d031783..59064563de5 100644
--- a/compiler/rustc_privacy/src/lib.rs
+++ b/compiler/rustc_privacy/src/lib.rs
@@ -36,7 +36,7 @@ use std::marker::PhantomData;
 use std::ops::ControlFlow;
 use std::{cmp, fmt, mem};
 
-use errors::{FieldIsPrivate, FieldIsPrivateLabel, ItemIsPrivate};
+use errors::{FieldIsPrivate, FieldIsPrivateLabel, ItemIsPrivate, UnnamedItemIsPrivate};
 
 ////////////////////////////////////////////////////////////////////////////////
 /// Generic infrastructure used to implement specific visitors below.
@@ -1248,13 +1248,10 @@ impl<'tcx> Visitor<'tcx> for TypePrivacyVisitor<'tcx> {
                     hir::QPath::TypeRelative(_, segment) => Some(segment.ident.to_string()),
                 };
                 let kind = kind.descr(def_id);
-                let msg = match name {
-                    Some(name) => format!("{} `{}` is private", kind, name),
-                    None => format!("{} is private", kind),
+                let _ = match name {
+                    Some(name) => sess.emit_err(ItemIsPrivate { span, kind, descr: name }),
+                    None => sess.emit_err(UnnamedItemIsPrivate { span, kind }),
                 };
-                sess.struct_span_err(span, &msg)
-                    .span_label(span, &format!("private {}", kind))
-                    .emit();
                 return;
             }
         }