Skip to content

Commit 0557d02

Browse files
committed
privacy: port unnamed "item is private" diag
Signed-off-by: David Wood <[email protected]>
1 parent cb90a4f commit 0557d02

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

compiler/rustc_error_messages/locales/en-US/privacy.ftl

+2
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ privacy-field-is-private-label = private field
44
55
privacy-item-is-private = {$kind} `{$descr}` is private
66
.label = private {$kind}
7+
privacy-unnamed-item-is-private = {$kind} is private
8+
.label = private {$kind}

compiler/rustc_privacy/src/errors.rs

+8
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,11 @@ pub struct ItemIsPrivate<'a> {
3737
pub kind: &'a str,
3838
pub descr: String,
3939
}
40+
41+
#[derive(SessionDiagnostic)]
42+
#[error(privacy::unnamed_item_is_private)]
43+
pub struct UnnamedItemIsPrivate {
44+
#[primary_span]
45+
pub span: Span,
46+
pub kind: &'static str,
47+
}

compiler/rustc_privacy/src/lib.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ use std::marker::PhantomData;
3636
use std::ops::ControlFlow;
3737
use std::{cmp, fmt, mem};
3838

39-
use errors::{FieldIsPrivate, FieldIsPrivateLabel, ItemIsPrivate};
39+
use errors::{FieldIsPrivate, FieldIsPrivateLabel, ItemIsPrivate, UnnamedItemIsPrivate};
4040

4141
////////////////////////////////////////////////////////////////////////////////
4242
/// Generic infrastructure used to implement specific visitors below.
@@ -1248,13 +1248,10 @@ impl<'tcx> Visitor<'tcx> for TypePrivacyVisitor<'tcx> {
12481248
hir::QPath::TypeRelative(_, segment) => Some(segment.ident.to_string()),
12491249
};
12501250
let kind = kind.descr(def_id);
1251-
let msg = match name {
1252-
Some(name) => format!("{} `{}` is private", kind, name),
1253-
None => format!("{} is private", kind),
1251+
let _ = match name {
1252+
Some(name) => sess.emit_err(ItemIsPrivate { span, kind, descr: name }),
1253+
None => sess.emit_err(UnnamedItemIsPrivate { span, kind }),
12541254
};
1255-
sess.struct_span_err(span, &msg)
1256-
.span_label(span, &format!("private {}", kind))
1257-
.emit();
12581255
return;
12591256
}
12601257
}

0 commit comments

Comments
 (0)