privacy: port unnamed "item is private" diag
Signed-off-by: David Wood <david.wood@huawei.com>
This commit is contained in:
parent
cb90a4f30c
commit
0557d02a9d
3 changed files with 14 additions and 7 deletions
|
@ -4,3 +4,5 @@ privacy-field-is-private-label = private field
|
||||||
|
|
||||||
privacy-item-is-private = {$kind} `{$descr}` is private
|
privacy-item-is-private = {$kind} `{$descr}` is private
|
||||||
.label = private {$kind}
|
.label = private {$kind}
|
||||||
|
privacy-unnamed-item-is-private = {$kind} is private
|
||||||
|
.label = private {$kind}
|
||||||
|
|
|
@ -37,3 +37,11 @@ pub struct ItemIsPrivate<'a> {
|
||||||
pub kind: &'a str,
|
pub kind: &'a str,
|
||||||
pub descr: String,
|
pub descr: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(SessionDiagnostic)]
|
||||||
|
#[error(privacy::unnamed_item_is_private)]
|
||||||
|
pub struct UnnamedItemIsPrivate {
|
||||||
|
#[primary_span]
|
||||||
|
pub span: Span,
|
||||||
|
pub kind: &'static str,
|
||||||
|
}
|
||||||
|
|
|
@ -36,7 +36,7 @@ use std::marker::PhantomData;
|
||||||
use std::ops::ControlFlow;
|
use std::ops::ControlFlow;
|
||||||
use std::{cmp, fmt, mem};
|
use std::{cmp, fmt, mem};
|
||||||
|
|
||||||
use errors::{FieldIsPrivate, FieldIsPrivateLabel, ItemIsPrivate};
|
use errors::{FieldIsPrivate, FieldIsPrivateLabel, ItemIsPrivate, UnnamedItemIsPrivate};
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
/// Generic infrastructure used to implement specific visitors below.
|
/// 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()),
|
hir::QPath::TypeRelative(_, segment) => Some(segment.ident.to_string()),
|
||||||
};
|
};
|
||||||
let kind = kind.descr(def_id);
|
let kind = kind.descr(def_id);
|
||||||
let msg = match name {
|
let _ = match name {
|
||||||
Some(name) => format!("{} `{}` is private", kind, name),
|
Some(name) => sess.emit_err(ItemIsPrivate { span, kind, descr: name }),
|
||||||
None => format!("{} is private", kind),
|
None => sess.emit_err(UnnamedItemIsPrivate { span, kind }),
|
||||||
};
|
};
|
||||||
sess.struct_span_err(span, &msg)
|
|
||||||
.span_label(span, &format!("private {}", kind))
|
|
||||||
.emit();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue