mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-14 21:16:50 +00:00
privacy: port "item is private" diag
Signed-off-by: David Wood <david.wood@huawei.com>
This commit is contained in:
parent
be9ebfdbce
commit
cb90a4f30c
@ -1,3 +1,6 @@
|
||||
privacy-field-is-private = field `{$field_name}` of {$variant_descr} `{$def_path_str}` is private
|
||||
privacy-field-is-private-is-update-syntax-label = field `{$field_name}` is private
|
||||
privacy-field-is-private-label = private field
|
||||
|
||||
privacy-item-is-private = {$kind} `{$descr}` is private
|
||||
.label = private {$kind}
|
||||
|
@ -27,3 +27,13 @@ pub enum FieldIsPrivateLabel {
|
||||
span: Span,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(SessionDiagnostic)]
|
||||
#[error(privacy::item_is_private)]
|
||||
pub struct ItemIsPrivate<'a> {
|
||||
#[primary_span]
|
||||
#[label]
|
||||
pub span: Span,
|
||||
pub kind: &'a str,
|
||||
pub descr: String,
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ use std::marker::PhantomData;
|
||||
use std::ops::ControlFlow;
|
||||
use std::{cmp, fmt, mem};
|
||||
|
||||
use errors::{FieldIsPrivate, FieldIsPrivateLabel};
|
||||
use errors::{FieldIsPrivate, FieldIsPrivateLabel, ItemIsPrivate};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// Generic infrastructure used to implement specific visitors below.
|
||||
@ -1073,11 +1073,11 @@ impl<'tcx> TypePrivacyVisitor<'tcx> {
|
||||
fn check_def_id(&mut self, def_id: DefId, kind: &str, descr: &dyn fmt::Display) -> bool {
|
||||
let is_error = !self.item_is_accessible(def_id);
|
||||
if is_error {
|
||||
self.tcx
|
||||
.sess
|
||||
.struct_span_err(self.span, &format!("{} `{}` is private", kind, descr))
|
||||
.span_label(self.span, &format!("private {}", kind))
|
||||
.emit();
|
||||
self.tcx.sess.emit_err(ItemIsPrivate {
|
||||
span: self.span,
|
||||
kind,
|
||||
descr: descr.to_string(),
|
||||
});
|
||||
}
|
||||
is_error
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user